Skip to content

test(react-context-selector): add cypress regression for eager-bailout (React 18)#36033

Merged
layershifter merged 6 commits intomasterfrom
layershifter/context-selector-cypress-regression
Apr 24, 2026
Merged

test(react-context-selector): add cypress regression for eager-bailout (React 18)#36033
layershifter merged 6 commits intomasterfrom
layershifter/context-selector-cypress-regression

Conversation

@layershifter
Copy link
Copy Markdown
Member

@layershifter layershifter commented Apr 23, 2026

Summary

Why cypress and not jest?

The bug: React runs the function component body then discards the JSX via bailoutOnAlreadyFinishedWork. The DOM does not change — but the function already ran. A commit-timed useEffect cannot observe this, so jest/jsdom tests pass even when the bug is present.

Expected CI behavior

Companion work:

🤖 Generated with Claude Code

…t (React 18)

Adds cypress component-testing scaffold (matches `@fluentui/workspace-plugin`
cypress-component-configuration generator output) to the package and a
regression test for the `useContextSelector` eager-bailout pitfall described
in the context-selector-tearing RFC.

The bug is not observable via jest + `@testing-library/react`: React runs
the function body and then discards the render via
`bailoutOnAlreadyFinishedWork`, so no commit happens and `useEffect` never
fires. The cypress test uses an in-render counter on `window` to catch the
discarded-render leak (item 1's render count grows from 3 to 4 on click 3).

The glitch is React-18-only (React 19 relaxed the eager-bailout precondition),
so the assertion is meaningful under `nx run react-context-selector:test-rit--18--e2e`.
Expected to be RED on master (v1 hook) and GREEN once #36002 lands.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2026

📊 Bundle size report

✅ No changes found

…en retries

Cypress retries a failing test up to 5 times by default and reuses the
component iframe window across retries. The render counter on `window`
was accumulating across attempts (5 attempts × 1 mount-render = 5),
making the very first post-mount assertion fail before the actual
regression check was reached.

Reset the counter in `beforeEach` so each attempt sees an absolute,
not-cumulative count.
@github-actions
Copy link
Copy Markdown

Pull request demo site: URL

… dimensions

The previous test used a bare div wrapping empty divs which had 0 height,
so cy.click() on the provider failed its visibility check. Wrap in a
button (so clicks pass visibility) and render visible text content in
items.
… of window

Replace window.__useContextSelectorRenderCounts__ with a module-level
RENDER_COUNTS object. Simpler — no window type munging, no lazy init.
Reset via in-place mutation in beforeEach so cy.wrap(RENDER_COUNTS).should(...)
sees the mutation on each cypress retry.
@layershifter layershifter marked this pull request as ready for review April 23, 2026 11:28
@layershifter layershifter requested review from a team as code owners April 23, 2026 11:28
@layershifter layershifter enabled auto-merge (squash) April 24, 2026 11:25
@layershifter layershifter merged commit 0392152 into master Apr 24, 2026
15 checks passed
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