Skip to content

Commit fd62e5e

Browse files
fix(mobile): disarm the first-paint valve once any frame has painted
expo-updates disarms its OTA recovery tasks at RN's first-native-view marker, which rides the first commit ANYWHERE in the root tree — providers above the navigation seam mount native views too. If a shell frame ever paints before Home's first commit, a Home crash afterwards is already 'after content appeared' for expo: a rethrow there would be a plain crash with the recovery tasks removed — strictly worse than the fallback. So the valve now also requires that the app has never completed a commit, latched by a sentinel layout effect that flips inside that very first commit and therefore stays false exactly when a render-phase throw discards it. In the all-at-once launch (the pre-PR world for bad OTAs) the valve fires and the startup-error pipeline runs; in an early-shell world it self-disarms and the fallback wins, matching the fact that cached-update fallback was never available in that world even on main.
1 parent cb480a0 commit fd62e5e

6 files changed

Lines changed: 98 additions & 15 deletions

File tree

‎apps/mobile/src/App.tsx‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Linking from "expo-linking";
22
import * as SplashScreen from "expo-splash-screen";
3-
import { useEffect } from "react";
3+
import { useEffect, useLayoutEffect } from "react";
44
import { StatusBar, View } from "react-native";
55
import { GestureHandlerRootView } from "react-native-gesture-handler";
66
import { KeyboardProvider } from "react-native-keyboard-controller";
@@ -20,6 +20,7 @@ import {
2020
import { RootStack } from "./Stack";
2121
import { appAtomRegistry } from "./state/atom-registry";
2222
import { OverlayPortalHost } from "./components/OverlayPortal";
23+
import { markAppRootCommitted } from "./components/app-first-commit";
2324
import { shouldHandleAppLink } from "./lib/appLinking";
2425
import { useMobileNavigationTheme } from "./lib/useMobileNavigationTheme";
2526
import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator";
@@ -53,6 +54,21 @@ function SplashScreenCoordinator() {
5354
return null;
5455
}
5556

57+
/**
58+
* Records the first completed commit of the app tree. expo-updates disarms
59+
* OTA startup-error recovery at RN's first-native-view marker, which rides
60+
* ANY commit — so the Home boundary's first-paint fatal valve must know
61+
* whether a frame has ever painted anywhere, not just inside Home. A layout
62+
* effect runs inside the commit itself: if a render-phase throw discards the
63+
* first commit, this never fires and the valve stays armed.
64+
*/
65+
function FirstCommitSentinel() {
66+
useLayoutEffect(() => {
67+
markAppRootCommitted();
68+
}, []);
69+
return null;
70+
}
71+
5672
export default function App() {
5773
return (
5874
<RegistryContext.Provider value={appAtomRegistry}>
@@ -71,6 +87,7 @@ function AppContent() {
7187

7288
return (
7389
<>
90+
<FirstCommitSentinel />
7491
<SplashScreenCoordinator />
7592
<SubscriptionUsageCoordinator />
7693
<GestureHandlerRootView className="flex-1">

‎apps/mobile/src/Stack.tsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,13 @@ function GuardedScreenLayout(props: {
804804
scope={`screen:${props.route.name}`}
805805
routeName={props.route.name}
806806
// Cold-launch OTA lockout guard: Home hosts checkForAppUpdateOnLaunch,
807-
// so if Home crashes before ever painting, let it stay fatal (rethrow →
808-
// ErrorRecovery rollback + its startup log) instead of stranding the
809-
// user on a fallback whose update check can never run. Once Home has
810-
// painted, failures recover in-session like every other screen.
807+
// so if Home crashes before ANY frame has ever painted, let it stay
808+
// fatal (rethrow from the failed render pass → expo-updates' full
809+
// startup-error pipeline) instead of stranding the user on a fallback
810+
// whose update check can never run. FirstCommitSentinel in App.tsx
811+
// disarms this once any commit has painted, because expo disarms its
812+
// recovery tasks at that same first-view marker. Any later failure
813+
// recovers in-session like every other screen.
811814
fatalIfFirstPaintFails={props.route.name === "Home"}
812815
// In split view the Thread route stays mounted while a sidebar selection
813816
// swaps its params; new params are new input and must not inherit a

‎apps/mobile/src/components/RenderErrorBoundary.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { SymbolView } from "./AppSymbol";
55
import { AppText as Text } from "./AppText";
66
import { MaterialButton } from "./MaterialButton";
77
import { tryCopyTextWithHaptic } from "../lib/copyTextWithHaptic";
8+
import { hasAppRootCommitted } from "./app-first-commit";
89
import {
910
describeRenderError,
1011
readErrorStack,
@@ -117,6 +118,7 @@ export class RenderErrorBoundary extends Component<
117118
shouldRethrowAsFatal({
118119
fatalIfFirstPaintFails: this.props.fatalIfFirstPaintFails === true,
119120
childCommitted: this.childCommitted,
121+
appRootCommitted: hasAppRootCommitted(),
120122
})
121123
) {
122124
// Cold-launch Home failure: rethrow inside this failed render pass.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Whether the app's root tree has ever completed a React commit.
3+
*
4+
* Why this exists: expo-updates 57 disarms its OTA startup-error recovery at
5+
* RN's CONTENT_APPEARED marker, which fires when the first native view is
6+
* added to the root view — i.e. when ANY commit has painted, not when the
7+
* Home screen specifically has. The Home first-paint fatal valve is only
8+
* equivalent to the pre-boundary behavior while nothing has painted; once
9+
* any frame exists, a rethrow is just a crash with no recovery tasks left,
10+
* so the valve must disarm itself. This flag flips false→true exactly once,
11+
* inside the first successful commit (the sentinel's layout effect is part
12+
* of that commit), which is the same commit CONTENT_APPEARED rides on.
13+
*/
14+
let appRootCommitted = false;
15+
16+
export function markAppRootCommitted(): void {
17+
appRootCommitted = true;
18+
}
19+
20+
export function hasAppRootCommitted(): boolean {
21+
return appRootCommitted;
22+
}
23+
24+
/** Test-only: reset the latch between cases. */
25+
export function resetAppRootCommitted(): void {
26+
appRootCommitted = false;
27+
}

‎apps/mobile/src/components/render-error-boundary-model.test.ts‎

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,21 +205,47 @@ describe("shouldRethrowAsFatal", () => {
205205
// Bad-OTA cold launch: Home throws before ever committing healthy
206206
// children — that is exactly the failure expo-updates' rollback exists
207207
// for, so it must not be swallowed into a fallback.
208-
expect(shouldRethrowAsFatal({ fatalIfFirstPaintFails: true, childCommitted: false })).toBe(
209-
true,
210-
);
208+
expect(
209+
shouldRethrowAsFatal({
210+
fatalIfFirstPaintFails: true,
211+
childCommitted: false,
212+
appRootCommitted: false,
213+
}),
214+
).toBe(true);
211215
});
212216

213217
it("recovers in-session failures after the first successful paint", () => {
214-
expect(shouldRethrowAsFatal({ fatalIfFirstPaintFails: true, childCommitted: true })).toBe(
215-
false,
216-
);
218+
expect(
219+
shouldRethrowAsFatal({
220+
fatalIfFirstPaintFails: true,
221+
childCommitted: true,
222+
appRootCommitted: true,
223+
}),
224+
).toBe(false);
225+
});
226+
227+
it("disarms once any frame has painted elsewhere in the root tree", () => {
228+
// CONTENT_APPEARED rides the first commit ANYWHERE (providers above the
229+
// seam mount native views too). After that a rethrow is a plain crash
230+
// with expo's recovery tasks already removed — strictly worse than the
231+
// fallback — so a Home-specific non-commit must not re-fire the valve.
232+
expect(
233+
shouldRethrowAsFatal({
234+
fatalIfFirstPaintFails: true,
235+
childCommitted: false,
236+
appRootCommitted: true,
237+
}),
238+
).toBe(false);
217239
});
218240

219241
it("never rethrows for screens without the cold-launch valve", () => {
220-
expect(shouldRethrowAsFatal({ fatalIfFirstPaintFails: false, childCommitted: false })).toBe(
221-
false,
222-
);
242+
expect(
243+
shouldRethrowAsFatal({
244+
fatalIfFirstPaintFails: false,
245+
childCommitted: false,
246+
appRootCommitted: false,
247+
}),
248+
).toBe(false);
223249
});
224250
});
225251

‎apps/mobile/src/components/render-error-boundary-model.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,20 @@ export function threadFeedResetKeys(
7171
* in-session recovery. A fatal is deliberately NOT recorded in the
7272
* render-error log: ErrorRecovery already logs it and Diagnostics reads
7373
* that log, and recording both would double-report the same crash.
74+
*
75+
* `appRootCommitted` closes a timing hole: CONTENT_APPEARED rides the first
76+
* commit ANYWHERE in the root tree (providers above the seam mount native
77+
* views too), not the first Home commit. If any frame has already painted,
78+
* a rethrow would arrive after expo disarmed its recovery tasks — strictly
79+
* worse than the fallback — so the valve only fires while nothing has ever
80+
* committed.
7481
*/
7582
export function shouldRethrowAsFatal(args: {
7683
readonly fatalIfFirstPaintFails: boolean;
7784
readonly childCommitted: boolean;
85+
readonly appRootCommitted: boolean;
7886
}): boolean {
79-
return args.fatalIfFirstPaintFails && !args.childCommitted;
87+
return args.fatalIfFirstPaintFails && !args.childCommitted && !args.appRootCommitted;
8088
}
8189

8290
/**

0 commit comments

Comments
 (0)