Skip to content

feat: don't override async bundle paths searchParams in prod#1509

Open
jbroma wants to merge 4 commits intofacebook:mainfrom
callstack:feat/search-params-dev
Open

feat: don't override async bundle paths searchParams in prod#1509
jbroma wants to merge 4 commits intofacebook:mainfrom
callstack:feat/search-params-dev

Conversation

@jbroma
Copy link
Contributor

@jbroma jbroma commented May 27, 2025

Summary

Part of #1480

When implementing Module Federation for Metro, we're reusing existing lazy bundling for production bundles, and we wanted to clean up the bundlePaths for the production bundles by not adding any query params to it. Since the searchParams are entirely based on sourceUrl, we can avoid adding searchParams by having a clean sourceUrl.

This PR does two things:

  • - it makes the override of runModule & modulesOnly params happen only in dev
  • - prevents adding ? to the URL when there are no searchParams

Changelog: [Feature] Prevent adding runModule & modulesOnly search params when processing bundle async paths for production bundles

Test plan

  • - existing tests pass
  • - new test passes

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels May 27, 2025
@vzaidman
Copy link
Contributor

Hey!
When spec mentions overriding params and not setting them?

@jbroma
Copy link
Contributor Author

jbroma commented May 28, 2025

hey @vzaidman 👋, I've taken that from here:

test('async bundle paths override modulesOnly and runModule', () => {

(although that might have been an over-interpretation on my side 😅)

@jbroma
Copy link
Contributor Author

jbroma commented Jun 27, 2025

@vzaidman is there anything we can do about this PR to move forward with it? 🙏

@robhogan
Copy link
Contributor

@jbroma sorry about the delay with this.

Could you remind me - is there a functional difference intended here (eg MF using different defaults, so we want to leave these params implicit), or is this purely tidying up?

@facebook-github-bot
Copy link
Contributor

@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@jbroma
Copy link
Contributor Author

jbroma commented Jun 27, 2025

@jbroma sorry about the delay with this.

Could you remind me - is there a functional difference intended here (eg MF using different defaults, so we want to leave these params implicit), or is this purely tidying up?

No worries, I feel like we got a little bit sidetracked and left those PRs be for the past month or so, so sorry about that too 😅

So this PR is mostly about tidying up the bundle output in production mode. This PR is completely optional for Module Federation but it cleans up the split module IDs by removing the query params from them.

This should not be breaking in any way because if the query params in question are already there they will be replaced just like before - and that seems to be the case, even for nested lazily imported bundles.

@robhogan
Copy link
Contributor

@jbroma I just had a closer look at this and notice the params we set here are the opposite of the defaults:

modulesOnly: getBoolean(query, 'modulesOnly', false),

runModule: getBoolean(query, 'runModule', true),

So these params are overrides to Metro defaults, and they're typically necessary when loading additional module definitions into an existing bundle from the Metro server (you don't need the bundle boilerplate hence modulesOnly: true, and it's up to the caller to evaluate hence runModule: false).

The effect of this PR is that if you don't explicitly specify modulesOnly=false (the default) when loading the entry bundle from Metro, then modulesOnly won't be overridden to true for lazy imports - which potentially breaks lazy bundling from the Metro server.

For your use case, I guess you're loading prebuilt bundles in prod and so the query params are just noise. But I think the more correct approach for that is to manipulate the URL only when loading from the dev server, rather than basing it on whether the particular params are present.

@jbroma
Copy link
Contributor Author

jbroma commented Jul 1, 2025

Ah, that makes sense, haven't thought of that implicit edge case. I'll rework this to a dev-only feature then 👍 Thanks for investigating this deeply 🙏

@jbroma jbroma force-pushed the feat/search-params-dev branch from c7e3853 to c6c1d36 Compare July 1, 2025 15:30
@jbroma jbroma force-pushed the feat/search-params-dev branch from c6c1d36 to 1baf4ef Compare July 1, 2025 15:31
@jbroma jbroma changed the title fix: override only existing searchParams feat: don't override async bundle paths searchParams in prod Jul 1, 2025
@jbroma
Copy link
Contributor Author

jbroma commented Jul 1, 2025

@robhogan I've aligned the PR to prevent overriding async bundle paths in prod only 👍

@facebook-github-bot
Copy link
Contributor

@robhogan has imported this pull request. If you are a Meta employee, you can view this in D77455249.

@jbroma
Copy link
Contributor Author

jbroma commented Jul 29, 2025

hey @robhogan 👋

anything left to do here to move forward with this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants