diff --git a/apps/client/src/widgets/collections/NoteList.tsx b/apps/client/src/widgets/collections/NoteList.tsx index 421f45cc4..0a79b5720 100644 --- a/apps/client/src/widgets/collections/NoteList.tsx +++ b/apps/client/src/widgets/collections/NoteList.tsx @@ -77,8 +77,8 @@ export function CustomNoteList({ note, isEnabled: shouldEnable props = { note, noteIds, notePath, highlightedTokens, - viewConfig: viewModeConfig[0], - saveConfig: viewModeConfig[1], + viewConfig: viewModeConfig.config, + saveConfig: viewModeConfig.storeFn, onReady: onReady ?? (() => {}), ...restProps } @@ -192,7 +192,11 @@ export function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOpt } export function useViewModeConfig(note: FNote | null | undefined, viewType: ViewTypeOptions | undefined) { - const [ viewConfig, setViewConfig ] = useState<[T | undefined, (data: T) => void]>(); + const [ viewConfig, setViewConfig ] = useState<{ + config: T | undefined; + storeFn: (data: T) => void; + note: FNote; + }>(); useEffect(() => { if (!note || !viewType) return; @@ -200,12 +204,14 @@ export function useViewModeConfig(note: FNote | null | undefin const viewStorage = new ViewModeStorage(note, viewType); viewStorage.restore().then(config => { const storeFn = (config: T) => { - setViewConfig([ config, storeFn ]); + setViewConfig({ note, config, storeFn }); viewStorage.store(config); }; - setViewConfig([ config, storeFn ]); + setViewConfig({ note, config, storeFn }); }); }, [ note, viewType ]); + // Only expose config for the current note, avoid leaking notes when switching between them. + if (viewConfig?.note !== note) return undefined; return viewConfig; }