-
Notifications
You must be signed in to change notification settings - Fork 799
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
Proper children reconcile for nested tags #871
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,17 +129,19 @@ const mapChildren = (children, instances) => ({ | |
} | ||
} | ||
|
||
const newChildren = asArray((child.props && child.props.children) || []) | ||
const newChildren = asArray( | ||
(child.props && child.props.children) || child.children || [], | ||
) | ||
const nextChildren = | ||
oldChildren.length && mapChildren(newChildren, oldChildren) | ||
|
||
return { | ||
...instanceLine, | ||
// actually child merge is needed only for TAGs, and usually don't work for Components. | ||
// actually child merge is needed only for "HTML TAG"s, and usually don't work for Components. | ||
// the children from an instance or rendered children | ||
// while children from a props is just a props. | ||
// they could not exists. they could differ. | ||
...(nextChildren ? { children: nextChildren } : {}), | ||
...(nextChildren || {}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a second. A little "gap" in the tree |
||
type: child.type, | ||
} | ||
}), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,12 +213,50 @@ describe('reconciler', () => { | |
|
||
incrementGeneration() | ||
wrapper.setProps({ update: 'now' }) | ||
expect(First.rendered).toHaveBeenCalledTimes(4) | ||
expect(First.rendered).toHaveBeenCalledTimes(3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means - fixed! |
||
expect(Second.rendered).toHaveBeenCalledTimes(3) | ||
|
||
incrementGeneration() | ||
wrapper.setProps({ second: false }) | ||
expect(First.rendered).toHaveBeenCalledTimes(5) | ||
expect(Second.rendered).toHaveBeenCalledTimes(4) | ||
|
||
expect(First.unmounted).toHaveBeenCalledTimes(0) | ||
expect(Second.unmounted).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('should use new children branch during reconcile for full components', () => { | ||
const First = spyComponent(() => <u>1</u>, 'test', '1') | ||
const Second = spyComponent(() => <u>2</u>, 'test', '2') | ||
|
||
const Section = ({ children }) => <div>{children}</div> | ||
|
||
const App = ({ second }) => ( | ||
<div> | ||
<div> | ||
<Section> | ||
<First.Component /> | ||
{second && <Second.Component />} | ||
</Section> | ||
</div> | ||
</div> | ||
) | ||
|
||
const Mounter = ({ second }) => <App second={second} /> | ||
|
||
const wrapper = mount(<Mounter second />) | ||
|
||
expect(First.rendered).toHaveBeenCalledTimes(1) | ||
expect(Second.rendered).toHaveBeenCalledTimes(1) | ||
|
||
incrementGeneration() | ||
wrapper.setProps({ update: 'now' }) | ||
expect(First.rendered).toHaveBeenCalledTimes(3) | ||
expect(Second.rendered).toHaveBeenCalledTimes(3) | ||
|
||
incrementGeneration() | ||
wrapper.setProps({ second: false }) | ||
expect(First.rendered).toHaveBeenCalledTimes(7) | ||
expect(First.rendered).toHaveBeenCalledTimes(5) | ||
expect(Second.rendered).toHaveBeenCalledTimes(4) | ||
|
||
expect(First.unmounted).toHaveBeenCalledTimes(0) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When result of this function on next render iteration got in here again - it will be just ignored.
That was the first problem.