Skip to content

Commit da17ac3

Browse files
fix(mobile): fast refresh releases the system palette listeners
systemColorPalettesAtom was keepAlive, so a fast refresh left the old atom mounted with its two AppState listeners. installAppearanceRuntime now holds it and releases it through App.tsx's foundation disposers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 37d2cc8 commit da17ac3

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎apps/mobile/src/features/settings/appearance/AppearancePreferencesProvider.tsx‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const systemColorPalettesAtom = Atom.make((get): MaterialYouPalettes | null => {
9595
focusSubscription.remove();
9696
});
9797
return initial;
98-
}).pipe(Atom.keepAlive, Atom.withLabel("mobile:system-color-palettes"));
98+
}).pipe(Atom.withLabel("mobile:system-color-palettes"));
9999

100100
function resolveThemeVariablesByAppearance(
101101
themeIds: MobileThemeIds,
@@ -161,9 +161,20 @@ function currentRuntimeState() {
161161
return appliedRuntimeState ?? appAtomRegistry.get(themeRuntimeStateAtom);
162162
}
163163

164-
/** App-lifetime: applies theme preferences to the native runtime. */
164+
/**
165+
* App-lifetime: applies theme preferences to the native runtime and holds the
166+
* system palette listeners. Holding them here instead of `keepAlive` lets the
167+
* fast-refresh disposer release the replaced module's AppState listeners.
168+
*/
165169
export function installAppearanceRuntime(): () => void {
166-
return appAtomRegistry.subscribe(themeRuntimeStateAtom, applyThemeRuntime, { immediate: true });
170+
const unsubscribeRuntime = appAtomRegistry.subscribe(themeRuntimeStateAtom, applyThemeRuntime, {
171+
immediate: true,
172+
});
173+
const releasePalettes = appAtomRegistry.mount(systemColorPalettesAtom);
174+
return () => {
175+
unsubscribeRuntime();
176+
releasePalettes();
177+
};
167178
}
168179

169180
export function AppearancePreferencesProvider(props: { readonly children: ReactNode }) {

0 commit comments

Comments
 (0)