@@ -10,7 +10,7 @@ import {
1010import { getLayoutModelForStaticTab } from "@/layout/lib/layoutModelHooks" ;
1111import { getWebServerEndpoint } from "@/util/endpoints" ;
1212import { fetch } from "@/util/fetchutil" ;
13- import { getPrefixedSettings , isBlank } from "@/util/util" ;
13+ import { deepCompareReturnPrev , getPrefixedSettings , isBlank } from "@/util/util" ;
1414import { atom , Atom , PrimitiveAtom , useAtomValue } from "jotai" ;
1515import { globalStore } from "./jotaiStore" ;
1616import { modalsModel } from "./modalmodel" ;
@@ -314,16 +314,15 @@ function useSettingsKeyAtom<T extends keyof SettingsType>(key: T): SettingsType[
314314 return useAtomValue ( getSettingsKeyAtom ( key ) ) ;
315315}
316316
317- function useSettingsPrefixAtom ( prefix : string ) : Atom < SettingsType > {
318- // TODO: use a shallow equal here to make this more efficient
319- let settingsPrefixAtom = settingsAtomCache . get ( prefix + ":" ) as Atom < SettingsType > ;
317+ function getSettingsPrefixAtom ( prefix : string ) : Atom < SettingsType > {
318+ let settingsPrefixAtom = settingsAtomCache . get ( prefix + ":" ) ;
320319 if ( settingsPrefixAtom == null ) {
320+ // create a stable, closured reference to use as the deepCompareReturnPrev key
321+ const cacheKey = { } ;
321322 settingsPrefixAtom = atom ( ( get ) => {
322323 const settings = get ( atoms . settingsAtom ) ;
323- if ( settings == null ) {
324- return { } ;
325- }
326- return getPrefixedSettings ( settings , prefix ) ;
324+ const newValue = getPrefixedSettings ( settings , prefix ) ;
325+ return deepCompareReturnPrev ( cacheKey , newValue ) ;
327326 } ) ;
328327 settingsAtomCache . set ( prefix + ":" , settingsPrefixAtom ) ;
329328 }
@@ -674,6 +673,7 @@ export {
674673 getObjectId ,
675674 getOverrideConfigAtom ,
676675 getSettingsKeyAtom ,
676+ getSettingsPrefixAtom ,
677677 getUserName ,
678678 globalStore ,
679679 initGlobal ,
@@ -700,6 +700,5 @@ export {
700700 useBlockMetaKeyAtom ,
701701 useOverrideConfigAtom ,
702702 useSettingsKeyAtom ,
703- useSettingsPrefixAtom ,
704703 WOS ,
705704} ;
0 commit comments