module-federation-examples icon indicating copy to clipboard operation
module-federation-examples copied to clipboard

Add SSR example with React 18 Suspense

Open botoxparty opened this issue 3 years ago • 10 comments

So i've created a working example for a server-side rendered application that hydrates on the client side.

  • No loadable-components required
  • No stats files being generated and consumed to load modules
  • All using React 18's updates to the Suspense API that allows SSR.
  • Removed enhancements such as CSS processing, HMR, etc. to make it very clear what is happening here.

In an issue that I posted, you made reference to loading the external remotes using HTTP. I wasn't able to get @telenko 's node-mf to work successfully, or @kenotron 's server-side-module-federation-plugin to work correctly.

I prefer the implementation for @kenotron 's library as it only involves lives on the server and doesn't require you to rebuild the remote with the plugin. However, I still couldn't get any of them to work.

I made some attempts to write my own remote module loader but started to run into trouble with the federated modules that were nested. I stopped because for my own purposes I don't really need this at this point and the original example did not include something like this.

Let me know your thoughts, if you think we should add anything else or remove something from this example.

botoxparty avatar Jun 05 '22 19:06 botoxparty

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jun 05 '22 19:06 CLAassistant

Yeah nested remotes were tricky. From what I've seen, these after market plugins generally are quite limited. I'll pull my nextjs SSR plugin core out into a separate node plugin as I know my implementation is fully functional

ScriptedAlchemy avatar Jun 08 '22 23:06 ScriptedAlchemy

Sounds good, let me know if you need any support with extracting the plugin core.

Will wait for that to be published to update my example.

botoxparty avatar Jun 09 '22 08:06 botoxparty

Update. We have started to work on a node plugin. It already runs but need to smooth it out a little. Will likely pick up this branch and implement it with module-federation/node

ScriptedAlchemy avatar Jun 28 '22 07:06 ScriptedAlchemy

Cool! Let me know if I can help in any way. Happy to support.

botoxparty avatar Jun 28 '22 21:06 botoxparty

Update on this. Will try to release something this week.

Our node Federation tech is proprietary and contains patents.

Will see if I'm able to ship a limited feature set or ship it as bytecode. It won't be open source but I've wanted to offer our node implementation without licensing fees.

ScriptedAlchemy avatar Jul 11 '22 03:07 ScriptedAlchemy

Do you happen to have a copy of the patent?

botoxparty avatar Jul 11 '22 07:07 botoxparty

Do you happen to have a copy of the patent?

Serverless Software Federation - A System and Method for Streaming Heterogeneous Software to Ephemeral Compute 63288643 • Filed

ScriptedAlchemy avatar Jul 11 '22 08:07 ScriptedAlchemy

Ah it's filed but not granted yet. I'll send you an email.

botoxparty avatar Jul 11 '22 12:07 botoxparty

We filed and were granted provisional patents :) so we had the time to refine the design and other docs

ScriptedAlchemy avatar Jul 12 '22 04:07 ScriptedAlchemy

ive open-sourced: https://github.com/module-federation/node

But the packae needs some work / cleanup - I'm mostly using a improved version of it under nextjs-mf/src/node-plugin

ScriptedAlchemy avatar Sep 13 '22 00:09 ScriptedAlchemy

ive open-sourced: https://github.com/module-federation/node

But the packae needs some work / cleanup - I'm mostly using a improved version of it under nextjs-mf/src/node-plugin

Based on @botoxparty work, I gave the plugin a try, and it worked. But I have some doubts about the plugin configuration and an error on the client side. Everything is described in https://github.com/botoxparty/module-federation-examples/pull/1.

I would really appreciate it if you could take a look @ScriptedAlchemy. I want to understand it :slightly_smiling_face: Let me know if I can help.

apehead avatar Sep 16 '22 18:09 apehead

@botoxparty is attempting to deploy a commit to the Module Federation Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Sep 16 '22 19:09 vercel[bot]

I have updated the PR to include @apehead 's work and have fixed the client side error that they were having.

It was basically just not loading any client-side javascript. I also added a button in the demo to test that javascript is being loaded in the client side correctly.

Let me know if there's anything else you'd like to see in this demo. I'm glad you've decided to open source these parts of module federation I think that will really help push adoption a lot further.

botoxparty avatar Sep 16 '22 20:09 botoxparty

Agreed. Was a tough call but ultimately it's for the betterment of the community.

Others have been trying to replicate my tech for several months. Which has led to many depending on very unreliable plugins from various aspects.

Node-mf was one of the better ones out there, no shade to that repo. (But it's based on my early work back when webpack was in beta)

Thanks for updating and not dropping the PR. I'm very glad to have a solid example

ScriptedAlchemy avatar Sep 17 '22 04:09 ScriptedAlchemy

If anyone runs into issues running this example it might be because you need [email protected], re: #2332

arecvlohe avatar Sep 28 '22 19:09 arecvlohe