-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Can this be used in a single spa application? #69
Comments
Hello @kennyist, |
There is this example of tss-react setup on a SPA: https://github.com/garronej/tss-react/tree/main/src/test/apps/spa you can run it with: git clone https://github.com/garronej/tss-react
cd tss-react
yarn
yarn build
yarn start_spa Regarding why it's not working in your case, I can't know with the fiew informations you provided me. |
Hi @garronej, thanks for the reply. Unfortunately cannot give access to the main repo, But I have made a quick setup in the same style being used at the moment, with it also not working there. This is using single spa for microservice setup. |
Thank you for setting up this sample repo.
I am getting this: Please provide additional informations to help me reproduce the specifical issue you are facing related to |
Ah sorry, You need to clone the repo and then do this for each sub folder (
Once all are running at the same time, go to http://localhost:9000. You should then get a |
Hi @kennyist, This is a problem not only for TSS but also potentially for other libraries you might be using. Please let me know it you manage to sort it out. |
Hi @kennyist - just wanted to check to see if you've had any success with this issue? I'm running into the same thing with my single-spa app (set up very similarly to your test repo you linked above) and cannot make the tss-styles override the MUI generated css-styles (have tried |
Hi @liztownd,
If you manage to setup |
@garronej & @kennyist -- I WIN! Lol. In the root-config file when registering the sub applications I passed an instance of the createCache & CacheProvider from @emotion, then picked them up from the props rather than importing them in each sub-app (I had several apps all importing their own theme object and assigning classNames). Voila, I now have one muiCache, and the styles are appearing in order, pre-prending the in root-config: import { registerApplication, start } from "single-spa";
import {
constructApplications,
constructRoutes,
constructLayoutEngine,
} from "single-spa-layout";
import microfrontendLayout from "./microfrontend-layout.html";
import { CacheProvider } from "@emotion/react";
import createCache from "@emotion/cache";
const routes = constructRoutes(microfrontendLayout);
const applications = constructApplications({
routes,
loadApp({ name }) {
return System.import(name);
},
});
const layoutEngine = constructLayoutEngine({ routes, applications });
const applicationsWithProps = applications.map((application) => {
return {
...application,
customProps: { createCache: createCache, CacheProvider: CacheProvider },
};
});
applicationsWithProps.forEach(registerApplication);
layoutEngine.activate();
start(); inside cache provider in every sub app: import { ReactChild } from "react";
import type { CacheProvider } from "@emotion/react";
import type createCache from "@emotion/cache";
export type Props = {
CacheProvider: typeof CacheProvider;
createCache: typeof createCache;
children?: ReactChild;
};
export function Theme(props: Props) {
const { CacheProvider, createCache, children } = props;
const muiCache = createCache({
"key": "mui", // to test in each sub app I assigned a different "key", they should all show up in one cache
"prepend": false
});
return <CacheProvider value={muiCache}>{children}</CacheProvider>;
}; |
@liztownd awesome, nicely done! |
@liztownd Your solution causes To fix this, don't create a new array with custom props added ( const routes = constructRoutes(microfrontendLayout, {
props: {
createCache: createCache,
CacheProvider: CacheProvider
},
loaders: {
}
}); And then in your layout html file add the props to the application like this: <application name="@your-app" props="createCache,CacheProvider"></application> |
@kennyist nice catch! Thank you! I'm new to single-spa (haven't even installed the |
I'm having issues using
tss-react
in a single spa environment. In my root app, I am able to get the UMD version ofMUI
andemotion
(not been able to find an umd/systemjs version of this package or create one successfully):And they are being externalised by webpack in the sub app I am trying to use
tss-react
, In this app I have created a cache as the docs showed:But
MUI
css always takes precedence overtss-react
created styles and cannot seem to get it to work. Is there a way to get this to work?The text was updated successfully, but these errors were encountered: