question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

create-subscription: call getValue in the constructor is too early

See original GitHub issue

Do 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:closed
  • Created 5 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
gaearoncommented, Aug 16, 2018

👍 Thanks for the repro cases, they’ve been helpful for the discussion!

1reaction
lixiaoyancommented, Aug 16, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

spring - @Value annotation not working in constructor
As far I remember, the value injection occurs after the constructor call. Try to change your constructor to this:
Read more >
Index (Java EE 6 )
AccessLocalException(String) - Constructor for exception javax.ejb. ... Application: Call the getValue() method on the specified ValueExpression .
Read more >
Index (Structure API 17.16.0 API)
Sets the "acknowledged" flag for a finished process so it is no longer shown ... calling code to get some values while other...
Read more >
Namespace Lucene.Net.Search | NCache Docs
FieldCacheRangeFilter builds a single cache for the field the first time it is used. ... Applications usually need only call the inherited Search(Query, ......
Read more >
Index (JADE v4.6.0 API)
AbsAggregate(String) - Constructor for class jade.content.abs. ... and automatically computes an AverageMeasure when the getValue() method is called.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found