You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is part of a larger effort to remove dynamic params from server
responses except in cases where they are needed to render a Server
Component. If a param is not rendered by a Server Component, then it can
omitted from the cache key, and cached responses can be reused across
pages with different param values.
In this step, I've implemented client parsing of the params from
the response headers.
The basic approach is to split the URL into parts, then traverse the
route tree to pick off the param values, taking care to skip over things
like interception routes.
Notably, this is not how the server parses param values. The server
gets the params from the regex that's also used for routing. Originally,
I thought I'd send the regex to the client and use it there, too.
However, this ended up being needlessly complicated, because the server
regexes are also used for things like interception route matching. But
this is already encapsulated by the structure of the route tree. So it's
easier to just walk the tree and pick off the params.
My main hesitation is that there's drift between the server and client
params parsing that we'll need to keep in sync. However, I think the
solution is actually to update the server to also pick the params off
the URL, rather than use the ones passed from the base router. It's
conceptually cleaner, since it's less likely that extra concerns from
the base server leaking into the application layer. As an example,
compare the code needed to get a catchall param value in the client
versus the server implementation.
Note: Although the ultimate goal is to remove the dynamic params from
the response body (e.g. FlightRouterState), I have not done so yet this
PR. The rest of the work will be split up into multiple subsequent PRs.
Copy file name to clipboardExpand all lines: packages/next/errors.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -764,5 +764,6 @@
764
764
"763": "\\`unstable_rootParams\\` must not be used within a client component. Next.js should be preventing it from being included in client components statically, but did not in this case.",
765
765
"764": "Missing workStore in %s",
766
766
"765": "Route %s used %s inside a Route Handler. Support for this API in Route Handlers is planned for a future version of Next.js.",
767
-
"766": "%s was used inside a Server Action. This is not supported. Functions from 'next/root-params' can only be called in the context of a route."
767
+
"766": "%s was used inside a Server Action. This is not supported. Functions from 'next/root-params' can only be called in the context of a route.",
768
+
"767": "An unexpected response was received from the server."
0 commit comments