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

Support optimizing ssr environment dependencies #13007

Merged
merged 8 commits into from
Feb 17, 2025

Conversation

jamesopstad
Copy link
Contributor

This adds support for optimizing dependencies in server environments by setting optimizeDeps.entries and optimizeDeps.include if the environment has optimizeDeps.noDiscovery set to false. Server environments default to noDiscovery: true so this will only affect environments that opt in. This is a requirement of the Cloudflare Vite plugin, which relies on dependency pre-bundling. As the scanner does not include virtual modules, the entries are required for discovery.

Copy link

changeset-bot bot commented Feb 12, 2025

🦋 Changeset detected

Latest commit: df22b53

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

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Feb 12, 2025

Hi @jamesopstad,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected].

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Feb 12, 2025

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@@ -1166,6 +1169,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {

viteChildCompiler = await vite.createServer({
...viteUserConfig,
cacheDir: "node_modules/.vite-child-compiler",
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 is to ensure that the child compiler cannot overwrite the default cache directory.

Comment on lines 1200 to 1218
{
name: "react-router:override-optimize-deps",
config(userConfig) {
if (
ctx.reactRouterConfig.future.unstable_viteEnvironmentApi &&
userConfig.environments
) {
for (const environmentName of Object.keys(
userConfig.environments
)) {
userConfig.environments[environmentName].optimizeDeps = {
noDiscovery: true,
};
}
} else {
userConfig.optimizeDeps = { noDiscovery: 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.

This plugin prevents unnecessary dependency optimization in the child compiler.

@markdalgleish markdalgleish changed the title Add support for optimizing server dependencies Support optimizing ssr environment dependencies Feb 17, 2025
Copy link
Member

@markdalgleish markdalgleish left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@markdalgleish markdalgleish merged commit f28c1d1 into remix-run:dev Feb 17, 2025
8 checks passed
Copy link
Contributor

🤖 Hello there,

We just published version 7.2.0-pre.5 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!

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