Skip to content

Keep the previous route until the incoming route stops suspending - #166

Open
JoseCMRocha wants to merge 1 commit into
preactjs:mainfrom
JoseCMRocha:rerender-incoming-route
Open

JoseCMRocha wants to merge 1 commit into
preactjs:mainfrom
JoseCMRocha:rerender-incoming-route

Conversation

@JoseCMRocha

@JoseCMRocha JoseCMRocha commented Nov 10, 2026 •

Copy link
Copy Markdown

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, onRouteChange and 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 Suspense does, 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

  • During a transition, the incoming route's components above the one that suspended re-render once per resolve (the route isn't shown yet).
  • The update no longer waits a tick during transitions. I couldn't find why it did; the suite passes on Preact 10 and 11.
  • A synchronous options.debounceRendering renders the route twice per resolve (still correct).
  • Unchanged from main: a re-render of the Router's parent during a transition (e.g. state set in onLoadStart) still drops the previous route, and a memo between 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.

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-bot

changeset-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fbe5280

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
preact-iso Patch

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

@rschristian

Copy link
Copy Markdown
Member

The PR description reads a lot like an LLM which, when undisclosed, is against our Code of Conduct FWIW.

We recognize that LLM's have become an integral tool for many users, however when using LLMs to help write issues or pull requests, disclose this. Transparency preserves the collaborative integrity that makes open-source communities work. It's the difference between "I used AI to help structure this bug report" (honest, helpful) and silently passing off generated content as your own analysis (deceptive, counterproductive). We as maintainers want to engage with humans rather than LLM-generated messages, put time in your issue report and that will be reflected back.

Examples of unacceptable behavior by participants include:

  • The use of sexualized language or imagery and unwelcome sexual attention or advances
  • Trolling, insulting/derogatory comments, and personal or political attacks
  • Public or private harassment
  • Publishing others' private information, such as a physical or electronic address, without explicit permission
  • Other conduct which could reasonably be considered inappropriate in a professional setting
  • Writing an issue, pull request or comments through an LLM without disclosing this

@JoseCMRocha

Copy link
Copy Markdown
Author

The PR description reads a lot like an LLM which, when undisclosed, is against our Code of Conduct FWIW.

We recognize that LLM's have become an integral tool for many users, however when using LLMs to help write issues or pull requests, disclose this. Transparency preserves the collaborative integrity that makes open-source communities work. It's the difference between "I used AI to help structure this bug report" (honest, helpful) and silently passing off generated content as your own analysis (deceptive, counterproductive). We as maintainers want to engage with humans rather than LLM-generated messages, put time in your issue report and that will be reflected back.
Examples of unacceptable behavior by participants include:

  • The use of sexualized language or imagery and unwelcome sexual attention or advances
  • Trolling, insulting/derogatory comments, and personal or political attacks
  • Public or private harassment
  • Publishing others' private information, such as a physical or electronic address, without explicit permission
  • Other conduct which could reasonably be considered inappropriate in a professional setting
  • Writing an issue, pull request or comments through an LLM without disclosing this

Sorry, yes, updated.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Router drops the previous route when the incoming route suspends twice (lazy() code, then data)

2 participants