Skip to content

Commit ad28c4d

Browse files
authored
fix(solid/tanstackrouter): Ensure web vitals are sent on pageload (#18542)
Adjusted the condition for reporting web vitals previously it would short circuit and prevent them from being reported, I included a test. similar to what we did in #18463 closes #18540
1 parent 8b2c0c2 commit ad28c4d

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

dev-packages/e2e-tests/test-applications/solid-tanstack-router/tests/routing-instrumentation.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,44 @@ test('sends a navigation transaction with a parameterized URL', async ({ page })
7070
},
7171
});
7272
});
73+
74+
test('sends pageload transaction with web vitals measurements', async ({ page }) => {
75+
const transactionPromise = waitForTransaction('solid-tanstack-router', async transactionEvent => {
76+
return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'pageload';
77+
});
78+
79+
await page.goto(`/`);
80+
81+
const transaction = await transactionPromise;
82+
83+
expect(transaction).toMatchObject({
84+
contexts: {
85+
trace: {
86+
op: 'pageload',
87+
origin: 'auto.pageload.solid.tanstack_router',
88+
},
89+
},
90+
transaction: '/',
91+
transaction_info: {
92+
source: 'route',
93+
},
94+
measurements: expect.objectContaining({
95+
ttfb: expect.objectContaining({
96+
value: expect.any(Number),
97+
unit: 'millisecond',
98+
}),
99+
lcp: expect.objectContaining({
100+
value: expect.any(Number),
101+
unit: 'millisecond',
102+
}),
103+
fp: expect.objectContaining({
104+
value: expect.any(Number),
105+
unit: 'millisecond',
106+
}),
107+
fcp: expect.objectContaining({
108+
value: expect.any(Number),
109+
unit: 'millisecond',
110+
}),
111+
}),
112+
});
113+
});

packages/solid/src/tanstackrouter.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ export function tanstackRouterBrowserTracingIntegration<R extends AnyRouter>(
6363
if (instrumentNavigation) {
6464
// The onBeforeNavigate hook is called at the very beginning of a navigation and is only called once per navigation, even when the user is redirected
6565
router.subscribe('onBeforeNavigate', onBeforeNavigateArgs => {
66-
// onBeforeNavigate is called during pageloads. We can avoid creating navigation spans by comparing the states of the to and from arguments.
67-
if (onBeforeNavigateArgs.toLocation.state === onBeforeNavigateArgs.fromLocation?.state) {
66+
// onBeforeNavigate is called during pageloads. We can avoid creating navigation spans by:
67+
// 1. Checking if there's no fromLocation (initial pageload)
68+
// 2. Comparing the states of the to and from arguments
69+
if (
70+
!onBeforeNavigateArgs.fromLocation ||
71+
onBeforeNavigateArgs.toLocation.state === onBeforeNavigateArgs.fromLocation.state
72+
) {
6873
return;
6974
}
7075

0 commit comments

Comments
 (0)