Unified · Split
| @@ -46,6 +46,7 @@ · 45 unmodified lines | ||
| 46 | 46 | "remark-breaks": "^4.0.0", |
| 47 | 47 | "remark-gfm": "^4.0.1", |
| 48 | 48 | "tailwind-merge": "^3.4.0", |
| 49 | + "use-sync-external-store": "^1.6.0", | |
| 49 | 50 | "zustand": "^5.0.11" |
| 50 | 51 | }, |
| 51 | 52 | "devDependencies": { |
| @@ -57,6 +58,7 @@ · 5 unmodified lines | ||
| 57 | 58 | "@types/babel__core": "^7.20.5", |
| 58 | 59 | "@types/react": "~19.2.14", |
| 59 | 60 | "@types/react-dom": "~19.2.3", |
| 61 | + "@types/use-sync-external-store": "^1.5.0", | |
| 60 | 62 | "@vercel/config": "^0.3.0", |
| 61 | 63 | "@vitejs/plugin-react": "^6.0.0", |
| 62 | 64 | "babel-plugin-react-compiler": "1.0.0", |
| @@ -29,6 +29,8 @@ import * as Struct from "effect/Struct"; · 28 unmodified lines | ||
| 29 | 29 | import { primaryServerSettingsAtom, serverEnvironment } from "~/state/server"; |
| 30 | 30 | import { usePrimaryEnvironment } from "~/state/environments"; |
| 31 | 31 | import { useAtomCommand } from "~/state/use-atom-command"; |
| 32 | +import { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector"; | |
| 33 | +import { shallow } from "zustand/shallow"; | |
| 32 | 34 | |
| 33 | 35 | const CLIENT_SETTINGS_PERSISTENCE_ERROR_SCOPE = "[CLIENT_SETTINGS]"; |
| 34 | 36 | |
| @@ -55,6 +57,10 @@ function getClientSettingsSnapshot(): ClientSettings { · 20 unmodified lines | ||
| 55 | 57 | return clientSettingsSnapshot; |
| 56 | 58 | } |
| 57 | 59 | |
| 60 | +function selectClientSettings(settings: ClientSettings): ClientSettings { | |
| 61 | + return settings; | |
| 62 | +} | |
| 63 | + | |
| 58 | 64 | function replaceClientSettingsSnapshot(settings: ClientSettings): void { |
| 59 | 65 | clientSettingsSnapshot = settings; |
| 60 | 66 | emitClientSettingsChange(); |
| @@ -214,8 +220,13 @@ function useMergedSettings<T>( · 153 unmodified lines | ||
| 214 | 220 | export function useClientSettings<T = ClientSettings>( |
| 215 | 221 | selector?: (settings: ClientSettings) => T, |
| 216 | 222 | ): T { |
| 217 | − const settings = useClientSettingsValue(); | |
| 218 | − return useMemo(() => (selector ? selector(settings) : (settings as T)), [selector, settings]); | |
| 223 | + return useSyncExternalStoreWithSelector( | |
| 224 | + subscribeClientSettings, | |
| 225 | + getClientSettingsSnapshot, | |
| 226 | + () => DEFAULT_CLIENT_SETTINGS, | |
| 227 | + selector ?? (selectClientSettings as (settings: ClientSettings) => T), | |
| 228 | + selector ? shallow : Object.is, | |
| 229 | + ); | |
| 219 | 230 | } |
| 220 | 231 | |
| 221 | 232 | /** Read current settings for one environment, merged with client-local preferences. */ |
| @@ -607,6 +607,9 @@ importers: · 606 unmodified lines | ||
| 607 | 607 | tailwind-merge: |
| 608 | 608 | specifier: ^3.4.0 |
| 609 | 609 | version: 3.6.0 |
| 610 | + use-sync-external-store: | |
| 611 | + specifier: ^1.6.0 | |
| 612 | + version: 1.6.0(react@19.2.6) | |
| 610 | 613 | zustand: |
| 611 | 614 | specifier: ^5.0.11 |
| 612 | 615 | version: 5.0.14(@types/react@19.2.16)(react@19.2.6)(use-sync-external-store@1.6.0(react@19.2.6)) |
| @@ -635,6 +638,9 @@ importers: · 22 unmodified lines | ||
| 635 | 638 | '@types/react-dom': |
| 636 | 639 | specifier: ~19.2.3 |
| 637 | 640 | version: 19.2.3(@types/react@19.2.16) |
| 641 | + '@types/use-sync-external-store': | |
| 642 | + specifier: ^1.5.0 | |
| 643 | + version: 1.5.0 | |
| 638 | 644 | '@vercel/config': |
| 639 | 645 | specifier: ^0.3.0 |
| 640 | 646 | version: 0.3.0 |
| @@ -4921,6 +4927,9 @@ packages: · 4280 unmodified lines | ||
| 4921 | 4927 | '@types/unist@3.0.3': |
| 4922 | 4928 | resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==} |
| 4923 | 4929 | |
| 4930 | + '@types/use-sync-external-store@1.5.0': | |
| 4931 | + resolution: {integrity: sha512-5dyB8nLC/qogMrlCizZnYWQTA4lnb/v+It+sqNl5YnSRAPMlIqY/X0Xn+gZw8vOL+TgTTr28VEbn3uf8fUtAkw==} | |
| 4932 | + | |
| 4924 | 4933 | '@types/ws@8.18.1': |
| 4925 | 4934 | resolution: {integrity: sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==} |
| 4926 | 4935 | |
| @@ -14947,6 +14956,8 @@ snapshots: · 10020 unmodified lines | ||
| 14947 | 14956 | |
| 14948 | 14957 | '@types/unist@3.0.3': {} |
| 14949 | 14958 | |
| 14959 | + '@types/use-sync-external-store@1.5.0': {} | |
| 14960 | + | |
| 14950 | 14961 | '@types/ws@8.18.1': |
| 14951 | 14962 | dependencies: |
| 14952 | 14963 | '@types/node': 24.12.4 |