LocaleProvider and ThemeProvider lived inside AppRouter, below the server-state scope fence (and below QueryClientProvider keyed by generation). A session change (FENCED -> READY) unmounted and remounted them, so their live state was thrown away and re-read from storage. The browser router was created in useMemo and never disposed, so every remount (and StrictMode's double useMemo) left a popstate listener behind. - New presentation/providers/preference-providers.tsx: persisted LocaleProvider + ThemeProvider (the wiring T45 added to AppRouter). - bootstrap/runtime-application.tsx: ApplicationProvider > PreferenceProviders > ServerStateGenerationProvider > AppRouter, so the fence only remounts session-scoped UI. - AppRouter no longer mounts Locale/Theme. It creates the router in the effect that disposes it: a disposed router never listens to history again, so useMemo + cleanup would break back/forward under StrictMode's replayed mount. - Tests that mount AppRouter directly now wrap it in PreferenceProviders (router, chunk-recovery-boundary, app-shell, product-feature-switch, locale-platform, reference-feature reference-page). Verified: RED "keeps locale state across a session scope fence and disposes routers" (RuntimeApplication, demo sign-in, storage cleared after choosing en-US) came back in Korean before and passes after; with the providers hoisted but no dispose it fails on popstate listeners (4 added, 0 removed). check:architecture, check:types:app, check:types:test, lint, test:component, test:reference-feature pass; test:unit passes except the pre-existing removal-fixture test (needs generated artifacts/ files absent from a fresh worktree). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
import { StrictMode, useEffect } from "react";
|
|
|
|
import { ApplicationProvider } from "../presentation/providers/application-provider.tsx";
|
|
import { PreferenceProviders } from "../presentation/providers/preference-providers.tsx";
|
|
import { ServerStateGenerationProvider } from "../presentation/adapters/query/server-state-generation-provider.tsx";
|
|
import { AppRouter } from "../presentation/routes/app-router.tsx";
|
|
import type { RuntimeComposition } from "./create-runtime-composition.ts";
|
|
|
|
/**
|
|
* Production provider tree. Tests import this component so the validated
|
|
* composition is proven against the same provider order used by main.
|
|
*/
|
|
/**
|
|
* §6.7 step 16 / §17.5. Optional runtime starts from the first committed
|
|
* effect, never during render and never during composition. StrictMode double
|
|
* invocation is safe: `startAfterMount` returns the same in-flight promise.
|
|
*/
|
|
function PostMountRuntimeStarter({
|
|
composition,
|
|
}: Readonly<{ composition: RuntimeComposition }>) {
|
|
useEffect(() => {
|
|
void composition.optional.startAfterMount();
|
|
}, [composition]);
|
|
return null;
|
|
}
|
|
|
|
export function RuntimeApplication({
|
|
composition,
|
|
}: Readonly<{ composition: RuntimeComposition }>) {
|
|
return (
|
|
<StrictMode>
|
|
{/* Preferences sit above the scope fence: a session change remounts
|
|
everything below it, and locale/theme must survive that. */}
|
|
<ApplicationProvider application={composition.application}>
|
|
<PreferenceProviders>
|
|
<ServerStateGenerationProvider
|
|
store={composition.infrastructure.serverStateGeneration}
|
|
scope={composition.infrastructure.serverStateScope}
|
|
mutationIntentFactory={
|
|
composition.infrastructure.mutationIntentFactory
|
|
}
|
|
transitionFallback={
|
|
<div
|
|
aria-busy="true"
|
|
className="state-surface state-surface--loading"
|
|
data-scope-state="scope-transition"
|
|
/>
|
|
}
|
|
>
|
|
<PostMountRuntimeStarter composition={composition} />
|
|
<AppRouter
|
|
basename={composition.config.build.routerBasePath}
|
|
buildId={composition.release.buildId}
|
|
/>
|
|
</ServerStateGenerationProvider>
|
|
</PreferenceProviders>
|
|
</ApplicationProvider>
|
|
</StrictMode>
|
|
);
|
|
}
|