-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Injecting styles into new windows opened via window.open #1229
Comments
This should be quite easily doable with emotion@10 using CacheProvider and such, but I see you are on emotion@9. It's not as easy as copying innerHTML (at least not for the production path) - I can't see in your sandbox where do you attempt to do that though. I've prepared a quick demo for you how you can achieve this now - https://codesandbox.io/s/jv0jr2j2ny . This was a quick hack, so I have not tested this thoroughly - it shows the idea though. |
@Andarist What would be the approach for doing this with CacheProvider? The link to the cache options in the docs is broken, so I'm not really sure what to look for... |
Hi everyone. I'd like to pick up the discussion here because it currently ails us. We're on emotion 10 as well. We'll be happy to make a PR if pointed in the right direction. |
Wont this work for you - #760 (comment) ? |
This problem is quite easily solvable with CacheProvider. Docs are live here - https://emotion.sh/docs/cache-provider . I hope this helps you - if not, please feel free to raise a new issue so we can discuss more (I promise you won't wait for a response as long as you did in the past). |
Hey @Andarist, I just read the doc, and I was wondering if you all had any example showing this live in action with React using this CacheProvider? Thanks! :) |
If you set up a CodeSandbox that would do what you want, just without styling, then I could probably showcase this to you. |
Here you go 😄 It doesn't refresh the setState when the modal is closed, but I think it's relatively good enough to see what I'm trying to achieve. https://codesandbox.io/s/admiring-fog-xsjnj?file=/src/App.tsx Thanks in advance |
I'm also having difficulty styling components in a window opened with |
@RPDeshaies sorry for the late reply but here you go: https://codesandbox.io/s/silly-burnell-c4ncs?file=/src/App.tsx . For this use case, it's much better to use @tomconnors your sandbox is very similar to the one provided by @RPDeshaies so I won't be making it work - I think it should become much more clear how to achieve that based on my fork of the sandbox provided by @RPDeshaies . One of the key things here is to use |
@Andarist Thanks! This solved my problem. |
emotion
version: 9.2.5react
version: 16.8.2Relevant code:
What you did:
Given a component and the snippet above,
The "hello world" rendered in the new window is rendered without any styling whatsoever, even though the page that triggered the new window has styles added to its
<head>
.Reproduction:
![Edit 24p0lk4oyj](https://camo.githubusercontent.com/ecd139ba9847d0c77607c86339eb8ee6939ca85143a92ae16ebf20f58325e1b6/68747470733a2f2f636f646573616e64626f782e696f2f7374617469632f696d672f706c61792d636f646573616e64626f782e737667)
Full reproduction on CodeSandbox
Expected
The contents of the new window receive the same styling as the source window.
What I find particularly interesting is that the components on the new window have computed
className
s – so that part works. It's just that there are no styles injected into<head>
that is throwing me off.cc @stereobooster who showed me this issue
The text was updated successfully, but these errors were encountered: