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
Hook injection makes certain styles not being applied properly #752
Comments
Any thoughts @huozhi ? :) |
Thanks for reporting, the inconsistence is caused by same property chaing from one in preloaded css (bootstrap.css in your example) and then changed in styled-jsx css so that it would trigger a css transition. Previously style tags are injected in render phase of React but it's highly dangerous and will lead to more inconsistence when upgrading to React 18 under concurrent mode. In this short period we don't have a good solution/hook to inject CSS ealier. There's still a workaround that you can try to create the styles only by styled-jsx for a component instead of mixing preloaded CSS styles and dynamic injected styles together. |
Thank you @huozhi. Why is it dangerous to inject styles in render phase? Isn't CSS feels like something that should always be present when rendering.. |
All side effects are potentially dangerous. In async rendering the render might be called multiple times which might bring more side effects. So that's why we rely on hooks for safety now. Current implementation is a transition from synchronized rendering to the future asynchronized rendering, React will propbably solve this more elegantly in the future. |
Upgrading to react 18 (currently in alpha) and next 12 can actually resolve this problem. Since we introduced the new hook from react for styled-jsx. I think you can wait for react 18 out or you can try it in advance. I'll close the issue since this might be the way to go for solving it without workaround for your case. |
Thank you @huozhi! |
@huozhi this is somehow broken again on 5.0.2. I can confirm that 5.0.1 works fine. a bit unexpected because the commits between 5.0.1 and 5.0.2 seem pretty innocuous.. |
@danqing Did you somehow manually install styled-jsx to your nextjs project? That will lead to FOUC problem where you have 2 styled-jsx registry, the collected styles aren't aigned in that case. Latest next.js is integrated with 5.0.1, and 5.0.2 will released along with next version. Can you please run |
Ah interesting... yea we do have |
next.js does have styled-jsx as dependency, if you installs next.js, styled-jsx should be able to be used out of box. That's whay I suggested to remove the duplicated one. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
On page load certain css styles aren't being loaded properly.
If the current behavior is a bug, please provide the steps to reproduce and possibly a minimal demo or testcase in the form of a Next.js app, CodeSandbox URL or similar
A repo has been uploaded here: https://github.com/luma-team/styled-jsx-issue. Run the code and you can see the above symptom.
What is the expected behavior?
The page loads to the end state directly.
Environment (include versions)
All OS / browser should have the issue.
Did this work in previous versions?
Yes.
Some additional info:
transition
attribute, which is why on page load they have the funny animation. But when an element first renders, the transition shouldn't kick in (and it didn't in previous versions).Let me know if there are other information I can provide. Thank you!
The text was updated successfully, but these errors were encountered: