-
Notifications
You must be signed in to change notification settings - Fork 3
Update react-router monorepo to v7 (major) #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
⚠ Artifact update problemRenovate failed to update an artifact related to this branch. You probably do not want to merge this PR as-is. ♻ Renovate will retry this branch, including artifacts, only when one of the following happens:
The artifact failure details are included below: File name: package-lock.json |
15f2280 to
1a456b1
Compare
|
This PR contains the following updates:
^5.2.0->^7.0.0^5.2.0->^7.0.0Release Notes
remix-run/react-router (react-router)
v7.9.4Compare Source
Patch Changes
handle external redirects in from server actions (#14400)
New (unstable)
useRoutehook for accessing data from specific routes (#14407)For example, let's say you have an
adminroute somewhere in your app and you want any child routes ofadminto all have access to theloaderDataandactionDatafromadmin.You might even want to create a reusable widget that all of the routes nested under
admincould use:In framework mode,
useRouteknows all your app's routes and gives you TS errors when invalid route IDs are passed in:useRoutereturnsundefinedif the route is not part of the current page:Note: the
rootroute is the exception since it is guaranteed to be part of the current page.As a result,
useRoutenever returnsundefinedforroot.loaderDataandactionDataare marked as optional since they could be accessed before theactionis triggered or after theloaderthrew an error:If instead of a specific route, you wanted access to the current route's
loaderDataandactionData, you can calluseRoutewithout arguments:This usage is equivalent to calling
useLoaderDataanduseActionData, but consolidates all route data access into one hook:useRoute.Note: when calling
useRoute()(without a route ID), TS has no way to know which route is the current route.As a result,
loaderDataandactionDataare typed asunknown.If you want more type-safety, you can either narrow the type yourself with something like
zodor you can refactor your app to pass down typed props to yourAdminWidget:v7.9.3Compare Source
Patch Changes
Do not try to use
turbo-streamto decode CDN errors that never reached the server (#14385)Fix Data Mode regression causing a 404 during initial load in when
middlewareexists without anyloaderfunctions (#14393)v7.9.2Compare Source
Patch Changes
middlewareon initial load even if no loaders exist (#14348)createRoutesStubto run route middleware<RoutesStub future={{ v8_middleware: true }} />flag to enable the propercontexttypeUpdate Lazy Route Discovery manifest requests to use a singular comma-separated
pathsquery param instead of repeatedpquery params (#14321)[UNSTABLE] Add
fetcher.unstable_reset()API (#14206)Made useOutlet element reference have stable identity in-between route chages (#13382)
feat: enable full transition support for the rsc router (#14362)
In RSC Data Mode, handle SSR'd client errors and re-try in the browser (#14342)
Support
middlewareprop on<Route>for usage with a data router viacreateRoutesFromElements(#14357)Handle encoded question mark and hash characters in ancestor splat routes (#14249)
Fail gracefully on manifest version mismatch logic if
sessionStorageaccess is blocked (#14335)v7.9.1Compare Source
Patch Changes
Futureinterface naming frommiddleware->v8_middleware(#14327)v7.9.0Compare Source
Minor Changes
Stabilize middleware and context APIs. (#14215)
We have removed the
unstable_prefix from the following APIs and they are now considered stable and ready for production use:RouterContextProvidercreateContextcreateBrowserRoutergetContextoption<HydratedRouter>getContextpropPlease see the Middleware Docs, the Middleware RFC, and the Client-side Context RFC for more information.
Patch Changes
meta()JSON-LD content (#14316)hreffunction available in a react-server context (#14262)getPayload()is called to allow for "in-context" decoding and hoisting of contextual assets (#14248)href()now correctly processes routes that have an extension after the parameter or are a single optional parameter. (#13797)v7.8.2Compare Source
Patch Changes
[UNSTABLE] Remove Data Mode
future.unstable_middlewareflag fromcreateBrowserRouter(#14213)getLoadContexttype behavior change[UNSTABLE] Add
<RouterProvider unstable_onError>/<HydratedRouter unstable_onError>prop for client side error reporting (#14162)server action revalidation opt out via $SKIP_REVALIDATION field (#14154)
Properly escape interpolated param values in
generatePath()(#13530)Maintain
ReadonlyMapandReadonlySettypes in server response data. (#13092)[UNSTABLE] Delay serialization of
.dataredirects to 202 responses until after middleware chain (#14205)Fix
TypeErrorif you throw frompatchRoutesOnNavigationwhen no partial matches exist (#14198)Fix
basenameusage without a leading slash in data routers (#11671)[UNSTABLE] Update client middleware so it returns the data strategy results allowing for more advanced post-processing middleware (#14151)
v7.8.1Compare Source
Patch Changes
matchPath(#11813)basenameis set withssr:false(#13791)isRouteErrorResponseutility inreact-serverenvironments (#14166)metaandlinksRoute Exports in RSC Data Mode (#14136)data()values toResponseinstances viaResponse.json()in resource routes and middleware (#14159, #14181)v7.8.0Compare Source
Minor Changes
nonceprop toLinks&PrefetchPageLinks(#14048)loaderDataarguments/properties alongside existingdataarguments/properties to provide consistency and clarity betweenloaderDataandactionDataacross the board (#14047)Route.MetaArgs,Route.MetaMatch,MetaArgs,MetaMatch,Route.ComponentProps.matches,UIMatch@deprecatedwarnings have been added to the existingdataproperties to point users to newloaderDataproperties, in preparation for removing thedataproperties in a future major releasePatch Changes
Prevent "Did not find corresponding fetcher result" console error when navigating during a
fetcher.submitrevalidation (#14114)Bubble client-side middleware errors prior to
nextto the appropriate ancestor error boundary (#14138)Switch Lazy Route Discovery manifest URL generation to usea standalone
URLSearchParamsinstance instead ofURL.searchParamsto avoid a major performance bottleneck in Chrome (#14084)Adjust internal RSC usage of
React.useto avoid Webpack compilation errors when using React 18 (#14113)Remove dependency on
@types/nodein TypeScript declaration files (#14059)Fix types for
UIMatchto reflect that theloaderData/dataproperties may beundefined(#12206)ErrorBoundaryis being rendered, not all active matches will have loader data available, since it may have been theirloaderthat threw to trigger the boundaryUIMatch.datatype was not correctly handing this and would always reflect the presence of data, leading to the unexpected runtime errors when anErrorBoundarywas renderedmatch.dataaccesses - you should properly guard forundefinedvalues in those scenarios.[UNSTABLE] Ensure resource route errors go through
handleErrorw/middleware enabled (#14078)[UNSTABLE] Propagate returned Response from server middleware if next wasn't called (#14093)
[UNSTABLE] Allow server middlewares to return
data()values which will be converted into aResponse(#14093)[UNSTABLE] Update middleware error handling so that the
nextfunction never throws and instead handles any middleware errors at the properErrorBoundaryand returns theResponseup through the ancestornextfunction (#14118)[UNSTABLE] When middleware is enabled, make the
contextparameter read-only (viaReadonly<unstable_RouterContextProvider>) so that TypeScript will not allow you to write arbitrary fields to it in loaders, actions, or middleware. (#14097)[UNSTABLE] Rename and alter the signature/functionality of the
unstable_respondAPI instaticHandler.query/staticHandler.queryRoute(#14103)unstable_generateMiddlewareResponsefor clarityunstable_respondand handing you the result, we now pass aquery/queryRoutefunction as a parameter and you execute the loaders/actions inside your callback, giving you full access to pre-processing and error handlingqueryversion of the API now has a signature of(query: (r: Request) => Promise<StaticHandlerContext | Response>) => Promise<Response>queryRouteversion of the API now has a signature of(queryRoute: (r: Request) => Promise<Response>) => Promise<Response>queryand direct error handling of errors thrown from querystaticHandlerunstable_respondAPI[UNSTABLE] Convert internal middleware implementations to use the new
unstable_generateMiddlewareResponseAPI (#14103)[UNSTABLE] Change
getLoadContextsignature (type GetLoadContextFunction) whenfuture.unstable_middlewareis enabled so that it returns anunstable_RouterContextProviderinstance instead of aMapused to contruct the instance internally (#14097)type unstable_InitialContextexportgetLoadContextfunction[UNSTABLE] Run client middleware on client navigations even if no loaders exist (#14106)
[UNSTABLE] Change the
unstable_getContextsignature onRouterProvider/HydratedRouter/unstable_RSCHydratedRouterso that it returns anunstable_RouterContextProviderinstance instead of aMapused to contruct the instance internally (#14097)unstable_getContextprop[UNSTABLE] proxy server action side-effect redirects from actions for document and callServer requests (#14131)
[UNSTABLE] Fix RSC Data Mode issue where routes that return
falsefromshouldRevalidatewould be replaced by an<Outlet />(#14071)v7.7.1Compare Source
Patch Changes
shouldRevalidatereturned false (#14026)Matched leaf route at location "/..." does not have an element or Componentwarnings when error boundaries are rendered. (#14021)v7.7.0Compare Source
Minor Changes
Add unstable RSC support (#13700)
For more information, see the RSC documentation.
Patch Changes
Handle
InvalidCharacterErrorwhen validating cookie signature (#13847)Pass a copy of
searchParamsto thesetSearchParamscallback function to avoid muations of the internalsearchParamsinstance. This was an issue when navigations were blocked because the internal instance be out of sync withuseLocation().search. (#12784)Support invalid
Dateinturbo-streamv2 fork (#13684)In Framework Mode, clear critical CSS in development after initial render (#13872)
Strip search parameters from
patchRoutesOnNavigationpathparam for fetcher calls (#13911)Skip scroll restoration on useRevalidator() calls because they're not new locations (#13671)
Support unencoded UTF-8 routes in prerender config with
ssrset tofalse(#13699)Do not throw if the url hash is not a valid URI component (#13247)
Fix a regression in
createRoutesStubintroduced with the middleware feature. (#13946)As part of that work we altered the signature to align with the new middleware APIs without making it backwards compatible with the prior
AppLoadContextAPI. This permittedcreateRoutesStubto work if you were opting into middleware and the updatedcontexttypings, but brokecreateRoutesStubfor users not yet opting into middleware.We've reverted this change and re-implemented it in such a way that both sets of users can leverage it.
createRoutesStubwith the updated API.Remove
Content-Lengthheader from Single Fetch responses (#13902)v7.6.3Compare Source
Patch Changes
Do not serialize types for
useRouteLoaderData<typeof clientLoader>(#13752)For types to distinguish a
clientLoaderfrom aserverLoader, you MUST annotateclientLoaderargs:v7.6.2Compare Source
Patch Changes
with-propschunk in Framework Mode by moving route module component prop logic from the Vite plugin toreact-router(#13650)headers()function processing for use with RSC (#13639)v7.6.1Compare Source
Patch Changes
Update
Route.MetaArgsto reflect thatdatacan be potentiallyundefined(#13563)This is primarily for cases where a route
loaderthrew an error to it's ownErrorBoundary. but it also arises in the case of a 404 which renders the rootErrorBoundary/metabut the root loader did not run because not routes matched.Partially revert optimization added in
7.1.4to reduce calls tomatchRoutesbecause it surfaced other issues (#13562)Fix typegen when same route is used at multiple paths (#13574)
For example,
routes/route.tsxis used at 4 different paths here:Previously, typegen would arbitrarily pick one of these paths to be the "winner" and generate types for the route module based on that path.
Now, typegen creates unions as necessary for alternate paths for the same route file.
Better types for
params(#13543)For example:
Previously,
paramsfor theroutes/layout.tsxroute were calculated as{ p: string, l: string }.This incorrectly ignores params that could come from child routes.
If visiting
/parent/1/layout/2/child1/3/4, the actual params passed toroutes/layout.tsxwill have a type of{ p: string, l: string, c1a: string, c1b: string }.Now,
paramsare aware of child routes and autocompletion will include child params as optionals:You can also narrow the types for
paramsas it is implemented as a normalized union of params for each page that includesroutes/layout.tsx:UNSTABLE: renamed internal
react-router/route-moduleexport toreact-router/internalUNSTABLE: removed
Infoexport from generated+types/*filesAvoid initial fetcher execution 404 error when Lazy Route Discovery is interrupted by a navigation (#13564)
href replaces splats
*(#13593)v7.6.0Compare Source
Minor Changes
Added a new
react-router.config.tsrouteDiscoveryoption to configure Lazy Route Discovery behavior. (#13451)/__manifestpath:routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" }routeDiscovery: { mode: "lazy", manifestPath: "/custom-manifest" }routeDiscovery: { mode: "initial" }Add support for route component props in
createRoutesStub. This allows you to unit test your route components using the props instead of the hooks: (#13528)Patch Changes
Fix
react-routermodule augmentation forNodeNext(#13498)Don't bundle
react-routerinreact-router/domCJS export (#13497)Fix bug where a submitting
fetcherwould get stuck in aloadingstate if a revalidatingloaderredirected (#12873)Fix hydration error if a server
loaderreturnedundefined(#13496)Fix initial load 404 scenarios in data mode (#13500)
Stabilize
useRevalidator'srevalidatefunction (#13542)Preserve status code if a
clientActionthrows adata()result in framework mode (#13522)Be defensive against leading double slashes in paths to avoid
Invalid URLerrors from the URL constructor (#13510)new URL("//", window.location.origin)Remove
Navigatordeclaration fornavigator.connection.saveDatato avoid messing with any other types beyondsaveDatain userland (#13512)Fix
handleErrorparamsvalues on.datarequests for routes with a dynamic param as the last URL segment (#13481)Don't trigger an
ErrorBoundaryUI before the reload when we detect a manifest verison mismatch in Lazy Route Discovery (#13480)Inline
turbo-stream@2.4.1dependency and fix decoding ordering of Map/Set instances (#13518)Only render dev warnings in DEV mode (#13461)
UNSTABLE: Fix a few bugs with error bubbling in middleware use-cases (#13538)
Short circuit post-processing on aborted
dataStrategyrequests (#13521)Cannot read properties of undefined (reading 'result')v7.5.3Compare Source
Patch Changes
loaderDatabeing cleared at the handlingErrorBoundaryroute (#13476)clientLoader.hydrateinitial load executions (#13477)v7.5.2Compare Source
Patch Changes
Update Single Fetch to also handle the 204 redirects used in
?_datarequests in Remix v2 (#13364).datarequests from outside the scope of React Router (i.e., anexpress/honomiddleware)Adjust approach for Prerendering/SPA Mode via headers (#13453)
v7.5.1Compare Source
Patch Changes
Fix single fetch bug where no revalidation request would be made when navigating upwards to a reused parent route (#13253)
When using the object-based
route.lazyAPI, theHydrateFallbackandhydrateFallbackElementproperties are now skipped when lazy loading routes after hydration. (#13376)If you move the code for these properties into a separate file, you can use this optimization to avoid downloading unused hydration code. For example:
Properly revalidate prerendered paths when param values change (#13380)
UNSTABLE: Add a new
unstable_runClientMiddlewareargument todataStrategyto enable middleware execution in customdataStrategyimplementations (#13395)UNSTABLE: Add better error messaging when
getLoadContextis not updated to return aMap" (#13242)Do not automatically add
nulltostaticHandler.query()context.loaderDataif routes do not have loaders (#13223)undefinedfrom loaders, our prior check ofloaderData[routeId] !== undefinedwas no longer sufficient and was changed to arouteId in loaderDatacheck - thesenullvalues can cause issues for this new checkcreateStaticHandler()/<StaticRouterProvider>, and usingcontext.loaderDatato control<RouterProvider>hydration behavior on the clientFix prerendering when a loader returns a redirect (#13365)
UNSTABLE: Update context type for
LoaderFunctionArgs/ActionFunctionArgswhen middleware is enabled (#13381)Add support for the new
unstable_shouldCallHandler/unstable_shouldRevalidateArgsAPIs indataStrategy(#13253)v7.5.0Compare Source
Minor Changes
Add granular object-based API for
route.lazyto support lazy loading of individual route properties, for example: (#13294)Breaking change for
route.unstable_lazyMiddlewareconsumersThe
route.unstable_lazyMiddlewareproperty is no longer supported. If you want to lazily load middleware, you must use the new object-basedroute.lazyAPI withroute.lazy.unstable_middleware, for example:Patch Changes
unstable_subResourceIntegrityfuture flag that enables generation of an importmap with integrity for the scripts that will be loaded by the browser. (#13163)v7.4.1Compare Source
Patch Changes
Fix types on
unstable_MiddlewareFunctionto avoid type errors when a middleware doesn't return a value (#13311)Dedupe calls to
route.lazyfunctions (#13260)Add support for
route.unstable_lazyMiddlewarefunction to allow lazy loading of middleware logic. (#13210)Breaking change for
unstable_middlewareconsumersThe
route.unstable_middlewareproperty is no longer supported in the return value fromroute.lazy. If you want to lazily load middleware, you must useroute.unstable_lazyMiddleware.v7.4.0Compare Source
Patch Changes
shouldRevalidatebehavior forclientLoader-only routes inssr:trueapps (#13221)RequestHandlerloadContextparameter type when middleware is enabled (#13204)Route.unstable_MiddlewareFunctionto have a return value ofResponse | undefinedinstead ofResponse | voidbecaue you should not return anything if you aren't returning theResponse(#13199)next()and are no longer leaking theMiddlewareErrorimplementation detail (#13180)v7.3.0Compare Source
Minor Changes
fetcherKeyas a parameter topatchRoutesOnNavigation(#13061)fetchercalls to undiscovered routes, this mismatch will trigger a document reload of the current pathPatch Changes
Skip resource route flow in dev server in SPA mode (#13113)
Support middleware on routes (unstable) (#12941)
Middleware is implemented behind a
future.unstable_middlewareflag. To enable, you must enable the flag and the types in yourreact-router-config.tsfile:clientMiddlewarethat we will be addressing this before a stable release.contextparameter passed to yourloader/actionfunctions - see below for more information.Once enabled, routes can define an array of middleware functions that will run sequentially before route handlers run. These functions accept the same parameters as
loader/actionplus an additionalnextparameter to run the remaining data pipeline. This allows middlewares to perform logic before and after handlers execute.Here's a simple example of a client-side logging middleware that can be placed on the root route:
Note that in the above example, the
next/middlewarefunctions don't return anything. This is by design as on the client there is no "response" to send over the network like there would be for middlewares running on the server. The data is all handled behind the scenes by the statefulrouter.For a server-side middleware, the
nextfunction will return the HTTPResponsethat React Router will be sending across the wire, thus giving you a chance to make changes as needed. You may throw a new response to short circuit and respond immediately, or you may return a new or altered response to override the default returned bynext().You can throw a
redirectfrom a middleware to short circuit any remaining processing:Note that in cases like this where you don't need to do any post-processing you don't need to call the
nextfunction or return aResponse.Here's another example of using a server middleware to detect 404s and check the CMS for a redirect:
contextparameterWhen middleware is enabled, your application will use a different type of
contextparameter in your loaders and actions to provide better type safety. Instead ofAppLoadContext,contextwill now be an instance ofContextProviderthat you can use with type-safe contexts (similar toReact.createContext):If you are using a custom server with a
getLoadContextfunction, the return value for initial context values passed from the server adapter layer is no longer an object and should now return anunstable_InitialContext(Map<RouterContext, unknown>):Fix types for loaderData and actionData that contained
Records (#13139)UNSTABLE(BREAKING):
unstable_SerializesToadded a way to register custom serialization types in Single Fetch for other library and framework authors like Apollo.It was implemented with branded type whose branded property that was made optional so that casting arbitrary values was easy:
However, this broke type inference in
loaderDataandactionDatafor anyRecordtypes as those would now (incorrectly) matchunstable_SerializesTo.This affected all users, not just those that depended on
unstable_SerializesTo.To fix this, the branded property of
unstable_SerializesTois marked as required instead of optional.For library and framework authors using
unstable_SerializesTo, you may need to addas unknowncasts before casting tounstable_SerializesTo.Fix single fetch
_root.datarequests when abasenameis used (#12898)Add
contextsupport to client side data routers (unstable) (#12941)Your application
loaderandactionfunctions on the client will now receive acontextparameter. This is an instance ofunstable_RouterContextProviderthat you use with type-safe contexts (similar toReact.createContext) and is most useful with the correspondingmiddleware/clientMiddlewareAPI's:Similar to server-side requests, a fresh
contextwill be created per navigation (orfetchercall). If you have initial data you'd like to populate in the context for every request, you can provide anunstable_getContextfunction at the root of your app:createBrowserRouter(routes, { unstable_getContext })<HydratedRouter unstable_getContext>This function should return an value of type
unstable_InitialContextwhich is aMap<unstable_RouterContext, unknown>of context's and initial values:v7.2.0Compare Source
Minor Changes
New type-safe
hrefutility that guarantees links point to actual paths in your app (#13012)Patch Changes
Fix typegen for repeated params (#13012)
In React Router, path parameters are keyed by their name.
So for a path pattern like
/a/:id/b/:id?/c/:id, the last:idwill set the value foridinuseParamsand theparamsprop.For example,
/a/1/b/2/c/3will result in the value{ id: 3 }at runtime.Previously, generated types for params incorrectly modeled repeated params with an array.
So
/a/1/b/2/c/3generated a type like{ id: [1,2,3] }.To be consistent with runtime behavior, the generated types now correctly model the "last one wins" semantics of path parameters.
So
/a/1/b/2/c/3now generates a type like{ id: 3 }.Don't apply Single Fetch revalidation de-optimization when in SPA mode since there is no server HTTP request (#12948)
Properly handle revalidations to across a prerender/SPA boundary (#13021)
.datarequests if the path wasn't pre-rendered because the request will 404loaderdata inssr:falsemode is static because it's generated at build timeclientLoaderto do anything dynamicloaderand not aclientLoader, we disable revalidation by default because there is no new data to retrieveConfiguration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about these updates again.
This PR was generated by Mend Renovate. View the repository job log.