-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
Add documentation on various techniques of handling CSS #242
Comments
For const { document: doc } = useFrame();
useLayoutEffect(() => {
// this covers development case as well as part of production
document.head.querySelectorAll("style").forEach((style) => {
const frameStyles = style.cloneNode(true);
doc?.head.append(frameStyles);
});
// inject the production minified styles into the iframe
if (process && process.env.NODE_ENV === "production") {
document.head.querySelectorAll('link[as="style"]').forEach((ele) => {
doc?.head.append(ele.cloneNode(true));
});
document.head
.querySelectorAll('link[rel="stylesheet"]')
.forEach((ele) => {
doc?.head.append(ele.cloneNode(true));
});
}
}, [doc]); |
@aboveyunhai What version of next and what version of this lib are you running? I'm running 13.1.1 and 5.2.6. All I get is a blank screen. If I regress to 4.1.3 of the lib. It works, but then I don't get the useFrame helper. Found out here, that it's possibly a state issue: #192 I have partial success but then
Outputs the same as document. Both giving the same parent html and not the parent AND iframe. Too many issues. If you could supply the full code, would be great! Thanks |
@paulm17 it's a react issue, you need to call useFrame() inside the instead of at the same level. const Inner = () => {
useFrame();
}
const Outer = () => {
// useFrame(); call hook here will fail because it's outside of <Frame />
<Frame>
<Inner/>
</Frame>
} |
@aboveyunhai Thanks for the quick reply. That's what I needed, I've written a wrapper function. My code in case this helps someone else.
This is how I'm using it in my proof of concept app.
I saw the examples from @ryanseddon but perhaps they work for CRA only? 🤷♂️ Anyway, I now have the latest 5.2.6 working with the help from the other thread. |
@paulm17 you are missing my production insert part, so it will only work on dev, if you use build step |
Thanks, but you missed the part where I said ^. The app won't ever see production. |
If anyone is using react-jss. This can help:
import { create } from 'jss';
import { ReactNode } from 'react';
import { useFrame } from 'react-frame-component';
import { JssProvider } from 'react-jss';
import preset from 'jss-preset-default';
const JssProviderWrapper = ({ children }: { children: ReactNode }) => {
const { document } = useFrame();
const jss = create({ insertionPoint: document.head });
jss.setup(preset());
return <JssProvider jss={jss}>{children}</JssProvider>;
};
export default JssProviderWrapper; Then use it: const App = () => (
<Frame initialContent={initialContent}>
<JssProviderWrapper>
<MyApp />
</JssProviderWrapper>
</Frame>
); |
How to load css from installed packages(node_modules)? |
This project gets a lot of questions on how to make CSS work inside the iframe from various CSS-in-JS libraries to CSS modules, SCSS etc.
Add some good examples covering how this can be done in the read me.
See latest issue with demo and code examples on solving that.
The text was updated successfully, but these errors were encountered: