Fix Event Replaying in Flare by Eagerly Adding Active Listeners #17933
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.
This effectively reverts part of #17513. I duplicated the event replaying tests to now include Flare too, just like the partial hydration tests already did. The existing tests only covered passive events.
The primary problem is that if there is no active listener attached, then the
IS_ACTIVE
flag isn't passed intoDEPRECATED_dispatchEventForResponderEventSystem
. So the replaying of the events, like Press, that normally listen to active events doesn't work.Replaying doesn't technically need to be active for all events. It's not guaranteed to always work to preventDefault if the code hasn't loaded yet. We could make the listeners attached as passive in the DOM but still pass the
IS_ACTIVE
flag. That would still "work" but it wouldn't actually work to prevent default.The problem is that we do use a best-effort attempt to allow
preventDefault
to work. Most of the time it just works because we are able to synchronously hydrate within the event. That's also how we preventDefault on links to prevent the browser from taking over.So I think ideally, at least some event should still be attached as active such as
submit
,click
and thekey
events. We don't have to make them all active. Notably the ones that can cause problems for scroll optimizations and such are the pointer events.