-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Initial work to add createGlobalStyle functionality #1416
Initial work to add createGlobalStyle functionality #1416
Conversation
Generated by 🚫 dangerJS |
Awesome! In terms of removing styles, we need to add a new method to |
I'll be looking into |
@mxstbr in a future (!) PR we should probably add interpolation support as well 😄 Edit: This could also use the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor problems that we'll need to fix first 😉 Thanks for picking this up! 🙌
return class extends React.Component { | ||
componentId = '' | ||
|
||
componentDidMount() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the component should use componentWillMount
instead 😉 otherwise this wouldn't work correctly for SSR. It's also important as we'll want the global styles to apply immediately before all DOM nodes mount (that might be referred to in or affected by these global styles).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Adjusted in df87dd7
const rules = css(strings, ...interpolations) | ||
const hash = hashStr(JSON.stringify(rules)) | ||
this.componentId = `sc-global-${hash}` | ||
if (StyleSheet.instance.hasInjectedComponent(this.componentId)) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to possible grab the stylesheet from the context (for SSR as well, and/or future tag support)
See here: https://github.com/styled-components/styled-components/blob/master/src/models/StyledComponent.js#L94
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet. Thanks for the tips. Adjusted in c6155ec
Damnnn df87dd7 🔥 🔥 🔥 Do you reckon we'll be able to use that for all styled components in the future? That'd be extremely rad. |
@mxstbr I don't think we should remove any rules for styled components as that'd be unnecessary work. We don't care whether rules remain around or not since we control their classnames 😁 |
Is there a |
34bb1f4
to
40ef36e
Compare
@JamieDixon that's definitely possible (I haven't had a look) but normally the default should be used. Maybe the Atom plugin falls back to its setting instead? That'd be horrible 😆 Feel free to add it to the Edit: Also, can you remove the |
40ef36e
to
769e3ba
Compare
Thanks @philpl. I've dropped the |
08935a6
to
5f40aa9
Compare
Is there more you'd like me to do on this one guys? I took a quick look into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me code wise, can we undo the changelog.md reformatting? That breaks git blame, which can be vital sometimes.
I'd also like some unit tests, but I can look at that if you don't want to write those 😉 We'll also need to add documentation to the website and deprecate injectGlobal for the next major.
5f40aa9
to
8bff338
Compare
8bff338
to
0985a8a
Compare
@mxstbr I've dropped the CHANGELOG commit and sent a new one with just the change we want. I need to figure out why prettier changed all the things. |
Hold on, why is that changelog entry under 2.4.1 and not under unreleased? Pretty sure that won't be going out in 2.4.1? |
Good point. Lemme fix that up. |
63bca43
to
a79cc26
Compare
Fixed |
@JamieDixon work was picked up in #1493; Please take a look to make sure that it's still on track 🙌 |
@kitten Cool. I hope what I did here was still useful 😬 |
@JamieDixon Definitely! Thanks for kicking this work off 👍 |
This is sexy. |
Closing in favor of #1493 since it's a continuation and evolution of this one 😸 |
Implements #1333
This is very much a WIP and open for discussion