Skip to content

Commit 567a933

Browse files
fix(mobile): showcase navigation retries when the thread shell changes
The coordinator dispatched each scene's navigation once per (requested, on-screen) scene pair, so a dispatch that did not move the route stalled the capture. On main the navigation effect re-ran whenever the showcase thread shell changed; the dedupe now includes the shell, matching that. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 749f3dd commit 567a933

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

‎apps/mobile/src/features/showcase/ShowcaseCaptureCoordinator.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import {
4040
SHOWCASE_THREAD_ID,
4141
showcaseReadinessKey,
4242
showcaseSceneOnScreen,
43+
shouldNavigateToShowcaseScene,
44+
type ShowcaseNavigationTarget,
4345
} from "./showcaseCaptureModel";
4446
import {
4547
buildShowcasePendingTasks,
@@ -127,7 +129,7 @@ export function installShowcaseCapture(
127129
let requestedScene: ShowcaseScene | null = null;
128130
let pendingTasks: Run | null = null;
129131
let agentActivity: Run | null = null;
130-
let lastNavigation: string | null = null;
132+
let lastNavigation: ShowcaseNavigationTarget | null = null;
131133
let readiness: { key: string; cancel: () => void } | null = null;
132134
const isCancelled = (run?: Run) => () => disposed || run?.cancelled === true;
133135

@@ -308,10 +310,11 @@ export function installShowcaseCapture(
308310
: null;
309311

310312
if (requestedScene !== null && hasFixture && showcaseThread && rootState) {
311-
const navigation = `${requestedScene}|${scene}`;
313+
const navigation = { requestedScene, scene, thread: showcaseThread };
314+
// Arriving forgets the target, so leaving the scene again navigates back.
312315
if (scene === requestedScene) {
313316
lastNavigation = null;
314-
} else if (navigation !== lastNavigation) {
317+
} else if (shouldNavigateToShowcaseScene(lastNavigation, navigation)) {
315318
lastNavigation = navigation;
316319
rootNavigationRef.dispatch({
317320
...showcaseNavigationAction(

‎apps/mobile/src/features/showcase/showcaseCaptureModel.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
isShowcaseThemeApplied,
55
showcaseReadinessKey,
66
showcaseSceneOnScreen,
7+
shouldNavigateToShowcaseScene,
78
type ShowcaseReadinessInput,
89
} from "./showcaseCaptureModel";
910

@@ -84,3 +85,15 @@ describe("showcaseReadinessKey", () => {
8485
expect(showcaseReadinessKey({ ...drawn, renderReports: 2 })).not.toBe(firstDraw);
8586
});
8687
});
88+
89+
describe("shouldNavigateToShowcaseScene", () => {
90+
it("dispatches again when the thread shell changes while the scene is still not on screen", () => {
91+
const shell = { id: "remote-command-center" };
92+
const first = { requestedScene: "review", scene: "threads", thread: shell } as const;
93+
expect(shouldNavigateToShowcaseScene(null, first)).toBe(true);
94+
expect(shouldNavigateToShowcaseScene(first, { ...first })).toBe(false);
95+
expect(shouldNavigateToShowcaseScene(first, { ...first, thread: { ...shell } })).toBe(true);
96+
expect(shouldNavigateToShowcaseScene(first, { ...first, scene: "thread" })).toBe(true);
97+
expect(shouldNavigateToShowcaseScene(first, { ...first, scene: "review" })).toBe(false);
98+
});
99+
});

‎apps/mobile/src/features/showcase/showcaseCaptureModel.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,31 @@ export function showcaseSceneOnScreen(
2727
: routeScene;
2828
}
2929

30+
export interface ShowcaseNavigationTarget {
31+
readonly requestedScene: ShowcaseScene;
32+
readonly scene: ShowcaseScene | null;
33+
/** The showcase thread shell; a new shell (or environment) is a new target to navigate to. */
34+
readonly thread: object;
35+
}
36+
37+
/**
38+
* Whether to dispatch the navigation for `next`, given the target last dispatched. A target is
39+
* dispatched once, and again whenever any part of it changes, so a dispatch that did not move
40+
* the route is retried when the thread shell or route updates.
41+
*/
42+
export function shouldNavigateToShowcaseScene(
43+
last: ShowcaseNavigationTarget | null,
44+
next: ShowcaseNavigationTarget,
45+
): boolean {
46+
return (
47+
next.scene !== next.requestedScene &&
48+
(last === null ||
49+
last.requestedScene !== next.requestedScene ||
50+
last.scene !== next.scene ||
51+
last.thread !== next.thread)
52+
);
53+
}
54+
3055
export function isShowcaseThemeApplied(input: {
3156
readonly launchRequestRead: boolean;
3257
readonly requestedTheme: MobileThemeId | null;

0 commit comments

Comments
 (0)