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
Allow specifying the target element for appending style tags #1324
Allow specifying the target element for appending style tags #1324
Conversation
Generated by 🚫 dangerJS |
CI is failing? |
Looking it into it now! For some reason the native tests on my machine can't run due to this But since my native tests failed, it skipped the bundlesize tests. Working on a fix for that now |
@mxstbr Is there a protocol we should follow when deciding when to raise the bundlesize threshold? Looks like the CI is failing from the bundlesize tests by 0.06KB Going to take a stab at minimizing it to get it passing, but just wanted to keep you in the loop and see if there were any alternatives? Tagging @siddharthkp as this may be related? |
You can increase the max size in package.json, it's kind of annoying that this makes it so much bigger though 😢 |
@bteng22 I've been in this situation 😄 @mxstbr Ideally you want to keep the threshold a good 2-3kB more than the current size (which is 14.49kB right now) so that you can catch mistakes. Keeping it too close to the current size sounds like micromanaging 🙂 This PR does not contribute a lot to the size, there were couple of pull requests in the past that made a big impact I sound like a broken record but add the github token so that you can see the difference in each pull request (or give me access for a few hours and i'll do it for you!) |
Thanks for the input @mxstbr & @siddharthkp 👍 I raised the threshold to |
Looks awesome, thanks so much @bteng22! One point of discussion is, do we want to rename the <StyleSheetManager target={document.getElementById()}>
</StyleSheetManager>
// vs.
<StyleSheet target={document.getElementById()}>
</StyleSheet> The second one seems more obvious to users, though it might be confusing since we also have Also, what happens when you nest two This also needs a bunch of documentation over at https://github.com/styled-components/styled-components-website, mind submitting a PR there? |
No problem @mxstbr. Just trying to get this in prod ASAP 😄 Hmm maybe In regards to your other questions, we're going to investigate a little further, but I just wanted to clarify a couple questions: *When server-side rendering with an app that has a My team and I tested it locally by keeping the SSR rendering the same as the documentation with a Also, is there a better channel we could reach you or any of the moderators? We might have some quick questions that could be better clarified if we PM'd you directly? |
Wait, what would people be using it for right now? Why do we export that?!
The issue is that that only works for top-level
|
It can be used when I would hold off from renaming it to just |
Sounds good to me, let's leave it as-is then. |
Some things to note:
|
Here's an example we got working of nested StyleSheetManagers:
To your point @mxstbr , users would have to use refs (specifically on an HTMLElement and not a React Element), for the StyleSheetManager to access the given Some other scenarios we explored with our app running its own instance of styled components:
In summary, using targets seems to work easily for pulling in external apps that are also using styled-components with a target, but requires a bit more work on the client-side if one is nesting StyleSheetManagers within a single application. |
That sounds like a bug, any ideas what's up with that? |
Also |
@ivanakimov hmm definitely sounds like a bug—are you using the same StyledComponents both inside and outside of your target container? If you could code up a small example on a gist to reproduce I could take a better look @Fer0x I believe |
@bteng22 yes I've tried the same |
@ivanakimov so, that sounds like either something’s wrong with this branch, or sth is wrong with your setup and you’re using two packages, maybe 😬 Can you make sure that your project is using a single version of styled-components? (Webpack can help ensure this) And would you have time to help us and the PR submitter @bteng22 with a reproduction please? :) |
@philpl I was using the same |
@ivanakimov could it be that it was installed in both repos but isn’t deduced? If those are sufficiently separate, the npm resolution algorithm will search the closest node_modules folder upwards, so if you install it in both they might still be duplicated even if they’re identical. It unfortunately depends a lot on the folder structure and build pipeline :/ a quick fix if they’re nested in each other would be to use peer dependency in the lower project |
@philpl hmm, well they're completely different repos in different folders with their own |
Well, reinstalling I've spent 2 hours today trying to build a basic example to reproduce the bug, but no luck. I've tried to recreate our conditions (with react router, with blueprintjs, with I can clearly see it happening on our own project and the fact that styles do not load anymore right after loading the external widget, but the two repos are so big, I am not sure how else to try and trigger it in a reproducible way. On the other hand, I guess this is good news for the PR... If there's any other suggestions on what I could try, I'm all ears. |
I know I'm a little late to the game but couldn't we use this support both an insertion point in the |
Any updates on this? |
Hi guys, we've run into the same issue having multiple CRA apps on one page. |
Hello, I wanted to comment and say this PR is critical for web applications that are developed by distributed teams, that are sharing the DOM, but are using multiple instances of styled-components. In an enterprise environment such as this, I have experienced collisions / missing style rules that break the way our application renders. Having a singleton / global space where styled-components mutates the singleton style node creates some problems in distributed environments with multiple instances. Being able to target specific elements would fix this problem. Thanks. |
Has anybody found any "quick fix" / "Hacks" for fixing this ? Right now we are trying to use: http://cssinjs.org/styled-jss/ in order to solve this. |
@AndersGerner We are currently injecting StyledComponents from one place to |
@hco sounds interesting and like a solution that might work for us. Thanks for letting me know! |
Pleaaaase merge this! |
Haven't really looked at this patch too much to be honest since I don't directly need it in production right now. A thorough code review and test in production would be appreciated and would help us ship this |
Picking this up, will work on the following topics:
Work happends in #1491 |
Thank you so much for helping us improve styled-components! Based on our Community Guidelines every person that has a PR of any kind merged is offered an invitation to the styled-components organization—that is you right now! Should you accept, you'll get write access to the main repository. (and a fancy |
@bteng22 Hiya, thanks to you as well! The changes have been merged with modifications by @marionebl in #1491 |
…with multiple sources When this PR is mergend we should not need this anymore: styled-components/styled-components#1324
@mxstbr As requested here's the PR. Luckily there weren't many merge conflicts to resolve and all the tests @paul-veevers wrote are passing! My team and I also tested it locally on our application and it looks like it helped solved the rehydration problem caused by multiple styled-components that others also voiced in the issue.
I don't know if I have permissions to link this PR to #1102 since it'll essentially be a duplicate, so let know if there's any due diligence needed on my end.
Thanks again for all the help 😄