Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created July 29, 2021 12:53
Show Gist options
  • Save mizchi/f5c6e516896da10d63d9dd6119ca6676 to your computer and use it in GitHub Desktop.
Save mizchi/f5c6e516896da10d63d9dd6119ca6676 to your computer and use it in GitHub Desktop.
import React from "react";
import ReactDOM from "react-dom";
import { ChakraProvider, DarkMode, Button, LightMode } from "@chakra-ui/react";
import type { ApplicationProps } from "../../shell/src/types";
import { CacheProvider } from "@emotion/react";
import createCache from "@emotion/cache";
function Root(props: ApplicationProps) {
return (
<>
<LightMode>
<Button>In Light Mode</Button>
</LightMode>
<DarkMode>
<Button>In Dark Mode(Broken)</Button>
</DarkMode>
</>
);
}
const run = (props: ApplicationProps) => {
const root = props.getRoot();
const shadowRoot = root.attachShadow({ mode: "open" });
const myCache = createCache({
// @ts-ignore
container: shadowRoot,
key: "c",
});
const rootElement = document.createElement("main");
shadowRoot.appendChild(rootElement);
ReactDOM.render(
<React.StrictMode>
<CacheProvider value={myCache}>
<ChakraProvider>
<DarkMode>
<Root {...props} />
</DarkMode>
</ChakraProvider>
</CacheProvider>
</React.StrictMode>,
rootElement
);
return () => {
ReactDOM.unmountComponentAtNode(root);
};
};
export default run;
@avalanche1
Copy link

Thanks bro! Helped me out 🙏

@mannol
Copy link

mannol commented Aug 28, 2022

Thanks, love ya ❤️

@stephen-w-choo
Copy link

Oh man, this is the only working code example I've found of getting ChakraUI to work with the shadow DOM. Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment