Fix ignored setState in Safari when iframe is touched#24459
Merged
Conversation
|
Comparing: 340060c...b7b40cd Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
gaearon
commented
Apr 28, 2022
| queue.forEach(cb => cb()); | ||
| queue = []; | ||
| flushMicrotasksPrematurely = function() { | ||
| while (queue.length > 0) { |
Collaborator
Author
There was a problem hiding this comment.
This simulates the Safari behavior of trying to drain the queue until it's empty. So that we don't "fix" this by adding an infinite loop.
Proof:
<body>
<script>
let busy = true
const callback = () => {
if (busy) {
console.error('noo im busy')
queueMicrotask(callback)
} else {
console.log('im ok')
}
}
queueMicrotask(callback);
console.log("will add iframe");
const iframe = document.createElement("iframe");
iframe.src = "localhost";
document.body.appendChild(iframe);
console.log("did add iframe");
busy = false
</script>
</body>gets Safari infinitely stuck
Collaborator
Author
|
ping @acdlite |
acdlite
approved these changes
May 12, 2022
This was referenced Mar 4, 2023
This was referenced Feb 10, 2024
This was referenced Nov 10, 2024
This was referenced Nov 10, 2024
This was referenced Nov 11, 2024
This was referenced Nov 11, 2024
This was referenced Nov 11, 2024
This was referenced Nov 12, 2024
This was referenced Nov 12, 2024
This was referenced Nov 12, 2024
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.
Fixes #24458.
Just like #22459, this is caused by a Safari bug (https://bugs.webkit.org/show_bug.cgi?id=235322).
Our original solution for #22459 was #23111: if the microtask callback runs prematurely, we ignore it. This relied on the assumption that we always check for more work at the end of the task anyway. However, we don't check for more work if we aren't either rendering or committing — notably, we don't check for more work at the end of the event handler.
This fix is to allow the update to flush early. This doesn't respect batching but matches what Safari is trying to do (which is to flush everything early).