Detect loops caused by updates during prerender #31445
Open
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.
When Meta tried rolling out enableSiblingPrerendering internally, there were reports of infinite render loops that we suspect were caused by updates triggered during the render phase. While we don't have an exact repro, we know that theoretically this is possible because any update, included one triggered as a side effect of rendering, will interrupt an in-progress prerender.
Although we already have warnings and protections against updates that occur during the render phase, the sibling prerendering experiment introduces new scenarios that could cause previously working (though technically incorrect) product code to regress.
The solution in this PR is to maintain a counter of how many times a prerender is interrupted before it successfully completes. Once the counter reaches that threshold, we disable the prerendering mechanism, effectively reverting to the behavior that's in canary today.
The counter is reset the next time the update queue is exhausted, allowing for subsequent prerenders to work as before.