Repository navigation
Keep the previous route until the incoming route stops suspending - #166
JoseCMRocha wants to merge 1 commit into
Conversation
When the incoming route suspended more than once (e.g. lazy() code, then data), the previous route was dropped as soon as the first promise resolved: the Router re-rendered an unchanged vnode, which Preact skips, so the second suspension happened outside the Router's render. While the previous route is kept, the Router now re-renders the incoming route itself when a promise resolves (as compat's Suspense does), in the same render pass as the route's own update, so every suspension happens in the Router's render and the route still renders once per resolve. Each promise is retried once, so a route that keeps throwing a resolved promise can't loop.
🦋 Changeset detectedLatest commit: fbe5280 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The PR description reads a lot like an LLM which, when undisclosed, is against our Code of Conduct FWIW.
|
Sorry, yes, updated. |
I used AI to help structure this bug report, write pr description, run code reviews on the possible fix, assist in writing code, rubber duck ideas, find possible tests and write them to prevent regression, also traverse the code to find possible break of uses with the code if the proposed change ever is approved.
Fixes #165
Cause
When a promise resolves, the Router re-renders with the unchanged route vnode, which Preact skips. The route only re-renders through its own update (as
lazy()does), so a second suspension (e.g.lazy()code, then data) happens outside the Router's render and the previous route is dropped.onLoadEnd,onRouteChangeand the scroll to top fire then too.Fix (both routers)
While the previous route is kept, the Router re-renders the incoming route itself when a promise resolves, as compat's
Suspensedoes, so every suspension happens in its own render. It updates in the same pass as the route's own update instead of a tick later, so Preact renders the Router first and the route only once. Each promise is retried once, so a route that keeps throwing a resolved promise can't loop. +74 B gzipped.Worth checking
options.debounceRenderingrenders the route twice per resolve (still correct).main: a re-render of the Router's parent during a transition (e.g. state set inonLoadStart) still drops the previous route, and amemobetween the route and the suspending component blocks the re-render.Tests (both routers, promises resolved by hand)
Previous route kept through code and two requests; events only after load; navigating away mid-load; custom render scheduling; a route that never updates itself; one render per resolve; new params; in-place suspensions after load; no loop on a resolved promise. Five of them fail on
main. The full suite passes on Preact 10.26.5 and 11.2.0.