Skip to content
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

Unmount multiple css #22

Open
Taifunov opened this issue Jul 28, 2023 · 0 comments
Open

Unmount multiple css #22

Taifunov opened this issue Jul 28, 2023 · 0 comments

Comments

@Taifunov
Copy link

Taifunov commented Jul 28, 2023

Hello, how can I unmount multiple CSS files?
For instance, I have my main CSS file: myModule.css, but after the build, it also creates a couple of chunks for those styles with names: 629.myModule.css, 927.myModule.css, and after switching from 1 micro-frontend to another it unmounts just main CSS, but other are still present.

[Numbers for chunk files can be any, this is just an example]

This is my main file:

import React from 'react';
import ReactDOMClient from 'react-dom/client';
import singleSpaReact from 'single-spa-react';
import singleSpaCss from 'single-spa-css';
import { ROOT_ELEMENT_ID, module } from './configs';
import RootComponent from './root.component';

const domElementGetter = () => {
  let el = document.getElementById(ROOT_ELEMENT_ID);
  if (!el) {
    el = document.createElement("div");
    el.id = "ROOT_ELEMENT_ID";
    document.body.appendChild(el);
  }
  return el;
};

const lifecycles = singleSpaReact({
  React,
  ReactDOMClient,
  renderType: "createRoot",
  rootComponent: RootComponent,
  domElementGetter,
  errorBoundary(err, info) {
    // eslint-disable-next-line no-console
    console.error(err, info);

    return (
      <div className='container'>
        <h1>Something went wrong.</h1>
        <details style={{ whiteSpace: 'pre-wrap' }}>
          {err?.toString()}
          <br />
          {info.componentStack}
        </details>
      </div>
    );
  },
});

const cssLifecycles = singleSpaCss({
  cssUrls: [`${module.url}/${module.styles}`],
  shouldUnmount: true,
  timeout: 15000,
});


export const bootstrap = [cssLifecycles.bootstrap, lifecycles.bootstrap];
export const mount = [cssLifecycles.mount, lifecycles.mount];
export const unmount = [lifecycles.unmount, cssLifecycles.unmount];

And this is my webpack config: https://gist.github.com/Taifunov/9bfe2855ff5d3bfed92a99e9b9c1e8d3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant