Skip to content

Only import the root route when SSRing SPA mode's index.html #13023

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

Merged
merged 5 commits into from
Feb 20, 2025

Conversation

jenseng
Copy link
Contributor

@jenseng jenseng commented Feb 13, 2025

Since we only SSR the root route in SPA mode, we don't need to import any other routes in the server bundle; the bundle is solely used to generate the index.html file, and is subsequently discarded.

This should speed up SPA mode builds and make them less error prone; often times apps use libraries that are not SSR-capable (e.g. referencing window in the module scope). By excluding all other routes (and their deps), we make the index.html render more likely to be successful and less likely to require a bunch of shenanigans in vite.config.js.

cc @brophdawg11

Closes #12360

Copy link

changeset-bot bot commented Feb 13, 2025

🦋 Changeset detected

Latest commit: 7ee78cc

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

This PR includes changesets to release 11 packages
Name Type
@react-router/dev Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch
react-router Patch
react-router-dom Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve 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

@jenseng jenseng force-pushed the improve-spa-prerendering branch from 488431a to 22c4a99 Compare February 14, 2025 15:40
@jenseng
Copy link
Contributor Author

jenseng commented Feb 14, 2025

Node 22 tests are failing, though that appears unrelated? Seems to fail the same occasionally elsewhere (e.g. this run from a push to main)

working on the latest run 🤷 🚀

@jenseng jenseng force-pushed the improve-spa-prerendering branch from 22c4a99 to cb3cfec Compare February 18, 2025 20:49
@brophdawg11
Copy link
Contributor

This looks awesome! I made a few minor updates but otherwise this is looking good. Do you mind rebasing onto dev since I don't think I can force push onto your fork

@brophdawg11 brophdawg11 self-assigned this Feb 19, 2025
jenseng and others added 4 commits February 19, 2025 14:50
Since we only actually render the top-level index route in SPA mode, we
don't need to import any other routes in the server bundle; the bundle is
solely used to generate the index.html file, and is subsequently discarded.

This should speed up SPA mode builds and make them less error prone; often
times apps use libraries that are not SSR-capable (e.g. referencing window
in the module scope). By excluding all other routes (and their deps), we
make the index.html render more likely to be successful and less likely to
require a bunch of externals/shimming shenanigans in vite.config.js.
@jenseng jenseng force-pushed the improve-spa-prerendering branch from 263497a to 9ce8c08 Compare February 19, 2025 21:56
@jenseng jenseng changed the base branch from main to dev February 19, 2025 21:56
@jenseng jenseng changed the title Only import the top-level index route when SSRing SPA mode's index.html Only import the root route when SSRing SPA mode's index.html Feb 19, 2025
@jenseng
Copy link
Contributor Author

jenseng commented Feb 19, 2025

This looks awesome! I made a few minor updates but otherwise this is looking good. Do you mind rebasing onto dev since I don't think I can force push onto your fork

Done! Let me know if anything else needs changing

@jenseng jenseng force-pushed the improve-spa-prerendering branch from 9ce8c08 to 7ee78cc Compare February 19, 2025 22:00
@brophdawg11 brophdawg11 merged commit b33bc9c into remix-run:dev Feb 20, 2025
8 checks passed
wilcoxmd added a commit to wilcoxmd/react-router that referenced this pull request Mar 5, 2025
…d-route-typegen

* upstream/dev: (65 commits)
  Generate types for `virtual:react-router/server-build` (remix-run#13152)
  Add support for client context and middleware (unstable) (remix-run#12941)
  Add playground for `vite-plugin-cloudflare` (remix-run#13151)
  do not typegen params for layout routes with a corresponding index (remix-run#13131) (remix-run#13140)
  Fix types for `loaderData` and `actionData` that contain `Record`s (remix-run#13139)
  chore: format
  chore(dev): remove unused dependencies (remix-run#13134)
  Remove unused Vite file system watcher (remix-run#13133)
  Remove stale changesets cherry-picked into release-next for 7.2.0
  Fix custom SSR build input with `serverBundles` (remix-run#13107)
  Skip resource route flow in dev mode when SPA  mode is enabled (remix-run#13113)
  chore: format
  Add integration test for `vite-plugin-cloudflare` (remix-run#13099)
  Fix custom client `build.rollupOptions.output.entryFileNames` (remix-run#13098)
  Detect lazy route discovery manifest version mismatches and trigger reloads (remix-run#13061)
  Fix critical CSS with custom `Vite.DevEnvironment` (remix-run#13066)
  Fix usage of `prerender` option with `serverBundles` (remix-run#13082)
  Fix support for custom `build.assetsDir` (remix-run#13077)
  Add changeset for remix-run#13064
  Only import the root route when SSRing SPA mode's index.html (remix-run#13023)
  ...
Copy link
Contributor

github-actions bot commented Mar 6, 2025

🤖 Hello there,

We just published version 7.3.0-pre.1 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

github-actions bot commented Mar 6, 2025

🤖 Hello there,

We just published version 7.3.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

1 similar comment
Copy link
Contributor

github-actions bot commented Mar 6, 2025

🤖 Hello there,

We just published version 7.3.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

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