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

Specifying mergeProps causes impure connected components to not update #337

Closed
DouglasLivingstone opened this issue Apr 6, 2016 · 1 comment

Comments

@DouglasLivingstone
Copy link

When an impure connected component is re-rendered due to its parent's state changing, its shouldComponentUpdate returns true, but if a non-default mergeProps is supplied then checkMergedEquals will also be true, causing the component to only update if its nextMergedProps have changed from the previous mergedProps.

In this JSFiddle example, I would expect the root component's setState to trigger a re-render of the PartComponent and both of the impure components, but since the second impure component has a custom mergeProps, it doesn't update.

let store = Redux.createStore(() => ({}))

class PartComponent extends React.Component {
  render() {
    return <span>{ new Date().getTime() }</span>
  }
}

const Impure_DefaultMerge_Connected_PartComponent = ReactRedux.connect(
    null, null, null, { pure: false }
)(PartComponent)

const Impure_CustomMerge_ConnectedPartComponent = ReactRedux.connect(
    null, null, () => ({}), { pure: false }
)(PartComponent)

const Pure_DefaultMerge_ConnectedPartComponent = ReactRedux.connect(
    null, null, null, { pure: true }
)(PartComponent)

const Pure_CustomMerge_ConnectedPartComponent = ReactRedux.connect(
    null, null, () => ({}), { pure: true }
)(PartComponent)

class RootComponent extends React.Component {
  render() {
    return <div>
        <PartComponent /> PartComponent <br />
        <Impure_DefaultMerge_Connected_PartComponent /> Impure_DefaultMerge_Connected_PartComponent <br />
        <Impure_CustomMerge_ConnectedPartComponent /> Impure_CustomMerge_ConnectedPartComponent <br />
        <Pure_CustomMerge_ConnectedPartComponent /> Pure_CustomMerge_ConnectedPartComponent <br />
        <Pure_DefaultMerge_ConnectedPartComponent /> Pure_DefaultMerge_ConnectedPartComponent <br />
      </div>
  }
  componentDidMount() {
    setInterval(() => this.setState({}), 777)
  }
}

ReactDOM.render(
  <ReactRedux.Provider store={store}>
    <RootComponent />
  </ReactRedux.Provider>,
  document.getElementById('container')
)
tgriesser added a commit to tgriesser/react-redux that referenced this issue Apr 6, 2016
tgriesser added a commit to tgriesser/react-redux that referenced this issue Apr 6, 2016
tgriesser added a commit to tgriesser/react-redux that referenced this issue Apr 6, 2016
gaearon added a commit that referenced this issue Apr 8, 2016
Fix #337, update impure component with custom mergeProps
@gaearon
Copy link
Contributor

gaearon commented Apr 8, 2016

Fixed in 4.4.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants