-
-
Notifications
You must be signed in to change notification settings - Fork 310
fix(node): Improve chunk flushing #1985
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
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d75dfde
fix(node): improve public path calculation
ScriptedAlchemy 4e1d84c
fix(node): refactor public path runtime module
ScriptedAlchemy 20e1426
fix(node): refactor public path runtime module
ScriptedAlchemy d416104
chore: disable checkout e2e test
ScriptedAlchemy 3c8a9da
chore: fix types
ScriptedAlchemy a520756
feat(runtime): onload hook allows custom factory
ScriptedAlchemy 1e2bbda
fix(node): improve chunk flush
ScriptedAlchemy 0502a07
fix(node): improve chunk flush
ScriptedAlchemy eff2df6
fix(node): improve chunk flush
ScriptedAlchemy 9b390a3
chore: clear all federation instances
2heal1 047acc3
fix(nextjs-mf): hot reloading
ScriptedAlchemy 357b01d
fix(nextjs-mf): hot reloading
ScriptedAlchemy 0e8f53e
fix(nextjs-mf): hot reloading
ScriptedAlchemy d5a7b20
fix(nextjs-mf): hot reloading
ScriptedAlchemy 46d7f77
fix(nextjs-mf): resolve to esm runtime
ScriptedAlchemy 022ca1f
Merge branch 'main' into feat/chunk-lush
ScriptedAlchemy 4c04cb5
chore: remove useless packages from next apps
ScriptedAlchemy 653501d
Merge branch 'main' into feat/chunk-lush
ScriptedAlchemy d279575
chore: lock file
ScriptedAlchemy e49e786
Merge branch 'main' into feat/chunk-lush
ScriptedAlchemy e1baee1
Merge branch 'main' into feat/chunk-lush
ScriptedAlchemy 22b953f
Merge remote-tracking branch 'origin/feat/chunk-lush' into feat/chunk…
ScriptedAlchemy fb23466
chore: update next build commands in ci
ScriptedAlchemy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@module-federation/nextjs-mf': patch | ||
'@module-federation/node': patch | ||
--- | ||
|
||
Rewrite chunk flushing and hot reloading to use federation runtime apis |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ declare global { | |
}; | ||
} | ||
} | ||
var usedChunks: Set<string>; | ||
|
||
var __FEDERATION__: { | ||
__INSTANCES__: Array<{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you found out why this is required? We have the same - I started going deep, trying to track it down but with this workaround staring me in the face, I couldn't throw too many hours at it for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
becuae next is already running, so if you clear require cache mid way though, its router is destroyed.
require cache clear really needs to happen before next entry points are required.
When it comes to federation, next.js is about the worst you money can buy.
Maybe when we introduce true HMR i can find a better solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worked aorund this in the past by using a proxy on get initial props and spawn a child worker to run the render and then just return the req/res via the worker and not the host.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, I had been exploring how I could do something like that, but inside the next.js app. Doing it outside is a rather interesting idea indeed! We haven't needed to run a custom next.js server yet but for this I think we can get one in place. Thanks I'll give it a try!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are using a custom server, you can easily clear the cache by running the "clear cache" command before it hits the next route handler middleware. You can achieve this by referring to the custom server http example and placing the "require(/next)" in the middleware of HTTP server instead of at the top of the file. By doing this, you can clean and re-require Next.js whenever necessary.
It is entirely doable, but not easy to make it out of the box for users, hence the double redirect hack haha.
If you look in the server dist folder, you can see if Next.js emits some basic HTTP dev server in dev mode. If so, we can patch it via a Webpack plugin by overwriting it or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ScriptedAlchemy, we're not currently and would ideally stay away from a custom server. I had a look at your suggestion. but I don't think you can move the require(next) because it's used to prepare the server and create the route handlers.
We have some unique limitations in what we can do in our project, but I'm sure there is a solution with module federation involved. While I continue my journey into the code and try to find a solution, we've had the ok to book some time to chat with you in more detail. Hopefully, that's ok with you? We'll have a look and stick something in calendly