re-renders are triggered even if the style props aren't changed
See original GitHub issueDescribe the bug
When sx
remains constant, the component re-renders on both 0.3.x and 0.4.x-rcs
To Reproduce Steps to reproduce the behavior:
-
Go to https://91hn6.csb.app/ or code
-
In react-dev-tools enable highlights when a component re-renders
-
type in the first input box (emotion
jsx
), see that only the input triggers the highlights -
type in the second input box (theme-ui
jsx
) see that the input triggers highlights even if the sx prop is hoisted out and is a constant object
Expected behavior
Ideally, if the value that is passed in to sx
doesn’t change, then emotion could also use their caching to not re-render.
Screenshots
Additional context We probably need to dig into how emotion is able to return the same component if the style stays the same.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
When does React re-render components? - Felix Gerschau
Directly mutating the props object is not allowed since this won't trigger any changes, and React doesn't notice the changes. this.props.user.
Read more >Component getting re-rendered when props aren't changing
I'm showing a map that is memoized using React. memo(). I want the map to only re-render when the props change, but it...
Read more >How and when to force a React component to re-render
React automatically re-renders components, but what happens when a component is not updating as expected? Find out what you can do here.
Read more >dynamically changing a styled component property re-renders ...
The first dom update seem to trigger a full-page re-render (throttle cpu if necessary). Then any further changes to that same property updates ......
Read more >Debug Why React (Re-)Renders a Component
Each state change in the parent component triggers a re-rendering of the child components even if they did not receive any props.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@atanasster it looks like theme-ui
0.5.0-alpha
with emotion 11 doesn’t have the re-render issue so we can probably go without the plugin for now. I’ll keep you posted if I find other cases of re-rendering due to object styles.@alexanderchan - I am a bit behind - do you think we need to incorporate the hoisting in the plugin?