create-subscription: call getValue in the constructor is too early
See original GitHub issueDo you want to request a feature or report a bug?
BUG
What is the current behavior?
https://codepen.io/intptr/pen/djEzbr?editors=1010
I made an example to show the execution order of some lifecycle functions while remounting a component:
newComponent.constructor() -> oldComponent.componentWillUnmount() -> newComponent.componentDidMount()
create-subscription calls getValue in constructor and save the result to its state. Before componentDidMount called, any changes will be ignored.
If I remount a component wrapped by create-subscription component, and do something in its componentWillMount which will modify the source value, I will get the wrong value in componentDidMount in the new component.
newComp.constructor -> oldComp.cWU -> newComp.cDM
state = A A -> B A !! (correct: B)
What is the expected behavior?
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
16.4.2 (latest)
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (7 by maintainers)

Top Related StackOverflow Question
👍 Thanks for the repro cases, they’ve been helpful for the discussion!
@gaearon I tried to make a runnable example yesterday and I found there’s no umd version of create-subscription on npm and then I gave it up 😂 I will take a look into CodeSandbox and try to make an online example later.