From b622dc3770a4b791afd75cd0d881eb2e8b145237 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Tue, 1 Sep 2026 16:35:31 +0200 Subject: [PATCH] test(tanstackstart): Deterministically match the server-side error event on Cloudflare The server-function error test flaked: it asserts the mechanism is `auto.middleware.tanstackstart.server_function` but occasionally received `auto.browser.global_handlers.onunhandledrejection`. The thrown error propagates back to the client over the server-function RPC and is captured a second time there with the same message. The `waitForError` predicate matched on message only, so it raced the two events and sometimes resolved with the client-side duplicate. Match the server mechanism as well so the correct event is always selected. The API-route test carries the identical latent race, so harden that predicate too. This mirrors the fix already applied to the tanstackstart-react app in #22137. Co-Authored-By: Claude Opus 5 (1M context) --- .../tests/errors.test.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/tests/errors.test.ts b/dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/tests/errors.test.ts index db34cb3a908d..f03a611e9592 100644 --- a/dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/tests/errors.test.ts +++ b/dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/tests/errors.test.ts @@ -33,7 +33,13 @@ test('Sends client-side error to Sentry', async ({ page }) => { test('Sends server-side function error to Sentry', async ({ page }) => { const errorEventPromise = waitForError('tanstackstart-react-cloudflare', errorEvent => { - return errorEvent?.exception?.values?.[0]?.value === 'Sentry Server Function Test Error'; + // The thrown error propagates back to the client over the server-function RPC and is also + // captured there as an `onunhandledrejection` with the same message. Match on the server-function + // mechanism so we deterministically pick the server-side event instead of racing the client one. + return ( + errorEvent?.exception?.values?.[0]?.value === 'Sentry Server Function Test Error' && + errorEvent?.exception?.values?.[0]?.mechanism?.type === 'auto.middleware.tanstackstart.server_function' + ); }); await page.goto(`/`); @@ -62,7 +68,12 @@ test('Sends server-side function error to Sentry', async ({ page }) => { test('Sends API route error to Sentry', async ({ page }) => { const errorEventPromise = waitForError('tanstackstart-react-cloudflare', errorEvent => { - return errorEvent?.exception?.values?.[0]?.value === 'Sentry API Route Test Error'; + // As with the server-function test, guard against a same-message client-side duplicate by + // matching the server request mechanism, so we always assert against the server-side event. + return ( + errorEvent?.exception?.values?.[0]?.value === 'Sentry API Route Test Error' && + errorEvent?.exception?.values?.[0]?.mechanism?.type === 'auto.middleware.tanstackstart.request' + ); }); await page.goto(`/`);