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

API: Mimic PureComponent behavior for Consumer children #6412

Merged
merged 6 commits into from
May 1, 2019

Conversation

benoitdion
Copy link
Member

This fixes a bug in react-native-server where SET_CURRENT_STORY was getting spammed over and over for the same story.

This fixes a bug in react-native-server where `SET_CURRENT_STORY` was getting spammed over and over for the same story.
@vercel
Copy link

vercel bot commented Apr 4, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://monorepo-git-react-native-server-rerenders.storybook.now.sh

@benoitdion benoitdion added this to the 5.1.0 milestone Apr 4, 2019
this.prevData &&
shallowEqualObjects(data, this.prevData)
) {
return this.prevChildren;
Copy link
Member

Choose a reason for hiding this comment

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

So at first I thought this was a great idea, but later I realized this mean ALL descendant components would have to be pure for this to work as expected.

I removed the pure prop, since this is just too big of a assumption to make.

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

later I realized this mean ALL descendant components would have to be pure for this to work as expected.

Why is that the case? Or, what's preventing descendants to not be pure?

Copy link
Member

Choose a reason for hiding this comment

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

@benoitdion if you return prevChildren from render, any updates to the new children won't be part of the newly created XML tree.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm still not sure I fully understand the problem. I added 7b2539a to show an example of a descendant updating when the provider data doesn't change.

When the provider data changes, shallowEqualObjects should return false and thechildren function will get called again.

@@ -76,8 +62,7 @@ export default class ReactProvider extends Provider {
handleAPI(api) {
addons.loadAddons(api);

api.onStory((kind, story) => {
this.selection = { kind, story };
api.onStory(() => {
Copy link
Member

Choose a reason for hiding this comment

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

api.onStory should at some point be changed to api.on

I understand onStory is kinda convenient, but I don't want to add a method for every event.

@codecov
Copy link

codecov bot commented Apr 11, 2019

Codecov Report

Merging #6412 into next will increase coverage by 0.06%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next    #6412      +/-   ##
==========================================
+ Coverage   40.37%   40.44%   +0.06%     
==========================================
  Files         639      637       -2     
  Lines        8785     8761      -24     
  Branches      643      641       -2     
==========================================
- Hits         3547     3543       -4     
+ Misses       5139     5120      -19     
+ Partials       99       98       -1
Impacted Files Coverage Δ
lib/api/src/index.tsx 0% <0%> (ø) ⬆️
...react-native-server/src/client/manager/provider.js 0% <0%> (ø) ⬆️
...erver/src/client/manager/components/PreviewHelp.js 0% <0%> (ø) ⬆️
lib/ui/src/components/layout/mobile.js 77.14% <0%> (-11.43%) ⬇️
lib/cli/lib/initiate.js 0% <0%> (ø) ⬆️
...contexts/src/manager/components/ToolbarControl.tsx 0% <0%> (ø) ⬆️
.../storyshots-core/src/frameworks/angular/helpers.ts 0% <0%> (ø) ⬆️
addons/contexts/src/preview/ContextsPreviewAPI.ts 0% <0%> (ø) ⬆️
...ddons/contexts/src/shared/@mock-types/_preact.d.ts
addons/contexts/src/preview/frameworks/preact.ts
... and 4 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 7548eae...44156f5. Read the comment docs.

@ndelangen
Copy link
Member

I'll fix the merge conflict & linting today and merge

@benoitdion
Copy link
Member Author

benoitdion commented Apr 26, 2019

I'll take of it early next week if that's ok. There are a couple of things I wanted to clean up before merging.

@benoitdion benoitdion force-pushed the react-native/server-rerenders branch from fefada7 to 44156f5 Compare May 1, 2019 21:58
@benoitdion benoitdion merged commit 82a7c84 into next May 1, 2019
@benoitdion benoitdion deleted the react-native/server-rerenders branch May 1, 2019 22:19
@shilman shilman changed the title Mimic PureComponent behavior for Consumer children Addon API: Mimic PureComponent behavior for Consumer children May 2, 2019
@shilman shilman changed the title Addon API: Mimic PureComponent behavior for Consumer children API: Mimic PureComponent behavior for Consumer children May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants