Skip to content

Commit e5c60fa

Browse files
committed
fix(tracing): Fire ExpoRouterErrorBoundary marker at wrap-call time
The wrapped boundary only mounts when Expo Router actually renders it (i.e., on an error), so a `useEffect`-based marker would undercount adoption for apps that ship the wrap but never hit a route error. Registering at wrap-call time fires as soon as the user's route file evaluates. No client is present if the wrap is called before `Sentry.init()`, but that is very rare in practice — Expo Router lazy-loads route files during navigation, so init has typically completed by then.
1 parent e9b715e commit e5c60fa

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

packages/core/src/js/tracing/expoRouterErrorBoundary.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ export interface ExpoRouterErrorBoundaryProps {
6767
export function wrapExpoRouterErrorBoundary<P extends ExpoRouterErrorBoundaryProps>(
6868
OriginalErrorBoundary: React.ComponentType<P>,
6969
): React.ComponentType<P> {
70-
const Wrapped: React.FC<P> = props => {
71-
React.useEffect(() => {
72-
registerFeatureMarker(EXPO_ROUTER_ERROR_BOUNDARY_INTEGRATION_NAME);
73-
}, []);
70+
// Register at wrap-call time (module evaluation) so the marker fires as soon
71+
// as the user's route file loads, not only when Expo Router actually renders
72+
// the boundary on an error. No-op if `Sentry.init()` has not run yet; route
73+
// files load lazily during navigation, so init has typically completed by
74+
// then.
75+
registerFeatureMarker(EXPO_ROUTER_ERROR_BOUNDARY_INTEGRATION_NAME);
7476

77+
const Wrapped: React.FC<P> = props => {
7578
// Reporting is intentionally done in `useEffect` (commit phase) rather than
7679
// during render: render must be pure, and in Concurrent Mode an in-progress
7780
// render can be discarded — we only want to report errors that React

packages/core/test/tracing/expoRouterErrorBoundary.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ describe('wrapExpoRouterErrorBoundary', () => {
8989
expect(getByTestId('fallback').props.children).toBe('boom');
9090
});
9191

92-
it('registers the ExpoRouterErrorBoundary marker on mount', () => {
93-
const Wrapped = wrapExpoRouterErrorBoundary(OriginalErrorBoundary);
94-
render(<Wrapped error={new Error('boom')} retry={jest.fn()} />);
92+
it('registers the ExpoRouterErrorBoundary marker at wrap-call time (before any mount)', () => {
93+
wrapExpoRouterErrorBoundary(OriginalErrorBoundary);
9594
expect(mockAddIntegration).toHaveBeenCalledWith({ name: EXPO_ROUTER_ERROR_BOUNDARY_INTEGRATION_NAME });
9695
});
9796

0 commit comments

Comments
 (0)