Skip to content

Commit

Permalink
fix: props merge order. #967 (#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey authored and gregberge committed May 8, 2018
1 parent b22f37e commit 1f8adb9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/reconciler/hotReplacementRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,20 @@ const hotReplacementRender = (instance, stack) => {
const next = instance => {
// copy over props as long new component may be hidden inside them
// child does not have all props, as long some of them can be calculated on componentMount.
const realProps = instance.props
const nextProps = {
...instance.props,
...realProps,
...(child.nextProps || {}),
...(child.props || {}),
}

if (isReactClass(instance) && instance.componentWillUpdate) {
// Force-refresh component (bypass redux renderedComponent)
instance.componentWillUpdate(nextProps, instance.state)
instance.componentWillUpdate({ ...realProps }, instance.state)
}
instance.props = nextProps
hotReplacementRender(instance, stackChild)
instance.props = realProps
}

// text node
Expand Down
4 changes: 2 additions & 2 deletions test/reconciler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('reconciler', () => {

// what props should be used? Look like the new ones
expect(second.willUpdate.mock.calls[0]).toEqual([
{ children: '42', newProp: true, keyId: '2' },
{ children: '42', keyId: '1' },
null,
{ children: '42', keyId: '1' },
null,
Expand All @@ -137,7 +137,7 @@ describe('reconciler', () => {
expect(second.willUpdate.mock.calls[1]).toEqual([
{ children: '42', newProp: true, keyId: '2' },
null,
expect.any(Object), // Flake in React 15. Should be { children: '42', keyId: "1" },
{ children: '42', keyId: '1' },
null,
])

Expand Down

0 comments on commit 1f8adb9

Please sign in to comment.