Compare commits

...
Author SHA1 Message Date
Cursor AgentandJulius Marminge 909cbf7df1 Prevent unrelated client settings rerenders
Co-authored-by: Julius Marminge <[email protected]>
2026-07-16 16:18:46 +00:00
3 changed files with 26 additions and 2 deletions

No files matched your search

+2
View File
@@ -46,6 +46,7 @@
"remark-breaks": "^4.0.0",
"remark-gfm": "^4.0.1",
"tailwind-merge": "^3.4.0",
"use-sync-external-store": "^1.6.0",
"zustand": "^5.0.11"
},
"devDependencies": {
@@ -57,6 +58,7 @@
"@types/babel__core": "^7.20.5",
"@types/react": "~19.2.14",
"@types/react-dom": "~19.2.3",
"@types/use-sync-external-store": "^1.5.0",
"@vercel/config": "^0.3.0",
"@vitejs/plugin-react": "^6.0.0",
"babel-plugin-react-compiler": "1.0.0",
+13 -2
View File
@@ -29,6 +29,8 @@ import * as Struct from "effect/Struct";
import { primaryServerSettingsAtom, serverEnvironment } from "~/state/server";
import { usePrimaryEnvironment } from "~/state/environments";
import { useAtomCommand } from "~/state/use-atom-command";
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector";
import { shallow } from "zustand/shallow";
const CLIENT_SETTINGS_PERSISTENCE_ERROR_SCOPE = "[CLIENT_SETTINGS]";
@@ -55,6 +57,10 @@ function getClientSettingsSnapshot(): ClientSettings {
return clientSettingsSnapshot;
}
function selectClientSettings(settings: ClientSettings): ClientSettings {
return settings;
}
function replaceClientSettingsSnapshot(settings: ClientSettings): void {
clientSettingsSnapshot = settings;
emitClientSettingsChange();
@@ -214,8 +220,13 @@ function useMergedSettings<T>(
export function useClientSettings<T = ClientSettings>(
selector?: (settings: ClientSettings) => T,
): T {
const settings = useClientSettingsValue();
return useMemo(() => (selector ? selector(settings) : (settings as T)), [selector, settings]);
return useSyncExternalStoreWithSelector(
subscribeClientSettings,
getClientSettingsSnapshot,
() => DEFAULT_CLIENT_SETTINGS,
selector ?? (selectClientSettings as (settings: ClientSettings) => T),
selector ? shallow : Object.is,
);
}
/** Read current settings for one environment, merged with client-local preferences. */
+11
View File
@@ -607,6 +607,9 @@ importers:
tailwind-merge:
specifier: ^3.4.0
version: 3.6.0
use-sync-external-store:
specifier: ^1.6.0
version: 1.6.0([email protected])
zustand:
specifier: ^5.0.11
version: 5.0.14(@types/[email protected])([email protected])([email protected]([email protected]))
@@ -635,6 +638,9 @@ importers:
'@types/react-dom':
specifier: ~19.2.3
version: 19.2.3(@types/[email protected])
'@types/use-sync-external-store':
specifier: ^1.5.0
version: 1.5.0
'@vercel/config':
specifier: ^0.3.0
version: 0.3.0
@@ -4921,6 +4927,9 @@ packages:
'@types/[email protected]':
resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==}
'@types/[email protected]':
resolution: {integrity: sha512-5dyB8nLC/qogMrlCizZnYWQTA4lnb/v+It+sqNl5YnSRAPMlIqY/X0Xn+gZw8vOL+TgTTr28VEbn3uf8fUtAkw==}
'@types/[email protected]':
resolution: {integrity: sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==}
@@ -14947,6 +14956,8 @@ snapshots:
'@types/[email protected]': {}
'@types/[email protected]': {}
'@types/[email protected]':
dependencies:
'@types/node': 24.12.4