Skip to content

ReSub ComponentBase "swallowing" context updates #38

Description

@lucasavila00

It seems that ReSub swallows the context update on some specific use-case.
I'm having trouble using ReSub and React-Router, but I was able to reproduce it with just React.

The repro is the following:

import * as React from "react";
import { ComponentBase } from "resub";
import * as PropTypes from "prop-types";

class NotWorking extends ComponentBase<{}, {}> {
  render() {
    return <div>{this.props.children}</div>;
  }
}

class Working extends React.Component {
  render() {
    return <div>{this.props.children}</div>;
  }
}

class RenderFromContext extends React.Component {
  static contextTypes = { text: PropTypes.string };
  render() {
    return this.context.text;
  }
}

class MakeContext extends React.Component<
  {},
  { text: string }
> {
  state = {
    text: "",
  };
  static childContextTypes = { text: PropTypes.string };

  getChildContext() {
    return { text: this.state.text };
  }

  componentDidMount() {
    this.setState({ text: "Works" });
  }

  render() {
    return <div>{this.props.children}</div>;
  }
}

class App extends React.Component {
  render() {
    return (
      <MakeContext>
        Working:
        <Working>
          <RenderFromContext />
        </Working>
        Not working:
        <NotWorking>
          <RenderFromContext />
        </NotWorking>
      </MakeContext>
    );
  }
}

export default App;

If you'd like to run it on your browser I've made a create-react-app with this code and it is hosted here: https://github.com/degroote22/resubctxbug2

Just clone then npm install then npm start and you should see the following on your browser:
Working: Works Not working:

Thanks for your time 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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