question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nextjs-sidecar example is confusing

See original GitHub issue

Great job on creating Module Federation. No doubt this is an important piece of how things will be done from now on. And quite awesome to see an example for implementation on NextJS. But I have to say the example itself is quite confusing, or at least not explained entirely. Why have a component (src/components/Dog.js) - which lives under NextJS already - treated as a remote component within NextJS. Why this loop into itself? Is this part of how Module Federation works or just to showcase how to consume components from NextJS? Please clarify this bit.

One more thing, even in this simple example the performance is surprisingly bad, is SSR not yet working with Module Federation?

Thanks again!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ScriptedAlchemycommented, Aug 1, 2020

Check this repo for a NextJS folder. It’s all in there. SSR works but I did have to bolt on some extra boilerplate because next is missing a async boundary internally.

Working to resolve that with the team.

1reaction
ScriptedAlchemycommented, Aug 23, 2020

The sidecar build is this though.

Making next and non-next work together is pretty much the same process. take a next app as is, with its import mechanism, and start up a different app and import its component / repoint the remote.

if its client-side, window.remoteName.get('./header') will work, assuming the remote is on the page.

SSR works with module federation, its next.js which does not work well with webpacks feature. SSR works on any other ssr example with far less complexity.

I made an example with bi-directional hosts. In reality, ill have apps that are just remotes, like component libraries. Those I import by injecting the script to the page myself, then manually initializing the remote inside a webpack 4 host, if its a webpack 5 host ill just import it as usual.

Webpack 4 cant share automatically, so we recreate some critical dependencies we want to share between WP4 and WP5 - manually.

Something like:

global[scope].init(
    Object.assign(
      {
        react: {
          get: () => Promise.resolve(() => require("react")),
          loaded: true,
        },
      },
      global.__webpack_require__ ? global.__webpack_require__.o : {}
    )
  );

Perf is probably bad because I’ve put nothin in place for SSR script chunks or preloading, so it boots and loads. Havent really looked at the perf, what aspects were bad?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Still a bit confused how sidecar and the various patterns work ...
so i suspect this sidecar example uses node.js pkg for the backend. I'm not familiar with node, so i suppose scripts and src...
Read more >
Sidecar for a Code Splitting. Long story short - ITNEXT
The oldest way to code split. While it may still not be quite clear when and what a sidecar is, I'll give a...
Read more >
Module Federation for React host and NextJS remote app ...
From the webpack config of the host, I can see that the next JS app is running on port 3002. You are getting...
Read more >
AMA + Messing Around with Next.js & Module Federation
Hanging out for a little, while I attempt to get Module Federation working on Next. js.
Read more >
The Sidecar Pattern for Application Developers - Medium
What ensued was a debate that introduced much confusion about the ages old sidecar / ambassador architectural patterns.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found