test(react-context-selector): add cypress regression for eager-bailout (React 18)#36033
Merged
layershifter merged 6 commits intomasterfrom Apr 24, 2026
Merged
Conversation
…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>
📊 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.
|
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.
dmytrokirpa
approved these changes
Apr 23, 2026
jurokapsiar
approved these changes
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@fluentui/react-context-selectorsrc/useContextSelector.cy.tsx- a 3-click cycling regression test for theuseStateeager-bailout pitfall documented in RFC: useContextSelector() amend with Option D (Relay pattern) #36001Why 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-timeduseEffectcannot observe this, so jest/jsdom tests pass even when the bug is present.Expected CI behavior
test-rit--18--e2eexpected to be 🔴 This is intentional — it proves the test catches the bug.Companion work:
🤖 Generated with Claude Code