-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Support for client side context #12515
base: dev
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 2a92d5e The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
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 |
@@ -85,6 +85,7 @@ export type { | |||
AwaitProps, | |||
IndexRouteProps, | |||
LayoutRouteProps, | |||
MemoryRouterOpts, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Export this and DOMRouterOpts
so they get picked up by typedoc
@@ -130,23 +131,62 @@ export function mapRouteProperties(route: RouteObject) { | |||
return updates; | |||
} | |||
|
|||
export interface MemoryRouterOpts { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted to an interface so it gets it's own docs page and to align with DOMRouterOpts
/** | ||
* Router context singleton that will be passed to loader/action functions. | ||
*/ | ||
context?: DefaultRouterContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only new API:
let router = createMemoryRouter(routes, {
context: { user: getUser() }
});
@@ -49,10 +45,6 @@ interface StubNonIndexRouteObject | |||
|
|||
type StubRouteObject = StubIndexRouteObject | StubNonIndexRouteObject; | |||
|
|||
interface AppLoadContext { | |||
[key: string]: unknown; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer need this duped with the repo merge and we can import the actual one
@@ -153,21 +145,15 @@ function processRoutes( | |||
); | |||
} | |||
|
|||
// Patch in the Remix context to loaders/actions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed 🫡
{ request }: LoaderFunctionArgs, | ||
singleFetch?: unknown | ||
) => | ||
dataRoute.loader = (_: LoaderFunctionArgs, singleFetch?: unknown) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request was unused here
@@ -812,6 +814,7 @@ export function createRouter(init: RouterInit): Router { | |||
); | |||
let inFlightDataRoutes: AgnosticDataRouteObject[] | undefined; | |||
let basename = init.basename || "/"; | |||
let routerContext = typeof init.context !== "undefined" ? init.context : {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default context to {}
just like in Remix/SSR
@@ -3676,7 +3679,7 @@ export function createStaticHandler( | |||
? actionMatch | |||
: findNearestBoundary(matches, actionMatch.route.id); | |||
|
|||
let context = await loadRouteData( | |||
let handlerContext = await loadRouteData( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename for clarity:
handlerContext
-> aStaticHandlerContext
returned fromstaticHandler.query()
requestContext
-> TheAppLoadContext
used passed tostaticHandler.query
by Remix SSR todayrouterContext
-> This newDefaultRouterContext
used for SPAs since it's not tired to a request like the SSR use case
In shared code, requestContext
becomes routerContext
@@ -118,19 +125,19 @@ export type Submission = | |||
interface DataFunctionArgs<Context> { | |||
request: Request; | |||
params: Params; | |||
context?: Context; | |||
context: Context; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer optional - still maintains a default type of any
though
request, | ||
matchesToLoad, | ||
matches, | ||
fetcherKey, | ||
manifest, | ||
mapRouteProperties | ||
mapRouteProperties, | ||
routerContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the core functional addition - the shared dataStrategy
stuff already supports context
for SSR, we just didn't used to pass anything for client side usages - now we do
@@ -2722,13 +2725,13 @@ export function createRouter(init: RouterInit): Router { | |||
results = await callDataStrategyImpl( | |||
dataStrategyImpl, | |||
type, | |||
state, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This param was unused
request: Request, | ||
matchesToLoad: AgnosticDataRouteMatch[], | ||
matches: AgnosticDataRouteMatch[], | ||
fetcherKey: string | null, | ||
manifest: RouteManifest, | ||
mapRouteProperties: MapRoutePropertiesFunction, | ||
requestContext?: unknown | ||
routerContext: unknown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer optional since it's used in both SSR and SPA use cases
No description provided.