fix(presentation): keep preferences above the scope fence, dispose routers (R-8.3)
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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e5ef6ba236
commit
ddf74ed6e9
@@ -1,6 +1,7 @@
|
||||
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";
|
||||
@@ -28,28 +29,32 @@ export function RuntimeApplication({
|
||||
}: Readonly<{ composition: RuntimeComposition }>) {
|
||||
return (
|
||||
<StrictMode>
|
||||
<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"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<ApplicationProvider application={composition.application}>
|
||||
<PostMountRuntimeStarter composition={composition} />
|
||||
<AppRouter
|
||||
basename={composition.config.build.routerBasePath}
|
||||
buildId={composition.release.buildId}
|
||||
/>
|
||||
</ApplicationProvider>
|
||||
</ServerStateGenerationProvider>
|
||||
{/* 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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user