fix inconsistent effects for suspended nodes#3991
Merged
Madoshakalaka merged 3 commits intomasterfrom Apr 24, 2026
Merged
Conversation
|
Visit the preview URL for this PR (updated for commit 4dcca09): https://yew-rs-api--pr3991-fix-suspense-use-eff-vd5sx1yr.web.app (expires Fri, 01 May 2026 06:22:32 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Benchmark - coreYew MasterPull Request |
Benchmark - SSRYew MasterDetails
Pull RequestDetails
|
Size ComparisonDetails
✅ None of the examples has changed their size significantly. |
3bafe86 to
c456a5f
Compare
b3897ff to
02d9e81
Compare
The previous approach routed a resuming child's rendered through the scheduler's `rendered` queue, which drains only after the update+render queues. That worked for a single suspender but not for siblings: if A resumed while B was still pending, A's rendered still fired before the boundary un-suspended, because Suspense's render with suspended=true still doesn't shift children into the live tree. Hand the pending rendered directly to the ancestor BaseSuspense as a PendingRendered, keyed by comp_id in a Vec. BaseSuspense drains this list in its own rendered lifecycle, gated on self.suspensions.is_empty() - i.e. the commit on which reconcile has already shifted children from the detached parent into the live tree. Re-committed children absorb into the existing entry so first_render=true survives a suspend/resume/suspend/resume cycle.
02d9e81 to
4dcca09
Compare
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.
Description
Fixes #3780
This PR gives a single atomic transition for every
<Suspense>boundary: no child effect inside it observes the DOM until the boundary is fully un-suspended and the DOM is live.Opus 4.7's research on React source code:
React arrives at the same invariant by a different route. Every
<Suspense>wraps its primary content in an Offscreen fiber carrying anOffscreenPassiveEffectsConnectedvisibility bit. While the boundary is hidden the bit is off and passive effects are skipped during commit; when it flips back on,recursivelyTraverseReconnectPassiveEffectswalks the subtree and fires every deferreduseEffectat once. React stores the "defer" state as a flag on the fiber and walks the tree on each commit; This PR now store it as aBTreeMap<comp_id, PendingRendered>Vec<(usize, PendingRendered)>onBaseSuspenseand drain it in one pass when the boundary un-suspends. Same guarantee, smaller footprint given Yew doesn't have an Offscreen abstraction.BTreeMap<comp_id, PendingRendered>was first considered but given up on because it bloats each example roughly by 5kB (~5% increase) probablly because of monomorphization.Checklist
Added two regression tests. Both fail on
master.