Skip to content
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

Merged
merged 11 commits into from
Jan 11, 2023

Conversation

jacob-ebey
Copy link
Member

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Dec 20, 2022

🦋 Changeset detected

Latest commit: f77b4f4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@remix-run/router Minor
react-router Patch
react-router-dom Patch
react-router-dom-v5-compat Patch
react-router-native Patch

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

jacob-ebey and others added 2 commits December 19, 2022 19:33
- add settledKey to DeferredData subscription callback
Comment on lines +2296 to +2303
let error = getInternalRouterError(400, { type: "defer-action" });
if (isRouteRequest) {
throw error;
}
result = {
type: ResultType.error,
error,
};
Copy link
Contributor

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>
Copy link
Contributor

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

Comment on lines 2980 to 2993
} 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);
}
}
Copy link
Contributor

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[] = [];
Copy link
Contributor

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]);

@brophdawg11 brophdawg11 changed the title initial attempt at exposing required data to ssr implementations defer - initial attempt at exposing required data to ssr implementations Dec 21, 2022
Comment on lines +2467 to +2470
activeDeferreds:
activeDeferreds.size > 0
? Object.fromEntries(activeDeferreds.entries())
: null,
Copy link
Contributor

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?

@brophdawg11 brophdawg11 marked this pull request as ready for review January 11, 2023 16:59
@jacob-ebey jacob-ebey merged commit ce2bb3f into dev Jan 11, 2023
@jacob-ebey jacob-ebey deleted the defer-static-handler branch January 11, 2023 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants