Skip to content

Commit 27f52d6

Browse files
fix(mobile): address review on shell UI effect removal
- CommandPalette: clear the dismiss fallback timer on unmount. - OverlayPortal: keep removal in an unmount-only effect so re-projecting keeps map order; drop the sort. - SliderRow (iOS): commit only values seen during the drag instead of reseeding the draft from props at drag start. - StackHeader: refresh the latest option factories before the inactive-tab early return. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 28a4786 commit 27f52d6

4 files changed

Lines changed: 34 additions & 18 deletions

File tree

‎apps/mobile/src/components/ui/OverlayPortal.tsx‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ const listeners = new Set<() => void>();
1414
let snapshot: Entries = new Map();
1515

1616
function emit() {
17-
// Re-projecting deletes and re-inserts an entry, so order by key (mount order)
18-
// rather than insertion order to keep overlays stacked as they opened.
19-
snapshot = new Map([...entries].sort(([left], [right]) => left - right));
17+
snapshot = new Map(entries);
2018
for (const listener of listeners) {
2119
listener();
2220
}
@@ -43,11 +41,17 @@ export function OverlayPortal(props: { readonly children: ReactNode }) {
4341
useEffect(() => {
4442
entries.set(key, props.children);
4543
emit();
46-
return () => {
44+
});
45+
46+
// Removal is unmount-only: deleting on every re-projection would move the
47+
// entry to the end of the map and restack it above overlays opened later.
48+
useEffect(
49+
() => () => {
4750
entries.delete(key);
4851
emit();
49-
};
50-
});
52+
},
53+
[key],
54+
);
5155

5256
return null;
5357
}

‎apps/mobile/src/components/ui/SliderRow.tsx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export type { SliderRowProps } from "./SliderRow.types";
1919

2020
export function SliderRow(props: SliderRowProps) {
2121
const { colors } = useControlTheme();
22-
const draft = useRef(props.value);
22+
// The value of the drag in progress; null until the drag moves.
23+
const draft = useRef<number | null>(null);
2324
const editing = useRef(false);
2425
const commit = (value: number) => {
2526
if (props.disabled) return;
@@ -57,14 +58,15 @@ export function SliderRow(props: SliderRowProps) {
5758
accessibilityValue(props.valueLabel),
5859
]}
5960
onValueChange={(value) => {
60-
draft.current = value;
6161
// Accessibility adjustments do not begin a touch editing session.
62-
if (!editing.current) commit(value);
62+
if (editing.current) draft.current = value;
63+
else commit(value);
6364
}}
6465
onEditingChanged={(isEditing) => {
6566
editing.current = isEditing;
66-
if (isEditing) draft.current = props.value;
67-
else commit(draft.current);
67+
const value = draft.current;
68+
draft.current = null;
69+
if (!isEditing && value !== null) commit(value);
6870
}}
6971
/>
7072
</NativeThemeHost>

‎apps/mobile/src/features/keyboard/CommandPalette.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,12 @@ export function CommandPalette(props: {
527527
props.onClose();
528528
pendingAction.current?.();
529529
}, [props]);
530+
useEffect(
531+
() => () => {
532+
if (dismissFallback.current !== null) clearTimeout(dismissFallback.current);
533+
},
534+
[],
535+
);
530536

531537
function close(run?: () => void) {
532538
if (closing.current) return;

‎apps/mobile/src/native/StackHeader.tsx‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,25 @@ export function NativeStackScreenOptions(props: {
197197

198198
// Stabilizing records each factory's latest closure, so it runs in the commit
199199
// phase: a render React discards must not leak its closures into the header.
200+
// It runs before the tab check so wrappers already installed in an inactive
201+
// tab's header still call the newest closures.
200202
useLayoutEffect(() => {
203+
const normalizedOptions = normalizeScreenOptions(props.options);
204+
const stableOptions = normalizedOptions
205+
? stabilizeOptionFunctions(
206+
normalizedOptions,
207+
"options",
208+
latestOptionFunctionsRef.current,
209+
optionFunctionWrappersRef.current,
210+
)
211+
: undefined;
201212
if (!tabActive) {
202213
lastAppliedOptionsSignatureRef.current = undefined;
203214
return;
204215
}
205-
const normalizedOptions = normalizeScreenOptions(props.options);
206216
if (!setOptions || !normalizedOptions) {
207217
return;
208218
}
209-
const stableOptions = stabilizeOptionFunctions(
210-
normalizedOptions,
211-
"options",
212-
latestOptionFunctionsRef.current,
213-
optionFunctionWrappersRef.current,
214-
);
215219
const signature = optionsSignature([stableOptions, props.optionsVersion]);
216220
if (lastAppliedOptionsSignatureRef.current === signature) {
217221
return;

0 commit comments

Comments
 (0)