Skip to content
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

Merged
merged 7 commits into from
Dec 21, 2017

Conversation

tmeasday
Copy link
Member

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.

@tmeasday tmeasday changed the base branch from master to release/3.3 December 18, 2017 03:55
@tmeasday tmeasday changed the title Tmeasday/remove rendundant react render Remove rendundant react render Dec 18, 2017
previousKind = selectedKind;
previousStory = selectedStory;
ReactDOM.unmountComponentAtNode(rootEl);
if (selectedKind === previousKind || previousStory === selectedStory) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&&?

Copy link
Member Author

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}`);
Copy link
Member

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 ?

Copy link
Member Author

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?

Copy link
Member

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 =)

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@codecov
Copy link

codecov bot commented Dec 18, 2017

Codecov Report

Merging #2503 into release/3.3 will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
app/react/src/client/preview/render.js 0% <ø> (ø) ⬆️
app/react/src/server/config/babel.js 0% <0%> (-100%) ⬇️
addons/actions/src/lib/index.js 7.14% <0%> (ø) ⬆️
lib/ui/src/modules/shortcuts/actions/shortcuts.js 22.41% <0%> (ø) ⬆️
addons/actions/src/lib/types/index.js 3.44% <0%> (ø) ⬆️
...dons/actions/src/lib/types/object/getObjectName.js 37.5% <0%> (ø) ⬆️
addons/actions/src/lib/util/canConfigureName.js 30% <0%> (ø) ⬆️
lib/ui/src/modules/api/actions/api.js 51.85% <0%> (ø) ⬆️
lib/ui/src/modules/ui/components/menu_item.js 19.14% <0%> (ø) ⬆️
addons/actions/src/lib/retrocycle.js 34.09% <0%> (ø) ⬆️
... and 51 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9504ef8...4242993. Read the comment docs.

@igor-dv
Copy link
Member

igor-dv commented Dec 18, 2017

I wonder if it's easy to add some test that will really check the life cycle.

@tmeasday
Copy link
Member Author

tmeasday commented Dec 18, 2017

@igor-dv

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 app/react framework package. My thought was maybe using JSDOM (or a headless browser) and checking the console.logs, but it seems quite complex to implement.

@tmeasday
Copy link
Member Author

Any other opinions on this @storybooks/team? Shall we merge it?

@ndelangen
Copy link
Member

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

@ndelangen ndelangen added the bug label Dec 21, 2017
@ndelangen ndelangen changed the title Remove rendundant react render [SIGNIFICANT] Remove redundant render in react Dec 21, 2017
@tmeasday tmeasday merged commit be68cdf into release/3.3 Dec 21, 2017
@tmeasday tmeasday deleted the tmeasday/remove-rendundant-react-render branch December 21, 2017 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants