From 40f4b75d4f733660f788785726037731352a2785 Mon Sep 17 00:00:00 2001 From: Matyas Forian-Szabo Date: Wed, 11 Oct 2023 00:58:36 +0200 Subject: [PATCH] fix(ui-react-utils): fix ID counter wrong when not in context WIP, still needs unit tests --- .../DeterministicIdContext/DeterministicIdContext.ts | 5 +++-- .../DeterministicIdContextProvider.tsx | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/ui-react-utils/src/DeterministicIdContext/DeterministicIdContext.ts b/packages/ui-react-utils/src/DeterministicIdContext/DeterministicIdContext.ts index 4ab89b0412..1d4b65eee4 100644 --- a/packages/ui-react-utils/src/DeterministicIdContext/DeterministicIdContext.ts +++ b/packages/ui-react-utils/src/DeterministicIdContext/DeterministicIdContext.ts @@ -24,6 +24,7 @@ import React from 'react' import { generateInstanceCounterMap } from './generateInstanceCounterMap' -const DeterministicIdContext = React.createContext(generateInstanceCounterMap()) +const defaultDeterministicIDMap = generateInstanceCounterMap() +const DeterministicIdContext = React.createContext(defaultDeterministicIDMap) -export { DeterministicIdContext } +export { DeterministicIdContext, defaultDeterministicIDMap } diff --git a/packages/ui-react-utils/src/DeterministicIdContext/DeterministicIdContextProvider.tsx b/packages/ui-react-utils/src/DeterministicIdContext/DeterministicIdContextProvider.tsx index 71e2f3b1f6..813d0fa1cf 100644 --- a/packages/ui-react-utils/src/DeterministicIdContext/DeterministicIdContextProvider.tsx +++ b/packages/ui-react-utils/src/DeterministicIdContext/DeterministicIdContextProvider.tsx @@ -22,15 +22,16 @@ * SOFTWARE. */ import React from 'react' -import { generateInstanceCounterMap } from './generateInstanceCounterMap' -import { DeterministicIdContext } from './DeterministicIdContext' +import { + DeterministicIdContext, + defaultDeterministicIDMap +} from './DeterministicIdContext' + type DeterministicIdProviderValue = Map type DeterministicIdProviderProps = React.PropsWithChildren<{ instanceCounterMap?: DeterministicIdProviderValue }> -const defaultContextValue = generateInstanceCounterMap() - /** * --- * category: components/utilities @@ -50,7 +51,7 @@ const DeterministicIdContextProvider = ({ ) } DeterministicIdContextProvider.defaultProps = { - instanceCounterMap: defaultContextValue + instanceCounterMap: defaultDeterministicIDMap } export { DeterministicIdContextProvider }