Skip to content

Make e2e specs wait for hydration before touching the showcase - #408

Merged
TrevorBurnham merged 1 commit into
jameskerr:mainfrom
melihozcan1:fix/e2e-wait-for-hydration
Nov 28, 2026
Merged

TrevorBurnham merged 1 commit into
jameskerr:mainfrom
melihozcan1:fix/e2e-wait-for-hydration

Conversation

@melihozcan1

Copy link
Copy Markdown
Contributor

Summary

Fixes the intermittent budget-spec.cy.js failure ("updates folder totals when an expense moves between folders"), first reported in #404. It also failed on #407.

How often: in the last 100 Build & Test runs, 7 of the 9 failures were this test, always the same assertion ('📂Entertainment$0' where $60 was expected), on 5 unrelated branches. That's about 1 in 5 of the runs that reached Cypress since the spec landed in #401. Branches failed and then passed on the next commit with no related change. The spec and pages/budget.tsx haven't changed since #401, so this is not a regression. The test has been racy since it was added.

Cause: the showcase is a Next static export, so /budget arrives as HTML with all 15 rows already rendered. cy.visit only waits for load, and React 18 hydrates in time slices that can finish after it. When Cypress fires the synthetic drag before hydration, react-dnd hasn't attached its listeners yet, and the drag does nothing. There's no error, because no handler runs at all. Every drag spec has this race. Budget loses it because it's alphabetically first, so it runs on a cold browser where hydration is slowest.

Repro: a throwaway spec (not committed) delayed the page chunk with setTimeout(…, 1500) via cy.intercept, so the rows are on screen while React hasn't hydrated. On main, the budget drag fails with exactly the CI message, and the drag-out drag fails the same way. With this PR, both pass.

Fix:

  • pages/_app.tsx sets data-hydrated on <html> in a useEffect. Passive effects run after the commit's layout effects, which is where react-dnd registers its sources and sets up the backend listeners, so the marker means the page is interactive.
  • New cy.visitHydrated(url) command: cy.visit(url), then wait for html[data-hydrated]. All five specs use it.

The marker is not in the exported HTML. It only appears once React runs.

Checklist

  • Added a .changes/ entry describing the change (see .changes/README.md), or applied the skip-changelog label if it has no user-facing effect.
  • yarn lint, yarn fmt:check, and yarn workspace react-arborist test pass (warning-clean — see AGENTS.md).

No changeset: test and showcase only, nothing in modules/react-arborist/src. yarn workspace e2e: 22/22 locally, plus both repro cases with hydration delayed.

Copilot AI balanced review requested due to automatic review settings November 28, 2026 19:37
@netlify

netlify Bot commented Nov 28, 2026

Copy link
Copy Markdown

👷 Deploy request for react-arborist pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 7d64481

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@TrevorBurnham
TrevorBurnham merged commit 2049d21 into jameskerr:main Nov 28, 2026
2 checks passed
@TrevorBurnham

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants