-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
defer - initial attempt at exposing required data to ssr implementations #9760
Conversation
🦋 Changeset detectedLatest commit: f77b4f4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 |
- add settledKey to DeferredData subscription callback
let error = getInternalRouterError(400, { type: "defer-action" }); | ||
if (isRouteRequest) { | ||
throw error; | ||
} | ||
result = { | ||
type: ResultType.error, | ||
error, | ||
}; |
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.
Converted this to our ErrorResponse
approach
@@ -2922,7 +2930,7 @@ function processRouteLoaderData( | |||
matchesToLoad: AgnosticDataRouteMatch[], | |||
results: DataResult[], | |||
pendingError: RouteData | undefined, | |||
activeDeferreds?: Map<string, DeferredData> | |||
activeDeferreds: Map<string, DeferredData> |
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 can be required now since we use it in SSR
packages/router/router.ts
Outdated
} else if (isDeferredResult(result)) { | ||
activeDeferreds && activeDeferreds.set(id, result.deferredData); | ||
loaderData[id] = result.deferredData.data; | ||
let init = result.deferredData.responseInit; | ||
if (init) { | ||
// Error status codes always override success status codes, but if all | ||
// loaders are successful we take the deepest status code. | ||
if (init.status != null && init.status !== 200 && !foundError) { | ||
statusCode = init.status; | ||
} | ||
if (init.headers) { | ||
loaderHeaders[id] = new Headers(init.headers); | ||
} | ||
} |
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.
I aligned the SuccessResult
/DeferredResult
apis here for statusCode
and headers
data: Record<string, unknown>; | ||
statusCode: number; | ||
headers: Headers; | ||
deferredKeys: string[] = []; |
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.
Could this be deduced via:
Object.entries(deferredData.data)
.filter(e => 'then' in e[1] && typeof e[1].then === 'function')
.map(e => e[0]);
fix: allow unsubscribe from DeferredData
activeDeferreds: | ||
activeDeferreds.size > 0 | ||
? Object.fromEntries(activeDeferreds.entries()) | ||
: null, |
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.
Do we need to convert this to an object? Or could it remain a Map
since it's never intended to be serialized?
No description provided.