-
-
Notifications
You must be signed in to change notification settings - Fork 274
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
feat(nextjs-mf): add support for Next.js App Router #2002
feat(nextjs-mf): add support for Next.js App Router #2002
Conversation
99b2cff
to
fd98cb2
Compare
@@ -151,7 +151,10 @@ class FederationRuntimePlugin { | |||
// TODO: maybe set this variable as constant is better https://github.com/webpack/webpack/blob/main/lib/config/defaults.js#L176 | |||
entryItem.import = ['./src']; | |||
} | |||
if (!entryItem.import.includes(entryFilePath)) { |
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.
We should not modify /enhanced in order to fix next.js
If you need to do this, we should add a hook or some option that we can pass down from next.js instead.
/enhanced needs to remain as pure as it can and not patch framework specific issues but rather bugs in webpack etc (like single runtime chunk) X
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.
Yes, maybe we can add "exclude" option to allow users control whether add our federation runtime entry file.
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 @ahabhgk How about adding exclude
options to allow users control whether add our federation runtime entry file in rspack/webpack ?
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.
yeah im good with that
packages/nextjs-mf/README.md
Outdated
filename: '', | ||
remotes: {}, | ||
exposes: {}, | ||
shared: ['next/navigation'], // This is important! |
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.
Add this to internal.ts instead, where Next.js retrieves its default shares. Users do not need to add extra shared module to make it work
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.
The reason I decided to use this was to ensure that defaultShared
is not pased in app router. That creates issues with react-dom and react runtime.
It might be a better idea to add a new flag enableAppRouter
in federation config - what do you think?
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.
Okay got another idea - I'll try to figure out whether the project uses app router and do this implicitly.
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.
What happens when if both pages and app router are used?
Will it break?
If so we can enable "appRouterOnly" mode so its either one or the other
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.
Nope, it works with both app and pages router.. I have a change, will push the commit shortly.
Only thing left right now is to figure out a way to run this without modifying @module-federation/enhanced
fd98cb2
to
2939201
Compare
9d0271a
to
3e3af3a
Compare
Okay, take a look at this branch. #2017 Might give you some ideas, but its still broken in the client, server works tho. |
hello all, any chance this gets merged soon? I'm getting error with |
Hey all, I'm getting error "Uncaught TypeError: Cannot read properties of null (reading 'useContext')" while using useRouter() in the remote application. Does anyone have any clue how might this be resolved? |
Hello everyone, sorry to bother again, will app router get supported any time soon? I'm using it with current page router but I want to integrate it with another nextjs that uses app router |
Hi guys, is there any progress? Thanks in advance! |
any news? and please add a example for next 14 (app router) |
No progress, i wouldnt expect it to be resolved anytime soon. |
@ScriptedAlchemy So, is the current statement to not use next14 with nextjs-mf? is it only for App router? Can you please confirm and provide the suggested solution? |
@Jony-Y |
V14 doesn't work if I use any react client features ( like useState ) in remote component even in page router. I haven't tried with clean projects though. |
You can't have any app router at all. No folder called app. Whole thing must be only pages router. App router will most likely never be supported. |
Could you say, is this a statement that there will never be micro frontends in app router? |
That would be a presumptive statement, I am sure vercel/nextjs would want to support micro-frontend architecture in some form, but based on experience they will likely provide their own solution at some point and push to make it a standard. |
There will never be module federation with app router, not my ecosystem - not for next.js Vercel will make proprietary system for app router most likely. |
There is an application and it's using the app router and pages structure (95%), I want to use mf in that project but "App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this" error accrued. How can I fix that. Should I need to copy app folder codes to pages structure ? or there is a work around? @ScriptedAlchemy |
@ScriptedAlchemy , what exactly is the issue? Is this because they switched to SWC? They are pushing the app router very hard and probably will deprecate the page router sooner or later |
you can try to use Multizone, other than that i think that we are cooked :/ |
Description
This PR adds support for module federation in Next.js App Router. To use this simply pass
next/navigation
as a shared dependency.Related Issue
Types of changes
Checklist