Skip to content

0.14.0-alpha1 children with parent-based context changes don't update #4218

@ryanflorence

Description

@ryanflorence
var Top = React.createClass({
  childContextTypes: {
    now: React.PropTypes.any
  },

  getChildContext() {
    return {
      now: this.state.now
    };
  },

  getInitialState() {
    return {
      now: Date.now()
    };
  },

  componentDidMount() {
    setInterval(() => {
      this.setState({
        now: Date.now()
      });
    }, 500);
  },

  render() {
    return (
      <div>
        <h1>{this.state.now}</h1>
        {React.cloneElement(this.props.children)}
      </div>
    );
  }
});

var Middle = React.createClass({
  render() {
    return React.Children.only(this.props.children);
  }
});

var Child = React.createClass({

  contextTypes: {
    now: React.PropTypes.any
  },

  shouldComponentUpdate() {
    return true;
  },

  render() {
    return <h2>{this.context.now}</h2>;
  }

});

// remove the bailout in the reconciler and this works
React.render(<Top><Child/></Top>, document.getElementById('example'));

// but this still doesn't
React.render(<Top><Middle><Child/></Middle></Top>, document.getElementById('example'));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions