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

Use store revisions to ensure that stories re-render on HMR. #2588

Merged
merged 2 commits into from
Dec 28, 2017

Conversation

tmeasday
Copy link
Member

@tmeasday tmeasday commented Dec 28, 2017

For #2587

Issue:

To avoid unnecessarily re-rendering stories we don't re-render if the story name+kind haven't changed.

However on HMR, this leads to not rerendering / breakage, as in this case the name/kind haven't changed, but the store's implementation itself changed.

What I did

I added the concept of a revision to the storystore. This implies that the same name+kind can be different as the store itself has changed. I got the idea from styleguidist which I think saw something similar in when I was reading their source ;)

Moving forward, if we want dynamic stores (yes please!) we may need to generalise the concept of revision to meaning more just "incrementing on each HMR".

How to test

Try changing stories implementations in the kitchen sink.

Is this testable with jest or storyshots? No

Does this need a new example in the kitchen sink apps? No

Does this need an update to the documentation? No

We should ensure this is merged into #2241

@codecov
Copy link

codecov bot commented Dec 28, 2017

Codecov Report

Merging #2588 into master will decrease coverage by 0.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2588      +/-   ##
==========================================
- Coverage   32.68%   32.67%   -0.02%     
==========================================
  Files         398      398              
  Lines        8838     8842       +4     
  Branches      945      943       -2     
==========================================
  Hits         2889     2889              
+ Misses       5305     5297       -8     
- Partials      644      656      +12
Impacted Files Coverage Δ
app/react/src/client/preview/render.js 0% <ø> (ø) ⬆️
app/react/src/client/preview/client_api.js 83.72% <0%> (-2%) ⬇️
app/react/src/client/preview/story_store.js 0% <0%> (ø) ⬆️
lib/ui/src/modules/api/actions/api.js 51.85% <0%> (ø) ⬆️
lib/codemod/src/transforms/move-buildin-addons.js 46.87% <0%> (ø) ⬆️
addons/info/src/components/PropVal.js 82.82% <0%> (ø) ⬆️
...t-native/src/preview/components/StoryView/index.js 0% <0%> (ø) ⬆️
lib/ui/src/modules/ui/components/search_box.js 36.36% <0%> (ø) ⬆️
lib/codemod/src/transforms/update-addon-info.js 50% <0%> (ø) ⬆️
...react-native/src/manager/components/PreviewHelp.js 0% <0%> (ø) ⬆️
... and 42 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 d455f97...cc25d2b. Read the comment docs.

@Hypnosphi Hypnosphi added bug patch:yes Bugfix & documentation PR that need to be picked to main branch ui labels Dec 28, 2017
@Hypnosphi
Copy link
Member

Should we do the same for other apps?

@tmeasday
Copy link
Member Author

tmeasday commented Dec 28, 2017 via email

@Hypnosphi
Copy link
Member

They don’t have this immediate problem

Why do they need the revisions then?

Copy link
Member

@danielduan danielduan left a comment

Choose a reason for hiding this comment

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

this looks like a decent enough patch. also curious as to why the other two platforms don't need it.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

LGTM. Have confirmed the bug and the fix on my machine, but don't understand the broader implications of this change (if any).

@shilman shilman merged commit a8c3dd2 into master Dec 28, 2017
@shilman shilman deleted the tmeasday/fix-react-hmr branch December 28, 2017 03:00
@tmeasday
Copy link
Member Author

@Hypnosphi

They don’t have this immediate problem
Why do they need the revisions then?

Good question, perhaps we can discuss elsewhere (I'll make this into a PR against #2241 and we can go into detail there).

I think it is conceptually correct that we keep track in the storystore that the stories have changed; ie the output of Foo:bar (kind="Foo", name="bar") is different to what it was previously.

In this case, such a distinction is needed because our React code is trying to avoid unnecessary re-renders when the story choice hasn't changed. There was no way (until this patch) for the React code to know if the story implementation had changed.

@danielduan

also curious as to why the other two platforms don't need it

They don't need it immediately because they are not (AFAIK) making this optimization [I don't really know if they need to either]. This patch is a reaction to a bug introduced when I made this optimization in React in #2503.

@Hypnosphi Hypnosphi removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label Dec 28, 2017
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