Commit 7d6f9f8
authored
test(tanstackstart-react): Wait for hydration before clicking client-error button (#21065)
## Summary
- Adds a hydration marker (`data-hydrated="true"` on `<html>`) in
`__root.tsx` of the tanstackstart-react e2e app, set in a `useEffect` so
it fires only after React hydration completes.
- Updates the two flaky client-error tests (`errors.test.ts:9`,
`tunnel.test.ts:17`) to wait on that marker before clicking the "Break
the client" button.
## Root cause (shared by three reported flakes)
[#20641](#20641),
[#20685](#20685),
and
[#20867](#20867)
all fail with the same pattern:
```
Test timeout of 30000ms exceeded.
```
…after the same test step: click "Break the client", await the error
event. The three issues differ only in which variant they were captured
in (tunnel-object, tunnel-static, proxy). Same root cause.
The "Break the client" button is server-rendered HTML; its onClick
handler (`() => { throw new Error('Sentry Client Test Error'); }`) is
attached only when React hydrates. Playwright's `toBeVisible()` polls
the DOM for visibility but doesn't wait for hydration — on slow CI runs,
the click can fire before React has attached the handler. With no
handler attached, the click does nothing, no error is thrown, the Sentry
SDK never sees an error, and `await errorEventPromise` times out at 30
s.
## Fix
In `__root.tsx`:
```tsx
useEffect(() => {
document.documentElement.setAttribute('data-hydrated', 'true');
}, []);
```
The `useEffect` only runs on the client after hydration. Tests now wait
on it explicitly:
```ts
await page.goto('/');
await page.locator('html[data-hydrated="true"]').waitFor(); // ← new
await expect(page.locator('button').filter({ hasText: 'Break the client' })).toBeVisible();
await page.locator('button').filter({ hasText: 'Break the client' }).click();
```
This is the standard Playwright + SSR-React pattern. Deterministic (no
`networkidle` flakiness), self-documenting, and the marker is now
reusable for any future client-interaction test in this app.
Fixes #20641
Fixes #20685
Fixes #20867
🤖 Generated with [Claude Code](https://claude.com/claude-code)1 parent 95b909e commit 7d6f9f8
3 files changed
Lines changed: 19 additions & 1 deletion
File tree
- dev-packages/e2e-tests/test-applications/tanstackstart-react
- src/routes
- tests
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | 22 | | |
18 | 23 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
| |||
0 commit comments