-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[SIGNIFICANT] Remove redundant render in react #2503
[SIGNIFICANT] Remove redundant render in react #2503
Conversation
previousKind = selectedKind; | ||
previousStory = selectedStory; | ||
ReactDOM.unmountComponentAtNode(rootEl); | ||
if (selectedKind === previousKind || previousStory === selectedStory) { |
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.
&&?
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.
😊
import React, { Component } from 'react'; | ||
|
||
function log(name) { | ||
console.log(`LifecycleLogger: ${name}`); |
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.
Feels like a linter warning ?
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.
Do you think I should use addon-actions for this instead?
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.
You can just ignore the warning =)
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.
You should use @storybook/client-logger
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.
Done.
Codecov Report
@@ Coverage Diff @@
## release/3.3 #2503 +/- ##
============================================
Coverage 19.45% 19.45%
============================================
Files 387 387
Lines 8734 8734
Branches 947 949 +2
============================================
Hits 1699 1699
+ Misses 6319 6307 -12
- Partials 716 728 +12
Continue to review full report at Codecov.
|
I wonder if it's easy to add some test that will really check the life cycle. |
Did you have an idea for this? It's tricky because it's testing the top-level of the |
Any other opinions on this @storybooks/team? Shall we merge it? |
Yeah this makes sense, we want this. Slightly concerned this will break some plugins, if they depend on this behavior. But let's merge and fix the addons if it happens. Related: #2463 |
Issue:
In the React framework code,
ReactDOM.render
would get unnecessarily called twice.What I did
Exit early from the render function if nothing is changing.
How to test
I added a story "Lifecycle:logging" to the cra-kitchen-sink app that demostrates the problem:
To reproduce: browse to the story, hit reload in the browser (as it happens whenever the preview redux store changes, there are a probably other ways to reproduce).
Previously: the component would re-render, which would log extra lines to the console.
Now: it simply renders once.
We should also satisfy ourselves that no other feature was relying on this bug (cf #2463)
Is this testable with jest or storyshots?
Not right now; it would be good to maybe use JSDOM to test this kind of thing.
Does this need a new example in the kitchen sink apps?
Yes, done
Does this need an update to the documentation?
No
If your answer is yes to any of these, please make sure to include it in your PR.