2

I'm trying to load two React micro front-end applications inside the single spa. But I'm facing style conflict with respect to the theme.

systemjs-import map inside index.ejs

<script type="systemjs-importmap">
{
  "imports": {
    "single-spa": "https://cdn.jsdelivr.net/npm/single-spa@5.9.0/lib/system/single-spa.min.js",
    "react": "https://cdn.jsdelivr.net/npm/react@16.13.1/umd/react.production.min.js",
    "react-dom": "https://cdn.jsdelivr.net/npm/react-dom@16.13.1/umd/react-dom.production.min.js",
    "@nviera/sos-react-header": "//localhost:8080/...sos-react-header.js",
    "@nviera/sos": "//localhost:8081/...sos.js"
  }
}
</script>

Using the template in the index.ejs

<template id="single-spa-layout">
  <single-spa-router>
    <nav class="topnav">
      <application name="...sos-react-header"></application>
    </nav>
    <div class="main-content mt-16">
      <route path="/">
        <application name="sos"></application>
      </route>
    </div>
  </single-spa-router>
</template>

root-config.js

const routes = constructRoutes(document.querySelector('#single-spa-layout'));
const applications = constructApplications({
  routes,
  loadApp({ name }) {
    return System.import(name);
  },
});
const layoutEngine = constructLayoutEngine({
  routes,
  applications,
  active: false,
});
applications.forEach(registerApplication);
layoutEngine.activate();
start();

header application

enter image description here

main application

enter image description here

The issue I'm facing here is, I have used AppBar in the header which has Paper in it, and defined custom backgroundColor in the theme. This backgroundColor is getting override by another micro front-end (which is the "Content micro front-end")

How can we encapsulate themes separately for separate micro front-ends and avoid this conflict?

hotcakedev
  • 2,194
  • 1
  • 25
  • 47
Raghu Acharya
  • 196
  • 1
  • 13

1 Answers1

0

Style sharing/overidding between microfrontends is a major topic. You can find a detailed overview in this single-spa css documentation.

In short, you ideally need to define your theme inside a styleguide utility module or pass it down to microfrontends as props in root config.

exaucae
  • 2,071
  • 1
  • 14
  • 24