Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] fix(fireEvent): Flush effects from discrete events immediately #898

Closed

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Apr 10, 2021

I get strong enzyme vibes from this PR (considering we rely on React implementation details). This PR is more exploratory and any discussion should probably be directed at facebook/react#21202 where I'd want this fix to land ideally.

BREAKING CHANGE
Importing from @testing-library/react will no longer wrap event
dispatches of @testing-library/dom in act(() => {}).

Essentially reverting #685. This will affect user-event but I don't see any other way. Wrapping in act(() => {}) in user-event is event worse since user-event is explicitly about user events which fireEevent.click was not about.

What:

If effects in a portaled component were scheduled from discrete event dispatches (e.g. fireEevent.click) then these effects were not flushed during that event but before we returned. This behavior does not match the behavior of events in response to a user interaction.

Why:

fireEvent majority usage is to test event dispatches in response to user interactions.

How:

discrete events are no longer wrapped in act(() => {}). Their updates are still flushed when we return though.

Checklist:

@eps1lon eps1lon added bug Something isn't working BREAKING CHANGE This change will require a major version bump labels Apr 10, 2021
@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 10, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 29da123:

Sandbox Source
React Configuration
react-testing-library-examples Configuration

BREAKING CHANGE:
Importing from `@testing-library/react` will no longer wrap event
dispatches of `@testing-library/dom` in `act(() => {})`
@eps1lon eps1lon force-pushed the feat/discrete-events-no-act branch from 54ec5ab to 5f73381 Compare April 10, 2021 08:43
@codecov
Copy link

codecov bot commented Apr 10, 2021

Codecov Report

Merging #898 (29da123) into master (58150b9) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #898   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          140       150   +10     
  Branches        28        28           
=========================================
+ Hits           140       150   +10     
Impacted Files Coverage Δ
src/pure.js 100.00% <ø> (ø)
src/fire-event.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 58150b9...29da123. Read the comment docs.

@eps1lon
Copy link
Member Author

eps1lon commented Jun 12, 2021

Will be handled in React 18: reactwg/react-18#21 (reply in thread)

@eps1lon eps1lon closed this Jun 12, 2021
@eps1lon eps1lon deleted the feat/discrete-events-no-act branch June 12, 2021 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGE This change will require a major version bump bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant