Skip to content

Commit 70b2b6c

Browse files
committed
Stop relying on idle state
1 parent 80ef73e commit 70b2b6c

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

packages/react/src/reactrouter-compat-utils/instrumentation.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,17 @@ export function createV6CompatibleWrapCreateBrowserRouter<
259259
}
260260

261261
router.subscribe((state: RouterState) => {
262-
// Mark pageload as complete on first PUSH navigation or when pageload span ends
263-
if (state.historyAction === 'PUSH') {
264-
isInitialPageloadComplete = true;
265-
} else if (!isInitialPageloadComplete && state.navigation.state === 'idle') {
262+
// Check if pageload span has ended to mark completion
263+
if (!isInitialPageloadComplete) {
266264
const currentRootSpan = getActiveRootSpan();
267265
const isStillInPageload = currentRootSpan && spanToJSON(currentRootSpan).op === 'pageload';
266+
268267
if (!isStillInPageload) {
269268
isInitialPageloadComplete = true;
270-
return; // Don't handle the POP that completes the initial pageload
269+
// Don't handle this specific callback if it's a POP that marks completion
270+
if (state.historyAction === 'POP') {
271+
return;
272+
}
271273
}
272274
}
273275

@@ -371,15 +373,17 @@ export function createV6CompatibleWrapCreateMemoryRouter<
371373
let isInitialPageloadComplete = false;
372374

373375
router.subscribe((state: RouterState) => {
374-
// Mark pageload as complete on first PUSH navigation or when pageload span ends
375-
if (state.historyAction === 'PUSH') {
376-
isInitialPageloadComplete = true;
377-
} else if (!isInitialPageloadComplete && state.navigation.state === 'idle') {
376+
// Check if pageload span has ended to mark completion
377+
if (!isInitialPageloadComplete) {
378378
const currentRootSpan = getActiveRootSpan();
379379
const isStillInPageload = currentRootSpan && spanToJSON(currentRootSpan).op === 'pageload';
380+
380381
if (!isStillInPageload) {
381382
isInitialPageloadComplete = true;
382-
return; // Don't handle the POP that completes the initial pageload
383+
// Don't handle this specific callback if it's a POP that marks completion
384+
if (state.historyAction === 'POP') {
385+
return;
386+
}
383387
}
384388
}
385389

0 commit comments

Comments
 (0)