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

Fix a few small issues with prerendering in v7 #11833

Merged
merged 13 commits into from
Sep 19, 2024

Conversation

brophdawg11
Copy link
Contributor

@brophdawg11 brophdawg11 commented Jul 23, 2024

Note: Ignore the first 2 commits as they were made in Remix and have since been brought over to dev and upmerged into here (see remix-run/remix#9695 and remix-run/remix#9792)

This PR adds:

  • Prerendering of __manifest to handle lazy route discovery in a prerendered app
  • Proper ErrorResponse 404 bubbling on single fetch .data requests to a non-existent prerendered .data file on the CDN

Copy link

changeset-bot bot commented Jul 23, 2024

⚠️ No Changeset found

Latest commit: 651b5f6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -1836,32 +1836,39 @@ async function handlePrerender(
);
}

async function prerenderData(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was accidentally a locally scoped function inside the parent handlePreRender function. No changes were made - it just moves out to be a module level function

Comment on lines +1839 to +1844
await prerenderManifest(
build,
clientBuildDirectory,
reactRouterConfig,
viteConfig
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With fog of war we now should prerender the __manifest as well. This means that statically prerendered sites will load the full manifest on initial load since there's no way to dynamically fetch based on the query params for only outgoing routes - and the enumerations aren't possible to prerender single-request manifest patches.

The only thing I can think of to enable true "fog of war" with prerendering would be to generate a .manifest file per path (like we do for .data) and then instead of one request to __manifest we'd load one request per outgoing path - but that would be be sub-optimal because pages with many links would end many request in parallel.

I think maybe the way to go is when pre-rendering is enabled - disable the "outgoing links" discovery and just let the first link click load the full __manifest and then all subsequent links clicks would match syncronously.

let mismatchBetweenSsrMatchesAndHydratedMatches =
(initialMatches || []).length !== ssrMatches.length ||
!(initialMatches || []).every((m, i) => ssrMatches[i] === m.route.id);
if (mismatchBetweenSsrMatchesAndHydratedMatches) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detect via matches and not URL to avoid false positives from trailing slashes - more prevalent in a prerendered world

if (url.pathname === "/") {
url.pathname = "_root.data";
} else {
url.pathname = `${url.pathname.replace(/\/$/, "")}.data`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing slashes when generating single fetch data calls

Comment on lines 415 to 417
if (res.status === 404) {
throw new ErrorResponseImpl(404, "Not Found", true);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bubble a proper 404 to our UI if we're in a prerendered app and there is no static file on the server

@brophdawg11 brophdawg11 merged commit 312bddb into dev Sep 19, 2024
8 checks passed
@brophdawg11 brophdawg11 deleted the brophdawg11/prerender-fixes branch September 19, 2024 18:48
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.

1 participant