Skip to content

feat(react-router): don't bundle react-router in react-router/dom export #13497

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 8 commits into from
May 1, 2025

Conversation

brophdawg11
Copy link
Contributor

@brophdawg11 brophdawg11 commented Apr 29, 2025

Closes #12512
Closes #12939

Copy link

changeset-bot bot commented Apr 29, 2025

🦋 Changeset detected

Latest commit: 818f8e0

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 Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/dev Patch
react-router-dom Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router 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

@brophdawg11 brophdawg11 linked an issue Apr 29, 2025 that may be closed by this pull request
@@ -12,6 +12,7 @@ const config = (enableDevWarnings: boolean) =>
{
clean: false,
entry,
external: ["react", "react-dom", "react-router"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only added this for the CJS config because the ESM build wasn't bundling react-router - but this can be added to both configs is that's safer

Copy link
Member

Choose a reason for hiding this comment

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

Even if it's redundant due to the way tsup is treating the ESM build differently to the CJS build, IMO it feels safer and more explicit to define the same externals everywhere.

Also, I think react and react-dom are redundant in this array. I ran the build locally without these and the require("react") and require("react-dom") calls were still there. The tsup docs say that external is for configuring additional externals, not replacing the default: https://tsup.egoist.dev/#excluding-packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh good catch - I noticed they weren't bundled originally but wasn't entirely sure why so included them out of an abundance of caution. Good to know that is expected/documented behavior 👍

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.

Just a minor comment, but this looks good to me.

@@ -166,7 +166,8 @@ test.describe("prefetch", () => {
await page.waitForSelector(
// Look for either Rollup or Rolldown chunks
[
"#nav link[rel='modulepreload'][href^='/assets/chunk-']",
// Rollup bundles RR (and transitively React) into an index chunk
"#nav link[rel='modulepreload'][href^='/assets/index-']",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@markdalgleish Does this feel expected or unexpected to you now that I added the external config to ESM? I'm temped to remove it so we stick with the prior ESM handling...

Copy link
Member

@markdalgleish markdalgleish May 1, 2025

Choose a reason for hiding this comment

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

As in, this change is introducing an additional chunk in the final app build? I wouldn't have guessed this would change. I've we're specifically targeting an issue with CJS build, I'm not against scoping the externals config to that build, so if you roll it back, maybe just add a comment explaining why it's not configured in the ESM build?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know that it's an additional chunk so much as a renamed chunk, but yeah I think I'll roll it back on the ESM build for now to keep the surface area minimal and we can revisit later if need be.

@MichaelDeBoey MichaelDeBoey changed the title Don't bundle react-router in react-router/dom export feat(react-router): don't bundle react-router in react-router/dom export May 1, 2025
@brophdawg11 brophdawg11 marked this pull request as ready for review May 1, 2025 14:25
@brophdawg11 brophdawg11 merged commit eb59d5f into dev May 1, 2025
5 checks passed
@brophdawg11 brophdawg11 deleted the brophdawg11/dom-bundle branch May 1, 2025 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants