[RFC] fix(fireEvent): Flush effects from discrete events immediately #898
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.
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 eventdispatches of
@testing-library/dom
inact(() => {})
.Essentially reverting #685. This will affect
user-event
but I don't see any other way. Wrapping inact(() => {})
inuser-event
is event worse sinceuser-event
is explicitly about user events whichfireEevent.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:
docs site
I don't think we need to add docs since automatic
configure
was never documented[ ]Typescript definitions updatedPR must be revisited once Flush discrete updates immediately in a batched context facebook/react#21202 is resolved.