fix: params becoming undefined in outgoing components during navigation#566
Open
brenelz wants to merge 1 commit into
Open
fix: params becoming undefined in outgoing components during navigation#566brenelz wants to merge 1 commit into
brenelz wants to merge 1 commit into
Conversation
Solid 2 disposes roots created inside a computation when it re-runs, so route roots created in the routeStates memo were disposed on every navigation, killing reactive nodes they owned. Roots are now created under the Routes component owner. Route contexts also get params scoped to their own lifetime via a sticky matches memo that retains its last valid value while the route is torn down. Components, effects, and preloads in outgoing routes (e.g. kept alive by a Loading boundary) no longer observe another route's params or refetch with undefined values. Also removes the routeMatches[0] fallback that could hand a context the wrong match.
🦋 Changeset detectedLatest commit: 2596327 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 |
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.
Summary
Fixes the "2.0 router params are broken" report (params turning
undefinedin preloads/effects when navigating away, updated params reaching suspended components). Reproduction from the report: https://stackblitz.com/edit/solidjs-templates-aesc6u3m?file=src%2FApp.tsxTwo distinct bugs:
1. Route roots were disposed on every navigation
In Solid 2 beta,
createRootattaches to the current owner and is disposed when that owner's computation re-runs. The per-route roots inRouteswere created inside therouteStatesmemo, so every re-run of that memo disposed all route roots, silently killing any reactive nodes they owned. Roots are now created under theRoutescomponent owner viarunWithOwner, restoring the intended "detached root + manual disposers" semantics.2. Outgoing routes observed the next route's params
useParams(), componentparams, andpreloadall shared a single router-level proxy over the current matches. Params flip to the new route at the start of navigation, while Solid 2's deferred disposal lets the outgoing tree's computations still run - so effects re-ran and async fetches refetched withundefinedparams (especially visible with a<Loading>boundary wrapping the app keeping the outgoing tree alive). TherouteMatches[i] ?? routeMatches[0]fallback could also hand a route context another route's match entirely.Now each route context gets:
matchesAtLevelmemo that retains its last valid matches once its route no longer matches, andpreload.useParams()returns the nearest route's params (base route falls back to router-level params), andwrapParamspreservesparamsWrappersupport for non-Proxy environments.Tests
<Loading>boundary - fails onnext(outgoing component refetches with[null, null]), passes with this fixtsc, type tests, and build pass