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
Feasibility of micro frontends #6040
Comments
|
Just out of curiosity, what would be the purpose of this approach? |
|
The purpose would be to enable a vertical style of development - Different teams could individually develop and deploy the parts relevant to them without having to deploy the whole stack. While this could certainly be implemented as a monolithic solution that just fetches data from different sources, we want to ensure future suitability for further growth of the company and its teams, as communication and arrangements get more complex. |
|
I just wonder why would you have multiple separate next.js apps? I'd see one worker running next.js. You can already have multiple components on your pages (developed separately). Given the following {
"dependencies": {
"@alltheteams/navigation-box": "2.0.4",
"@alltheteams/product-listing-box": "1.3.9",
"@alltheteams/footer-box": "1.5.0"
}
}Now, let's presume the team working on This is a simple scenario, however, I believe it could work quite well. Any thoughts about this idea? 🙃 |
|
I tested the approach I've mentioned above. It was an easy thing thanks to create-react-library. That lib helped a lot with building the mico React apps. Please let me know if the example would be needed ;) |
|
@kopacki Wouldn't those dependencies mean that the main app would have to be rebuild for every change?
Independent deployment seems to be a requirement. |
|
Microfrontends are essentially reflecting microservices approach. If you update the dependency of some microservice, you have to deploy that microservice. The deployment of Next.js application worker could be done seamlessly, so in the end, once the team deploys a new version of their microfrontend, their work is done. |
|
After some thinking, I'd say that you could have an API that delivers components as stringified functions. These stringified functions could be run through |
|
I think it's possible ONLY if output of NextJS is not the whole HTML, but only a section of the page, like only a |
I am also doing feasibility analysis on micro frontend approach.
I am still in progress to finalize and implement, but my approaches are as below -
As of now, CSR and micro apps has implemented. Yet to implement-
Any further suggestion is most welcome, if it is feasible with next.js the it would be great. |
|
@kopacki Yes there're several ways like the one you gave as example to compose the application out of different modules, requiring them to be deployed together. A best-case scenario would be, if each separately deployable part would still run through a bundling and optimization process. If we take the concept @kopacki gave and serve them stringified, the missing Link would be, how to let an instance of e.g. express use nextjs to stitch them together on the server. @ranjanrajiv00 Yes I also came up with some ideas how to do this client side, but not a real solution on how to do this server side. I think a general question here could be: Could a node server framework, like express make use of nextjs to render explicitly into a part/container of a whole page, and serve that to the client while maintaining getInitialProps features? (Just noticed, essentially this is what @revskill10 mentioned) This would still leave open what would be the best way to share these components(like stringified functions) and also, if encapsulation would work properly, if multiple sources would be composed into one page. |
|
I've been working on the concept of having some components (like Design System library) imported as ordinary npm packages (so these would be compiled and optimised), and also having some functional components (template partials) imported as strings from a Template API. There is a small demo of my idea. I want to have two APIs, one for content and the other one for templates. These APIs would provide all information required to render given page. I will let you know once I have more detailed idea on how to implement that concept. |
|
After analyzing different approach, I implemented micro frontend as below (without next.js). Created micro apps (Core, Product and Cart).
Created a AppShell (container app).
With this approach i am able to implement micro frontend as our requirement. But still would be interested to see if i can implement same with next.js (as we are using next.js in existing application). Otherwise we have to remove next.js from future plan (micro frontend journey) |
|
@kopacki Your approach seems interesting, and appareantly it mostly boils down to using react-jsx-parser to parse the stringified components. The example you gave is clientside, will try if that works with nextjs/ssr aswell. |
|
@ranjanrajiv00 Could you give more details on how these things work together?
What does that mean essentially? Are those fetched on the server and then served to the client together with your container app, or are they just rendered clientside and therefore not taking advantage of SSR? Also, does |
|
@janus-reith /api/render will render react component using renderToString() and return to container app for SSR. |
|
My suggestion for general case is: Ability to provide a React Component as a service. That means, we need to return React Component as a JSON response, and ability to reconstruct it both on NodeJS and browser. |
|
Any example/sample code for micro frontends with next.js approach. |
|
@janus-reith and all, could you take a look into my approach. Your feedback/input would give me to make it better. |
|
I'm looking into this at the moment. As it stands you can't run two instances of next.js in the same browser because they collide on I did a quick test of this - an outer next js app using the default next js and Would it be feasible to namespace those globals above? I'm not sure exactly how, maybe we could specify a suffix in the config or something? |
Sure, will take a look :) |
|
@AlexGilleran Yes, this were the concern I had regarding the scope of each next instance. |
|
I would love to see this happening for microfrontend. Legacy code(monolith) can be splitted into different docker container and independent to each other. Similar technique develop by Taylorjs. |
|
Trulia.com is moving to Next.js using zones (https://nextjs.org/docs/advanced-features/multi-zones) ZEIT day talk: Video they did talking about it: Article series on their blog: More general article about the "why": At this point in time we're not planning on allowing running multiple Next.js apps in 1 page, as it adds a really big amount of complexity into how this have to work and how they're hydrated etc. Maybe we'll support it in the future. Zones allows you to gradually migrate to Next.js and independently deploy Next.js apps. We'll be focusing on improving the zones features 🔜 |
|
I'm not sure If I understood Zones properly, Does it means to enable or use Zones approach the entire infra (i.e each micro-app will be a zone and the app shell/ container of these micro-apps should also be built using Next JS ). In my requirement, I will be responsible for building a micro-app (I would love to use Next JS) and the other micro apps teams and the core/main(one who is responsible for stitching the app ) aren't using Next JS. As a contract from each Micro App, the core APP would expect 2 endpoints
I'm not sure will Next JS serve my purpose. Would appreciate your advice on if I can or cannot use Next JS? CC @timneutkens @ranjanrajiv00 @janus-reith Thanks in advance |
|
@timneutkens I reviewed zones and the posts and youtube videos from Trulia. Trulia's method sounds great, but I don't see how zones does builds the architecutre they're talking about. For example, the base Next app contains shared responsibilities like security and the top and bottom nav bars. The other Next apps are build into this app and use the base app's security and navigations -- Next apps with Next apps. Yet in the zones examples they don't and can't share anything. They are separate apps on different URLs "glued" together with a proxy. I don't see how you get from Next Zones to what they describe. Anyhow I could just use the proxy to glue together any app, including "create-react-apps". What I thought was different/exciting was having "full stack" micro services that included the front end (normally it's only micro-service APIs), and having a centralize next app "container" that "glued" them all in one. |
|
@timneutkens @aadamsx Have you discovered anything else about how trulia implemented their “app shell”? The current Nextjs docs describe zones as independent apps glued by a proxy. I’m facing the same issue. I need to implement a new architecture to an ERP App, its a huge one. The app contains 10 modules, thats a perfect case for micro frontends and NextJs is the best solution so far. |
|
interested in seeing an example of this much talked "app shell" |
|
I would love to continue the conversation and contribute. The current inability to stitch micro frontends is a primary deterrent from adding Next to our stack. I understand the core teams stance, but this seems like a bottleneck when building very large scale, dynamic, next js applications. |
|
I am actively working on this: ☝️ it'll be part of Webpack 5 core I'll have to backport it to WP4 if there's enough motivation. |
|
@ScriptedAlchemy Wow, this is huge and really seems to tackle the issue at its root. I'm impressed! Also thanks for the link @Jordan-Gilliam |
|
anyone interested in building a ssr framework with micro frontend support? https://twitter.com/rauchg/status/1229856712921759744?s=21 |
|
@janus-reith Thank you. I've been really frustrated that nobody actually solved this. Been building MFE stacks since 2015 and have thoroughly hated the infra and appalling amount of manual labor required. It's about time this issue is put to bed once and for all. Due to having literally written this into Webpacks core, ill be spinning up a new monorepo of various tools, routers, and other such things to offer more robust capability.
There's usually some concern around the concepts of automatic sharing or module export merging. But its already working for me so I'm struggling to see why I shouldn't offer it again as a third-party enhancement to what I'm working on. These ideas are experimental and Id much prefer a stable initial release with fewer advanced use cases built-in. Keeps its simple to write test cases for. @Jordan-Gilliam While unrelated to Webpack Federation - I've figured out how to support Suspense SSR without the current workarounds I actually co-authored (all code-splitting SSR systems are based on my original workaround react-universal-component) Suspense SSR, at least at this stage is quite straightforward. But I need to create a @msreekm Regarding the So far it works like a charm & in production. I've been able to consolidate and distribute components, pages, and apps with 0 refactor time and no binding whatsoever to I'm more than willing to work with anyone who shares my views or motives. Anything and everything federation related will be published as open-source software under an official project ill put together in the next few weeks. Let's build the future we want ❤️ |
|
@ScriptedAlchemy Any news about that ? |
|
I am working with the next.js team. There are three branches in WIP status. After those make it to a merge, ill pull the project down again and begin opening PRs for anything else, as well as start testing this out. From my initial PR is will be possible. Ill just need to add some documentation to Next or a medium post about how to enable it. It will come, guaranteed. As a workaround, i have a WP4 shim that allows next to consume federated code. However, there's limitations. I do use the shim in production and it powers AB tests and Analytics. |
|
@ScriptedAlchemy i am excited for Webpack Federation technology ! Waiting to see what you are building . |
|
Getting closer. Attempted to livestream today but had some issues. |
|
is next.js getting webpack federation support soon? @ScriptedAlchemy .thanks for the module federation examples on your channel. |
|
To be determined. Module Federation isn't a primary concern of Next, However if Next runs on Webpack 5 we should be able to make a plan with the configurations. I’m in comms with some of the internal members, internal support: unknown, compatibility: likely |
|
One of the biggest issues with module federation and Next seems to be trying to force Next.js into something that it was never designed to be. Next.js is optimized for Vercels platform. Module Federation changes the rules. We need to start from a lower design level than Next. I'm beginning to organize these thoughts in a new project with the goal of leveraging webpack to begin creating abstractions that treat [MFE, Federated Modules, Multi-Threading, Serverless, NoServer, and Edge Computing] as first class citizens with 0 cloud deps. Please note this project extremely un-refined and is the result of 1 coding session. |
|
Next.js is a part of a commercial offering. We are asking for prioritization of experimental software in a commercial product 📦 That product has its own delivery roadmap that we are, effectively, disrupting. Based on my own inspections of the source. Full module-federation support would require one async boundary be installed within the next server and next client entrypoints, before React is initially imported. If you follow my work closely, you'll know I am already using Module Federation on this platform and have moved on to upgrading the other third-party plugins that stand in my way of a production deployment at my own company. Its not perfect based on the missing async boundary, but it lets me move forward and I can manage the workaround for the time being. |
|
Hi, anyone following this thread and want to discuss this further. This seems like a mess to me! Quite complex. Are there any solutions that can work now, i.e. that don't depend on this new webpack feature? I don't care very much about SSR of my "subapps". I would be happy to use next.js to render the app shell, and then maybe use import-maps to load the subapps inside the app shell. My main requirement is to have a the subapps CI/build/deploy separate from the app shell. |
|
Module Federation is kinda the only solution I'm aware of with next.js. Other than loading separate apps entirely. If you don't care about SSR, Module federation isn't very complicated to implement client side, I've got it in production at the moment without issue |
|
@vonwao The api for Module Federation seems clear considering the complexity that it manages. Versioning and name-spacing are the main concerns so far in our implementation (we aren't using nextjs). Effective E2E tests + Federated Dashboard will also definitely help quell governance anxiety.
Do you have a shared k8s volume in your cluster? Are you aiming for something like Trulia's Architecture? |
|
Super excited about this initiative. We're looking at moving towards using vercel/nextjs. My company is also requiring the use of microfront ends to further benefit from decoupling our application(s), so it's really cool to see the prerequisite pieces start to fall into place. I notice this issue has been closed. Is there a related issue that is open that would be worth following in addition to this one, especially as webpack 5 goes into release candidate? I want to say I read that @ScriptedAlchemy has a pull request to make things come together rather nicely? |
|
Next supports webpack 5 as of 9.5 - the webpack RC was just released so if you use the RC you'll need the canary version of next. There's still issues beyond supporting webpack 5 that's related to how next is built. I've got next and webpack 5 happily in production. Sharing vendors requires some workaround in next 9. Next 10 should have async support internally which should enable module federation, without workarounds. I'm not sure if vercel plans to use MF inside of next itself (each page is an entrypoint, they could treat each page as a remote - having the host use its own remote) But I believe we will have MF support 🎊 |
|
@ScriptedAlchemy existing news. I wonder if it is possible for each remote entry to have a page set (eg. With the team, I develop such a project using CRA, React-router in host and entry, single-spa and a lot of vanilla code to async loading with edge cases. Without SSR of course. Maintenance is a nightmare. |
|
Yeah it's possible to have MF pages. You'd likely use the catch all route and have it fed to MF, see if there's a mapping available, if not then 404. I'm busy upgrading all company repos to WP5 stable and NextJS 955. While you won't be able to use sharing without workarounds. (You can't share react, thus loading multiple copies) Soon as I've got my large repos in production - I'll start working on federated page routing and will make a repo or something. I'll likely use react and react dom as externals until next is async. Overall, client side spa style routing between apps is the easiest. You can also replace the next.js router with react router or use that in the catch all as a way to route stuff easier. |
Of course it is. |
|
I would not ssr pages from other locations. SSRs would happen on another server. Client side, I'll pull chunks for routing. SSR, my infrastructure points my request to the right lambda. Each remote should be capable of rendering itself. I use a decentralized AppShell. Each host/remote has its own shell. I don't need to ssr pages that belong to something else. I'd just render on the server that handles that route. If you did want SSRd pages, a use advanced config and make react shared but import false in advanced api. Then you'd need to try shared and eager in the main host. But you might not even be able to share it in next. So be prepared to set a window global for all remotes to get react. Or manually initialize react into their share scope from next. |
|
Ssr needs code to be requirable on disk. So you need a way to share a volume. I've worked around this with custom webpack targets that let me stream code from s3 or other hosts. It makes chunk loading on node work like it does in the browser |
|
I recently came across this mono-repo framework has support for next.js, https://nx.dev/react ,it is a different approach from MF. |
|
Lol spoken to several of these companies who are moving to MF. But yeah that's a classical solution that's well presented and abstracted |
|
Hey @ScriptedAlchemy are there any updates on it? 😄 We're facing issues trying to consume a remote component inside a nextjs application using modules federation plugin. We're able to expose components, but consuming it causes issues that, after researching with no success, brought me to this thread (as I started questioning if this is not yet supposed to be possible with nextjs). So I'm considering maybe start using the multi-zones approach to give other teams possibility to have their own "microfrontend" based on pages, and do it routes based while nextjs is not yet fully supporting it, but I'm 100% sure that this is a limitation on nextjs side. |
|
any update on this?. i've seen @module-federation/nextjs-mf. but seems like no one use it base on amount of npm downloads |
|
It's on a paid registry, the one on NPM is no longer supported. https://app.privjs.com/buy/packageDetail?pkg=@module-federation/nextjs-mf I use it in production users have not reported any issues beyond some slight DX improvements like logging during builds I've also gotten SSR, multi zones / federated pages, translations, environment variables all working. I hold workshops for companies interested in the SSR system and have a reference architecture with 3 independent next apps that uses federated page routing, federated SSR etc |
|
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Im evaluating wether nextjs would be suitable for a microservice approach, where the page is build from multiple separate components that could be deployed separately.
I found different concepts that only render serser side static templates or create the content clientside.
I would like to have am isomorphic approach, preferable with nextjs.
Did anyone implement such a solution, or what would be your opinion on the technical feasibility?
E.g. the content is build from three separate nextjs apps, each running on their own port or instance. One would serve as the main UI and have a navigation to allow seamless transition between routes.
I also wonder how they could be scoped, although I think styled-jsx would really offer benefits here due to its nature.
I'd also welcome different solutions for this, main requirements would be:
The text was updated successfully, but these errors were encountered: