fix(nextjs-mf): use matchRemoteWithNameAndExpose for beforeRequest cache-busting#4661
Conversation
|
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b750f7347
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
8b750f7 to
7bbcb0b
Compare
|
can you help add related test cases? |
7bbcb0b to
eca846a
Compare
|
@2heal1
Also added |
…okup
Replace the broken id.split('/').shift() approach in the beforeRequest
hook with the canonical matchRemoteWithNameAndExpose from runtime-core.
The split approach has two bugs:
1. args.id uses the remote's alias, but the lookup only checks
remote.name — when alias differs from name, cache-busting is skipped.
2. For scoped identifiers like @scope/remote/widget, split('/').shift()
yields @scope, never matching the full alias @scope/remote.
matchRemoteWithNameAndExpose uses startsWith + boundary checking to
correctly handle scoped names, scoped aliases, and all edge cases — and
is already the standard approach used elsewhere in the runtime (e.g.
getRemoteModuleAndOptions).
Fixes module-federation#4659
eca846a to
4d158f1
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d158f1400
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Summary
The
beforeRequesthook innext-internal-pluginappends a cache-busting?t=parameter to remote entry URLs. However, it usesid.split('/').shift()to extract the remote name, which has two bugs:Alias mismatch:
args.iduses the remote's alias, but the lookup only checksremote.name. When alias differs from name,find()returnsundefinedand cache-busting is silently skipped.Scoped name/alias breakage: For scoped identifiers like
@scope/remote/widget,split('/').shift()yields@scope— not@scope/remote. This means any remote with a scoped name or alias never gets cache-busted.This causes stale
mf-manifest.jsonto be served from browser/CDN cache after deployments for affected remotes.Change
Replace the broken
split('/').shift()+find()approach with the canonicalmatchRemoteWithNameAndExposefrom@module-federation/runtime-core. This function usesstartsWith+ boundary checking to correctly handle scoped names, scoped aliases, and all edge cases — and is already the standard approach used elsewhere in the runtime (e.g.getRemoteModuleAndOptions).Also adds
@module-federation/runtime-coreas a direct dependency innextjs-mf/package.json(already a transitive dep via@module-federation/runtime).Tests
8 test cases for the
beforeRequesthook:app1)app1/button)my-alias/button→ namemy-remote-provider)@scope/my-remote/widget)@federation/app1/button)?t=already presentReproduction
loadRemote('@scope/my-remote/some-module')mf-manifest.jsonrequest has no?t=parameter?t=is correctly appendedFixes #4659