Skip to content

Commit 9bcf29c

Browse files
antonisclaude
andcommitted
fix(tracing): Guard getNewScreenTimeToDisplay behind enableTimeToInitialDisplay
NATIVE.getNewScreenTimeToDisplay() was called on every navigation state change regardless of whether enableTimeToInitialDisplay was enabled. This native bridge call posts to the main thread and registers a Choreographer callback (Android) or CADisplayLink (iOS) to capture the next frame timestamp. On low-end devices (Fire TV, Chromecast) this is measurable overhead that the user could not avoid even after setting enableTimeToInitialDisplay: false. The dispatch-time native calls (setActiveSpanId, navigationProcessingSpan) were already correctly guarded behind the flag. This aligns the state-change-time call with the same guard. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4ff35e2 commit 9bcf29c

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

packages/core/src/js/tracing/reactnavigation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,9 @@ export const reactNavigationIntegration = ({
438438
return undefined;
439439
}
440440

441-
addTimeToInitialDisplayFallback(latestNavigationSpan.spanContext().spanId, NATIVE.getNewScreenTimeToDisplay());
441+
if (enableTimeToInitialDisplay) {
442+
addTimeToInitialDisplayFallback(latestNavigationSpan.spanContext().spanId, NATIVE.getNewScreenTimeToDisplay());
443+
}
442444

443445
if (previousRoute?.key === route.key) {
444446
debug.log(`[${INTEGRATION_NAME}] Navigation state changed, but route is the same as previous.`);

packages/core/test/tracing/reactnavigation.ttid.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,16 @@ describe('React Navigation - TTID', () => {
585585
}),
586586
);
587587
});
588+
589+
test('should not call getNewScreenTimeToDisplay when ttid is disabled', () => {
590+
jest.runOnlyPendingTimers(); // Flush app start transaction
591+
592+
mockWrapper.NATIVE.getNewScreenTimeToDisplay.mockClear();
593+
mockedNavigation.navigateToNewScreen();
594+
jest.runOnlyPendingTimers(); // Flush navigation transaction
595+
596+
expect(mockWrapper.NATIVE.getNewScreenTimeToDisplay).not.toHaveBeenCalled();
597+
});
588598
});
589599

590600
describe('ttid for preloaded/seen routes', () => {

0 commit comments

Comments
 (0)