Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

useSettings.ts

651 lines24.1 KB

1/**
2 * Environment-scoped settings hooks.
3 *
4 * Abstracts the split between server-authoritative settings (persisted in
5 * `settings.json` on the server, fetched via `server.getConfig`) and
6 * client-only settings (persisted in localStorage).
7 *
8 * Live server settings always require an environment id. Primary-environment
9 * access is intentionally named as such so environment-sensitive consumers
10 * cannot silently read the wrong server's settings.
11 */
12import { useCallback, useMemo, useSyncExternalStore } from "react";
13import { useAtomValue } from "@effect/atom-react";
14import {
15 DEFAULT_SERVER_SETTINGS,
16 AuthSettingsWriteScope,
17 requiredScopesForServerSettingsPatch,
18 type EnvironmentId,
19 type ProviderInstanceMutation,
20 ServerSettings,
21 type ServerSettingsPatch,
22 sessionGrantsScope,
23} from "@t3tools/contracts";
24import {
25 type ClientSettingsPatch,
26 type ClientSettings,
27 DEFAULT_CLIENT_SETTINGS,
28 type EnvironmentIdentificationMode,
29 type UnifiedSettings,
30} from "@t3tools/contracts/settings";
31import { safeErrorLogAttributes } from "@t3tools/client-runtime/errors";
32import {
33 isAtomCommandInterrupted,
34 squashAtomCommandFailure,
35} from "@t3tools/client-runtime/state/runtime";
36import {
37 filterSharedServerPatch,
38 splitSharedServerPatch,
39 supportsSharedSettingsSync,
40} from "@t3tools/client-runtime/state/shared-settings";
41import { ensureLocalApi } from "~/localApi";
42import {
43 getThemeDefinition,
44 getThemePreviewSidebarArtwork,
45 resolveThemeHalf,
46 subscribeToThemePreview,
47 themeAllowsSidebarArtwork,
48} from "~/themePalette";
49import * as Struct from "effect/Struct";
50import * as Option from "effect/Option";
51import { AsyncResult, Atom } from "effect/reactivity";
52import { toastManager } from "~/components/ui/toast";
53import { isHostedStaticApp } from "~/hostedPairing";
54import { primaryServerSettingsAtom, serverEnvironment } from "~/state/server";
55import { useEnvironments, usePrimaryEnvironment } from "~/state/environments";
56import { useAtomCommand } from "~/state/use-atom-command";
57import { useTheme } from "./useTheme";
58import { environmentSession, readEnvironmentScope, useEnvironmentScope } from "~/state/session";
59import { appAtomRegistry } from "~/rpc/atomRegistry";
60​
61const CLIENT_SETTINGS_PERSISTENCE_ERROR_SCOPE = "[CLIENT_SETTINGS]";
62​
63type UnifiedSettingsPatch = ServerSettingsPatch & ClientSettingsPatch;
64​
65const clientSettingsListeners = new Set<() => void>();
66const clientSettingsHydrationListeners = new Set<() => void>();
67type ClientSettingsHydrationStatus = "pending" | "ready" | "failed" | "retrying";
68let clientSettingsSnapshot = DEFAULT_CLIENT_SETTINGS;
69let clientSettingsHydrationStatus: ClientSettingsHydrationStatus = "pending";
70let clientSettingsHydrationPromise: Promise<void> | null = null;
71let clientSettingsHydrationGeneration = 0;
72let clientSettingsPersistenceQueue: Promise<void> = Promise.resolve();
73let deferredClientSettingsPatchCount = 0;
74​
75function emitClientSettingsChange() {
76 for (const listener of clientSettingsListeners) {
77 listener();
78 }
80​
81function emitClientSettingsHydrationChange() {
82 for (const listener of clientSettingsHydrationListeners) {
83 listener();
84 }
86​
87function getClientSettingsSnapshot(): ClientSettings {
88 return clientSettingsSnapshot;
90​
91function replaceClientSettingsSnapshot(settings: ClientSettings): void {
92 clientSettingsSnapshot = settings;
93 emitClientSettingsChange();
95​
96function setClientSettingsHydrationStatus(nextStatus: ClientSettingsHydrationStatus): void {
97 if (clientSettingsHydrationStatus === nextStatus) {
98 return;
99 }
100 clientSettingsHydrationStatus = nextStatus;
101 emitClientSettingsHydrationChange();
103​
104function subscribeClientSettings(listener: () => void): () => void {
105 clientSettingsListeners.add(listener);
106 void hydrateClientSettings().catch(() => undefined);
107 return () => {
108 clientSettingsListeners.delete(listener);
109 };
111​
112function getClientSettingsHydratedSnapshot(): boolean {
113 return clientSettingsHydrationStatus === "ready";
115​
116function getClientSettingsHydrationStatusSnapshot(): ClientSettingsHydrationStatus {
117 return clientSettingsHydrationStatus;
119​
120function subscribeClientSettingsHydration(listener: () => void): () => void {
121 clientSettingsHydrationListeners.add(listener);
122 void hydrateClientSettings().catch(() => undefined);
123 return () => {
124 clientSettingsHydrationListeners.delete(listener);
125 };
127​
128async function hydrateClientSettings(): Promise<void> {
129 if (clientSettingsHydrationStatus === "ready") {
130 return;
131 }
132 if (clientSettingsHydrationPromise) {
133 return clientSettingsHydrationPromise;
134 }
135​
136 const hydrationGeneration = clientSettingsHydrationGeneration;
137 setClientSettingsHydrationStatus(
138 clientSettingsHydrationStatus === "failed" || clientSettingsHydrationStatus === "retrying"
139 ? "retrying"
140 : "pending",
141 );
142 const nextHydration = (async () => {
143 try {
144 const persistedSettings = await ensureLocalApi().persistence.getClientSettings();
145 if (hydrationGeneration !== clientSettingsHydrationGeneration) {
146 return;
147 }
148 if (persistedSettings) {
149 replaceClientSettingsSnapshot({ ...DEFAULT_CLIENT_SETTINGS, ...persistedSettings });
150 }
151 setClientSettingsHydrationStatus("ready");
152 } catch (error) {
153 if (hydrationGeneration === clientSettingsHydrationGeneration) {
154 setClientSettingsHydrationStatus("failed");
155 }
156 console.error(`${CLIENT_SETTINGS_PERSISTENCE_ERROR_SCOPE} hydrate failed`, {
157 operation: "hydrate",
158 ...safeErrorLogAttributes(error),
159 });
160 throw error;
161 }
162 })();
163​
164 const hydrationPromise = nextHydration.finally(() => {
165 if (clientSettingsHydrationPromise === hydrationPromise) {
166 clientSettingsHydrationPromise = null;
167 }
168 });
169 clientSettingsHydrationPromise = hydrationPromise;
170​
171 return clientSettingsHydrationPromise;
173​
174const defaultClientSettingsPersistence = (settings: ClientSettings): Promise<void> =>
175 ensureLocalApi().persistence.setClientSettings(settings);
176​
177function enqueueClientSettingsPersistence<A>(work: () => Promise<A>): Promise<A> {
178 const result = clientSettingsPersistenceQueue.then(work);
179 clientSettingsPersistenceQueue = result.then(
180 () => undefined,
181 () => undefined,
182 );
183 return result;
185​
186export function persistClientSettingsPatch(
187 patch: ClientSettingsPatch,
188 persist: (settings: ClientSettings) => Promise<void> = defaultClientSettingsPersistence,
189): Promise<void> {
190 // Patches queued before hydration must publish before newer optimistic patches.
191 const deferPatch =
192 clientSettingsHydrationStatus !== "ready" || deferredClientSettingsPatchCount > 0;
193 if (deferPatch) {
194 deferredClientSettingsPatchCount += 1;
195 } else {
196 replaceClientSettingsSnapshot({ ...getClientSettingsSnapshot(), ...patch });
197 }
198 return enqueueClientSettingsPersistence(async () => {
199 if (deferPatch) {
200 try {
201 if (clientSettingsHydrationStatus !== "ready") {
202 await hydrateClientSettings();
203 }
204 replaceClientSettingsSnapshot({ ...getClientSettingsSnapshot(), ...patch });
205 } finally {
206 deferredClientSettingsPatchCount -= 1;
207 }
208 }
209 await persist(getClientSettingsSnapshot());
210 }).catch((error) => {
211 console.error(`${CLIENT_SETTINGS_PERSISTENCE_ERROR_SCOPE} persist failed`, {
212 operation: "persist",
213 ...safeErrorLogAttributes(error),
214 });
215 });
217​
218/**
219 * Persists a client-settings update before publishing it to the in-memory
220 * snapshot. If another settings write lands while persistence is pending, the
221 * updater is reapplied to that newer snapshot and persisted again so neither
222 * change is lost.
223 */
224export async function persistClientSettingsUpdate(
225 update: (current: ClientSettings) => ClientSettings,
226 persist: (settings: ClientSettings) => Promise<void> = defaultClientSettingsPersistence,
227): Promise<ClientSettings> {
228 return enqueueClientSettingsPersistence(async () => {
229 if (clientSettingsHydrationStatus !== "ready") {
230 await hydrateClientSettings();
231 }
232 for (;;) {
233 const current = getClientSettingsSnapshot();
234 const next = update(current);
235 await persist(next);
236 if (getClientSettingsSnapshot() === current) {
237 replaceClientSettingsSnapshot(next);
238 return next;
239 }
240 }
241 });
243​
244// ── Key sets for routing patches ─────────────────────────────────────
245​
246const SERVER_SETTINGS_KEYS = new Set<string>(Struct.keys(ServerSettings.fields));
247​
248function splitPatch(patch: UnifiedSettingsPatch): {
249 serverPatch: ServerSettingsPatch;
250 clientPatch: ClientSettingsPatch;
251} {
252 const serverPatch: Record<string, unknown> = {};
253 const clientPatch: Record<string, unknown> = {};
254 for (const [key, value] of Object.entries(patch)) {
255 if (SERVER_SETTINGS_KEYS.has(key)) {
256 serverPatch[key] = value;
257 } else {
258 clientPatch[key] = value;
259 }
260 }
261 return {
262 serverPatch: serverPatch as ServerSettingsPatch,
263 clientPatch: clientPatch as ClientSettingsPatch,
264 };
266​
267// ── Hooks ────────────────────────────────────────────────────────────
268​
269/**
270 * Non-hook accessor for the current merged client settings snapshot.
271 * Used by non-React code paths (e.g. runtime services) that need the latest
272 * settings without subscribing.
273 */
274export function getClientSettings(): ClientSettings {
275 return getClientSettingsSnapshot();
277​
278/**
279 * Resolves after settings load or storage confirms no saved settings exist.
280 * Failed reads reject and remain retryable. They must not allow defaults to
281 * overwrite saved preferences.
282 *
283 * The pre-hydration snapshot is just the schema defaults, so imperative paths
284 * that open a preview must await this or they bake the built-in viewport, zoom
285 * and appearance into a tab that never picks up the user's saved values.
286 */
287export function ensureClientSettingsHydrated(): Promise<void> {
288 return hydrateClientSettings();
290​
291export function useClientSettingsHydrated(): boolean {
292 return useSyncExternalStore(
293 subscribeClientSettingsHydration,
294 getClientSettingsHydratedSnapshot,
295 () => false,
296 );
298​
299export function useClientSettingsHydrationStatus(): ClientSettingsHydrationStatus {
300 return useSyncExternalStore(
301 subscribeClientSettingsHydration,
302 getClientSettingsHydrationStatusSnapshot,
303 () => "pending",
304 );
306​
307function useClientSettingsValue(): ClientSettings {
308 return useSyncExternalStore(
309 subscribeClientSettings,
310 getClientSettingsSnapshot,
311 () => DEFAULT_CLIENT_SETTINGS,
312 );
314​
315export function mergeEnvironmentSettings(
316 serverSettings: ServerSettings,
317 clientSettings: ClientSettings,
318): UnifiedSettings {
319 // Decode drops retired client keys, but older untyped persistence adapters
320 // can still return them. Server-owned values must always win.
321 return { ...clientSettings, ...serverSettings };
323​
324function useMergedSettings<T>(
325 serverSettings: ServerSettings,
326 selector: ((settings: UnifiedSettings) => T) | undefined,
327): T {
328 const clientSettings = useClientSettingsValue();
329​
330 const merged = useMemo<UnifiedSettings>(
331 () => mergeEnvironmentSettings(serverSettings, clientSettings),
332 [clientSettings, serverSettings],
333 );
334​
335 return useMemo(() => (selector ? selector(merged) : (merged as T)), [merged, selector]);
337​
338export function useClientSettings<T = ClientSettings>(
339 selector?: (settings: ClientSettings) => T,
340): T {
341 const settings = useClientSettingsValue();
342 return useMemo(() => (selector ? selector(settings) : (settings as T)), [selector, settings]);
344​
345export function resolveEnvironmentIdentificationMode(input: {
346 mode: EnvironmentIdentificationMode;
347 settingsHydrated: boolean;
348 paletteThemeActive?: boolean;
349 paletteThemeAllowsArtwork?: boolean;
350}): EnvironmentIdentificationMode {
351 // Avoid briefly rendering the default artwork before a persisted pill/none choice loads.
352 if (!input.settingsHydrated) return "none";
353 // Artwork palettes are maintained for built-ins only. Keep an explicit
354 // "none", but use the theme-aware pill for user-controlled palettes.
355 return input.paletteThemeActive && !input.paletteThemeAllowsArtwork && input.mode === "artwork"
356 ? "pill"
357 : input.mode;
359​
360export function useEnvironmentIdentificationMode(): EnvironmentIdentificationMode {
361 const settingsHydrated = useClientSettingsHydrated();
362 const mode = useClientSettingsValue().environmentIdentificationMode;
363 const { resolvedTheme, theme, themeHalves } = useTheme();
364 const previewSidebarArtwork = useSyncExternalStore(
365 subscribeToThemePreview,
366 getThemePreviewSidebarArtwork,
367 () => null,
368 );
369 const activeTheme = resolveThemeHalf(theme, themeHalves, resolvedTheme);
370 const activeThemeDefinition = getThemeDefinition(activeTheme);
371 return resolveEnvironmentIdentificationMode({
372 mode,
373 settingsHydrated,
374 paletteThemeActive: previewSidebarArtwork !== null || activeThemeDefinition !== null,
375 paletteThemeAllowsArtwork: previewSidebarArtwork ?? themeAllowsSidebarArtwork(activeTheme),
376 });
378​
379/**
380 * Whether the legacy sidebar (Settings → General → Legacy features) replaces
381 * the default one.
382 *
383 * Held at the default sidebar until client settings hydrate: the pre-hydration
384 * snapshot is just the schema defaults, so resolving against it could mount one
385 * sidebar and then swap it out once persisted settings land — remounting the
386 * whole tree for everyone instead of only for legacy opt-ins.
387 */
388export function useLegacySidebarEnabled(): boolean {
389 const settingsHydrated = useClientSettingsHydrated();
390 const legacySidebarEnabled = useClientSettingsValue().legacySidebarEnabled;
391 return settingsHydrated && legacySidebarEnabled;
393​
394/** Read current settings for one environment, merged with client-local preferences. */
395export function useEnvironmentSettings<T = UnifiedSettings>(
396 environmentId: EnvironmentId,
397 selector?: (settings: UnifiedSettings) => T,
398): T {
399 const serverSettings = useAtomValue(serverEnvironment.settingsValueAtom(environmentId));
400 return useMergedSettings(serverSettings ?? DEFAULT_SERVER_SETTINGS, selector);
402​
403/** Atomically mutate one provider instance against the server's latest settings snapshot. */
404export function usePersistEnvironmentProviderInstanceMutation(environmentId: EnvironmentId) {
405 const mutateProviderInstance = useAtomCommand(serverEnvironment.mutateProviderInstance, {
406 reportFailure: false,
407 });
408 return useCallback(
409 (providerInstanceMutation: ProviderInstanceMutation, patch: ServerSettingsPatch = {}) =>
410 mutateProviderInstance({
411 environmentId,
412 input: { patch, providerInstanceMutation },
413 }),
414 [environmentId, mutateProviderInstance],
415 );
417​
418/** Primary-only settings access for the settings UI and other explicitly global surfaces. */
419export function usePrimarySettings<T = UnifiedSettings>(
420 selector?: (settings: UnifiedSettings) => T,
421): T {
422 return useMergedSettings(useAtomValue(primaryServerSettingsAtom), selector);
424​
425export const PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE =
426 "This setting is saved on a server, and the hosted app is not anchored to one. Change it from the desktop app or from the server's own address.";
427​
428/**
429 * Whether primary-scoped server settings have a server to live on. The
430 * hosted app connects to every environment as a remote, so it has no primary:
431 * `usePrimarySettings` reads schema defaults there and writes have nowhere
432 * to go. Desktop and server-served web always have one.
433 */
434export function usePrimarySettingsAvailable(): boolean {
435 const primaryEnvironment = usePrimaryEnvironment();
436 return primaryEnvironment !== null || !isHostedStaticApp();
438​
439/** Connected sync targets, excluding grants already known to forbid settings writes. */
440function useSharedSettingsSyncTargetIds(includePending = false): ReadonlyArray<EnvironmentId> {
441 const { environments } = useEnvironments();
442 const writableTargetsAtom = useMemo(
443 () =>
444 Atom.make((get) =>
445 environments.filter(supportsSharedSettingsSync).flatMap((environment) => {
446 const result = get(environmentSession.sessionStateAtom(environment.environmentId));
447 // A cold grant must not drop a shared edit. The server authorizes the
448 // write; mismatch suggestions still wait for a confirmed grant.
449 if (includePending && result._tag === "Initial") {
450 return [environment.environmentId];
451 }
452 const session =
453 result._tag === "Failure" ? null : Option.getOrNull(AsyncResult.value(result));
454 return session !== null && sessionGrantsScope(session, AuthSettingsWriteScope)
455 ? [environment.environmentId]
456 : [];
457 }),
458 ),
459 [environments, includePending],
460 );
461 return useAtomValue(writableTargetsAtom);
463​
464/**
465 * Returns an updater that routes each key to the correct backing store.
466 *
467 * Server keys are optimistically patched in atom-backed server state, then
468 * persisted via RPC. Shared server keys (see `SHARED_SERVER_SETTING_KEYS`)
469 * are written to every eligible sync target, not only the selected target, so
470 * a user preference does not silently drift between machines. Client keys go
471 * through client persistence.
472 */
473function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
474 // Mount this session even on pages without a visible permission-gated control.
475 useEnvironmentScope(environmentId, AuthSettingsWriteScope);
476 const persist = useAtomCommand(serverEnvironment.updateSettings, {
477 label: "server settings update",
478 reportFailure: false,
479 });
480 const { environments } = useEnvironments();
481 const persistServerSettings = useCallback(
482 async (request: Parameters<typeof persist>[0]) => {
483 const result = await persist(request);
484 if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
485 const label =
486 environments.find((environment) => environment.environmentId === request.environmentId)
487 ?.label ?? request.environmentId;
488 const error = squashAtomCommandFailure(result);
489 toastManager.add({
490 type: "error",
491 title: "Setting not saved",
492 description: `Could not save on ${label}: ${error instanceof Error ? error.message : "The save failed. Try reconnecting and saving again."}`,
493 });
494 }
495 return result;
496 },
497 [environments, persist],
498 );
499 const sharedSettingsSyncTargetIds = useSharedSettingsSyncTargetIds(true);
500 const updateSettings = useCallback(
501 (patch: UnifiedSettingsPatch) => {
502 const { serverPatch, clientPatch } = splitPatch(patch);
503​
504 const canWriteServerPatch =
505 environmentId === null ||
506 requiredScopesForServerSettingsPatch(serverPatch).every((scope) =>
507 readEnvironmentScope(environmentId, scope),
508 );
509 if (Object.keys(serverPatch).length > 0 && !canWriteServerPatch) {
510 toastManager.add({
511 type: "warning",
512 title: "Setting not saved",
513 description: `This connection lacks permission to change settings on ${environments.find((target) => target.environmentId === environmentId)?.label ?? "the selected environment"}.`,
514 });
515 }
516 if (Object.keys(serverPatch).length > 0 && canWriteServerPatch) {
517 const { sharedPatch, localPatch } = splitSharedServerPatch(serverPatch);
518 // Dropping the write silently leaves the control looking saved.
519 const warnUnsaved = (description = PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE) =>
520 toastManager.add({
521 type: "warning",
522 title: "Setting not saved",
523 description,
524 });
525 if (Object.keys(localPatch).length > 0) {
526 if (environmentId) {
527 void persistServerSettings({
528 environmentId,
529 input: { patch: localPatch },
530 });
531 } else {
532 warnUnsaved();
533 }
534 }
535 if (Object.keys(sharedPatch).length > 0) {
536 const sourceSettings = environments.find(
537 (target) => target.environmentId === environmentId,
538 )?.serverConfig?.settings;
539 const targets = new Set(sharedSettingsSyncTargetIds);
540 if (environmentId) {
541 targets.add(environmentId);
542 }
543 const writes: Array<Parameters<typeof persist>[0]> = [];
544 const deniedLabels: string[] = [];
545 for (const targetId of targets) {
546 const target = environments.find((candidate) => candidate.environmentId === targetId);
547 const targetPatch = filterSharedServerPatch(
548 sharedPatch,
549 target?.serverConfig?.environment.capabilities,
550 target?.serverConfig?.settings,
551 sourceSettings,
552 targetId === environmentId,
553 );
554 if (Object.keys(targetPatch).length === 0) continue;
555 const session = appAtomRegistry.get(environmentSession.sessionStateAtom(targetId));
556 if (
557 session._tag !== "Initial" &&
558 !requiredScopesForServerSettingsPatch(sharedPatch).every((scope) =>
559 readEnvironmentScope(targetId, scope),
560 )
561 ) {
562 deniedLabels.push(target?.label ?? targetId);
563 continue;
564 }
565 writes.push({
566 environmentId: targetId,
567 input: { patch: targetPatch },
568 });
569 }
570 if (writes.length === 0) {
571 warnUnsaved(
572 deniedLabels.length > 0
573 ? `This connection lacks permission to change settings on ${deniedLabels.join(", ")}.`
574 : targets.size > 0
575 ? "Update older servers to save this setting."
576 : undefined,
577 );
578 } else {
579 void Promise.all(
580 writes.map(async (request) => ({
581 label:
582 environments.find((target) => target.environmentId === request.environmentId)
583 ?.label ?? request.environmentId,
584 result: await persist(request),
585 })),
586 ).then((outcomes) => {
587 const failures = outcomes.flatMap(({ label, result }) => {
588 if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return [];
589 const error = squashAtomCommandFailure(result);
590 return [
591 `Could not save on ${label}: ${error instanceof Error ? error.message : "The save failed. Try reconnecting and saving again."}`,
592 ];
593 });
594 if (failures.length === 0) return;
595 const saved = outcomes
596 .filter(({ result }) => result._tag === "Success")
597 .map(({ label }) => label);
598 toastManager.add({
599 type: "error",
600 title:
601 saved.length > 0 ? "Setting saved on some environments" : "Setting not saved",
602 description: [
603 ...failures,
604 ...(saved.length > 0 ? [`Saved on ${saved.join(", ")}.`] : []),
605 ].join("\n"),
606 });
607 });
608 }
609 }
610 }
611 if (Object.keys(clientPatch).length > 0) {
612 void persistClientSettingsPatch(clientPatch);
613 }
614 },
615 [environmentId, environments, persist, persistServerSettings, sharedSettingsSyncTargetIds],
616 );
617​
618 return updateSettings;
620​
621export function useUpdateEnvironmentSettings(environmentId: EnvironmentId) {
622 return useUpdateSettingsTarget(environmentId);
624​
625export function useUpdatePrimarySettings() {
626 return useUpdateSettingsTarget(usePrimaryEnvironment()?.environmentId ?? null);
628​
629export function useUpdateClientSettings() {
630 return useCallback((patch: ClientSettingsPatch) => {
631 return persistClientSettingsPatch(patch);
632 }, []);
634​
635export function __resetClientSettingsPersistenceForTests(): void {
636 clientSettingsHydrationGeneration += 1;
637 clientSettingsSnapshot = DEFAULT_CLIENT_SETTINGS;
638 clientSettingsHydrationStatus = "pending";
639 clientSettingsHydrationPromise = null;
640 clientSettingsPersistenceQueue = Promise.resolve();
641 deferredClientSettingsPatchCount = 0;
642 clientSettingsListeners.clear();
643 clientSettingsHydrationListeners.clear();
645​
646export function __setClientSettingsForTests(settings: ClientSettings): void {
647 clientSettingsHydrationGeneration += 1;
648 clientSettingsSnapshot = settings;
649 clientSettingsHydrationStatus = "ready";
650 clientSettingsHydrationPromise = null;