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.

Support Module Federation + React SSR

See original GitHub issue

🐛 Bug Report

There are problems when trying to integrate the loadable with a React application that uses Module Federation, especially if the application performs SSR with federated components.

Sample to reproduce

I created a repository that exemplifies the issues in two use cases, one with React 16 and the other with React 18. Here is the repo link

https://github.com/brunos3d/loadable-module-federation-react-ssr

How to run it

To make it work just clone it, navigate with the terminal to one of the example folders, install the dependencies with yarn, and then run yarn start, here are the commands to run quickly:

cd samples/loadable-react-16
yarn install
yarn start

About the sample repo

The project has a readme file that explains how to use it, but basically, there are two workspaces in the samples folder, two applications in each workspace.

Expected behavior

In both samples the expected result is the same: render the app1 on the server side consuming the Content component that is federated by app2 application using Module Federation and importing it using loadable. The component must be delivered to the client side statically and must be hydrated so that it can be reactive whenever the user changes the text input.

Workarounds and hacks

I worked alongside @ScriptedAlchemy so that we could identify a way to make this work and we created some workarounds in the examples to make this work. They are described/listed here, I hope that these applied hacks can be useful to solve the problem natively. The places that have the application of these workarounds are marked with the following comment // ================ WORKAROUND ================.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:1
  • Comments:13

github_iconTop GitHub Comments

2reactions
brunos3dcommented, Dec 15, 2022

Hello, folks. Me and @ScriptedAlchemy just created a PR that adds a new option to babel-plugin called moduleFederation, it makes Module Federation compatible with loadable.

Here is a branch with the changes to test this fix.

cc: @theKashey @ScriptedAlchemy

1reaction
bwhittycommented, Nov 30, 2022

Would using a sync require() have implications on runtime performance?

e.g. a require() would mean that all this must be done up-front (at app bootup), but a import() would mean that we’d be able to resolve federated imports at any point during runtime with no impact on the running app’s process (via the non-blocking import)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-side rendering tactics for federated applications
What are the available techniques for SSR applications powered by Module Federation? There are a few to choose from, let's list them.
Read more >
Server Side Rendering Example - GitHub
Module Federation Server Side Rendering example using React Suspense. This example demonstrates a basic shell application loading remote components and ...
Read more >
Webpack Federation SSR - ebey.me
Webpack Module Federation has been a game changer in the micro-frontend space allowing multiple SPA's to operate as one cohesive bundle.
Read more >
Module federation - SSR data fetching on remote module
The problem: I am trying to set up a simple module-federation enabled React application that uses server-side rendering.
Read more >
server-side-module-federation-plugin - npm
ModuleFederationPlugin, but for the server over http. Latest version: 1.0.2, last published: 2 years ago.
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