-
Notifications
You must be signed in to change notification settings - Fork 262
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
Don't use deprecated lifecycle hook #457
Conversation
I think that we shouldn't use the @bvaughn I hate to bother you but I would love to know your opinion on this. Basically we are creating or updating styles and I am afraid that if we do so in To give you a bit more context this component renders styles in the <div>
<_JSXStyle id={123} css="div { color: red } p { color: green }" />
<p>howdy</p>
</div> |
Hi! The I don't have a lot of context for this problem, so please take my suggestion with a grain of salt, but I would move the This approach won't work for server-side rendering, since nothing "mounts" on the server. If you need to be able to support that as well, you could also leave the code in the constructor and run it only when |
@bvaughn 👋 thanks for the clarification! I think you suggested this a while ago but back then I didn't think about moving the side effect to
Fair enough! We'll give @kevva do you have an app to test this out? Or (better/optional) if you have time add an e2e test? I once added this https://github.com/zeit/styled-jsx/blob/master/test/browser.js but jsdom is not good for these kind of things. You could replace that with |
@kevva can you move |
Fixed in #464 |
We tried master on zeit.co and it seems that when we have the side effects in `componentDidMount` styles are rendered after the content causing transitions to apply to properties that wouldn't otherwise be animated e.g. `padding` similarly to this https://jsfiddle.net/uwbm165z/ (unfortunately I wasn't able to reproduce with React yet but here is my attempt https://codesandbox.io/s/p7q6n6r35m). In this patch we move the side effect `styleSheetRegistry.add` to `render` making sure that `shouldComponentUpdate` doesn't trigger unnecessary re-renderings. On update we then remove the old styles early enough aka on `getSnapshotBeforeUpdate`. @bvaughn this is a "followup" of the conversation we had in #457 (comment) Does it make sense?
We tried master on zeit.co and it seems that when we have the side effects in `componentDidMount` styles are rendered after the content causing transitions to apply to properties that wouldn't otherwise be animated e.g. `padding` similarly to this https://jsfiddle.net/uwbm165z/ (unfortunately I wasn't able to reproduce with React yet but here is my attempt https://codesandbox.io/s/p7q6n6r35m). In this patch we move the side effect `styleSheetRegistry.add` to `render` making sure that `shouldComponentUpdate` doesn't trigger unnecessary re-renderings. On update we then remove the old styles early enough aka on `getSnapshotBeforeUpdate`. @bvaughn this is a "followup" of the conversation we had in vercel/styled-jsx#457 (comment) Does it make sense?
We tried master on zeit.co and it seems that when we have the side effects in `componentDidMount` styles are rendered after the content causing transitions to apply to properties that wouldn't otherwise be animated e.g. `padding` similarly to this https://jsfiddle.net/uwbm165z/ (unfortunately I wasn't able to reproduce with React yet but here is my attempt https://codesandbox.io/s/p7q6n6r35m). In this patch we move the side effect `styleSheetRegistry.add` to `render` making sure that `shouldComponentUpdate` doesn't trigger unnecessary re-renderings. On update we then remove the old styles early enough aka on `getSnapshotBeforeUpdate`. @bvaughn this is a "followup" of the conversation we had in vercel/styled-jsx#457 (comment) Does it make sense?
We tried master on zeit.co and it seems that when we have the side effects in `componentDidMount` styles are rendered after the content causing transitions to apply to properties that wouldn't otherwise be animated e.g. `padding` similarly to this https://jsfiddle.net/uwbm165z/ (unfortunately I wasn't able to reproduce with React yet but here is my attempt https://codesandbox.io/s/p7q6n6r35m). In this patch we move the side effect `styleSheetRegistry.add` to `render` making sure that `shouldComponentUpdate` doesn't trigger unnecessary re-renderings. On update we then remove the old styles early enough aka on `getSnapshotBeforeUpdate`. @bvaughn this is a "followup" of the conversation we had in vercel/styled-jsx#457 (comment) Does it make sense?
We tried master on zeit.co and it seems that when we have the side effects in `componentDidMount` styles are rendered after the content causing transitions to apply to properties that wouldn't otherwise be animated e.g. `padding` similarly to this https://jsfiddle.net/uwbm165z/ (unfortunately I wasn't able to reproduce with React yet but here is my attempt https://codesandbox.io/s/p7q6n6r35m). In this patch we move the side effect `styleSheetRegistry.add` to `render` making sure that `shouldComponentUpdate` doesn't trigger unnecessary re-renderings. On update we then remove the old styles early enough aka on `getSnapshotBeforeUpdate`. @bvaughn this is a "followup" of the conversation we had in vercel/styled-jsx#457 (comment) Does it make sense?
We tried master on zeit.co and it seems that when we have the side effects in `componentDidMount` styles are rendered after the content causing transitions to apply to properties that wouldn't otherwise be animated e.g. `padding` similarly to this https://jsfiddle.net/uwbm165z/ (unfortunately I wasn't able to reproduce with React yet but here is my attempt https://codesandbox.io/s/p7q6n6r35m). In this patch we move the side effect `styleSheetRegistry.add` to `render` making sure that `shouldComponentUpdate` doesn't trigger unnecessary re-renderings. On update we then remove the old styles early enough aka on `getSnapshotBeforeUpdate`. @bvaughn this is a "followup" of the conversation we had in vercel/styled-jsx#457 (comment) Does it make sense?
When testing my app using
React.StrictMode
, it complains about the usage of this lifecycle hook. It also complains about thecomponentWillUpdate
one, but it seems like it has to stay to avoid flashes of unstyled content.