-
Notifications
You must be signed in to change notification settings - Fork 369
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
Error with unmounted NextRouter
when consuming Nextjs remote application #6498
#6509
Comments
@jianingroja Modern.js 主应用 需要更新下代码,现在只初始化了项目 |
@KyrieLii |
Hi guys! I trying to do something similar but working with ssr: true, is it possible? It's throwing this error for me: |
@jianingroja 因为 nextjs remote + modernjs host 丢失了 nextjs 框架运行时上下文,这个能力是由 @ScriptedAlchemy Hi zack , any ideas for this case (modernjs host + nextjs remote) ?I think this demand will increase, do we have any solutions or plans? 🤔 |
What's the issue you are encountering? I see next router mentioned here, note it's important not to use any of the router imports from next and next.js router is coupled tightly to next itself. |
@ScriptedAlchemy ye, the problem is indeed that an error occurs when using the nextjs router api (useRouter).. |
@MaykonMorais Can you provide a minimal reproducible demo? It may not be the same problem. |
@MaykonMorais you can give a new issue for us |
@ScriptedAlchemy I'm not sure ,will the problem be solved by setting nextjs-router as shared ? |
Not work ... ignore this |
@2heal1 I have tried shared something, nextjs is a complex system .. |
Nexts router is an external that's set to the window by _app as window.NEXT_ROUTER So the best thing would be to share modernjs router and link. Then use those in next.js instead. Using modernjs route system not next. Next router only work with next host. |
@KyrieLii @ScriptedAlchemy Thank you for the replies. We are currently using Next.js page router, as it it supported with module federation next plugin. As Zack you are suggesting to use modernjs router system, which is implemented on top of react route, I am thinking, does it mean to completely refactor/abandon next page router, and replace it with react router? As each route API of react router needs to be used In the end we are having an application that behaves and structured based on Another problem is that our current nextjs application use heavily SSR, and Thank you. |
Next.js can function as a remote, but if used as a dev server, it would need a ModernJS host to vend it locally. In this setup, Next.js essentially serves as a build step. Alternatively, you could create a shared router module capable of switching between Next.js and React Router imports, allowing it to work locally with Next.js but default to ModernJS components (e.g., ModernJS’s Link) when hosted by ModernJS. A custom runtime plugin could help manage these transitions. ByteDance's broader teams plan to support migration solutions in the coming quarter; until then, I’ll work on proof-of-concept projects this month to identify and address any issues. A runtime plugin could be used to map ModernJS supports federated SSR, so document-based limitations shouldn’t be a concern—Remix can SSR effectively as well. A local development shell using ModernJS would prevent Next.js from being a host in any situation. While both can coexist, having any Vercel-owned product in your stack can introduce federation challenges. One approach is to make page components agnostic by passing Link and router props to them. This way, pages can provide the necessary elements, making the components adaptable and enabling dependency injection via props as needed. |
@ScriptedAlchemy Thank you for the comments. We will wait for the migration solution. |
@jianingroja I opened an issue about this |
NextRouter
when consuming Nextjs remote application #6498
@MaykonMorais Thank you, I will be following it! And I have added English version for this issue. |
I will not retire the plugin without solutions for users 😊 |
中文
问题描述
现有应用框架如下
主应用和子应用之间使用 Module Federation 提供的插件进行连接。
由于 Module Federation 宣布不再为 Next.js 16 及之后的版本提供插件支持,我正在尝试将主应用向 Modern.js 迁移。
期待达成的应用框架如下
目前遇到的问题是,Next.js 子应用接入后,一旦涉及到子应用内部使用 useRouter,便会产生报错,
NextRouter was not mounted
。问题复现
Demo:
可看出,当从主应用访问路由
/simple-page
时,子应用正常加载;访问/complex-page
时,由于子应用中使用了useRouter
,会产生报错NextRouter was not mounted
。错误源码
期待行为
可以从主应用正常访问加载子应用的页面。
English
Description
Micro Frontend Applications structure
next-mfe
pluginAs Module Federation announces it will stop supporting Next.js since version 16, I am trying to migration the host application to Modern.js, and keep the remote application being Next.js.
Micro Frontend Applications structure after migration
next-mfe
pluginProblem
When Next.js remote application is being consumed from the Modern.js host Application, if the loaded remote component contains the usage of
NextRouter
, an error ofNextRouter was not mounted
will be thrown.Reproduction
Demo:
It can be seen that when accessing
/simple-page
from the host application, remote application is loaded as expected. When accessingcomplex-page
, because of the usage ofuseRouter
in remote application, an errorNextRouter was not mounted
is thrown.Error source
Expectation
To load remote application with router usage from the host application.
The text was updated successfully, but these errors were encountered: