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

@computed not firing when other computed value is used in triggering function #1535

Closed
michalpleszczynski opened this issue May 8, 2018 · 4 comments
Labels

Comments

@michalpleszczynski
Copy link

Hi, not sure what's going on this seems a bit too specific for stackoverflow so I'll try here.

Description:
Basically I have a store (ProductStore) that holds information about products in different variants, described by their format (folding) and color. The store has only one @observable currentVariantId that tracks which product variant is currently chosen. Whole bunch of @computed values are directly and indirectly derived from that observable.

What's (maybe) important is that I'm not injecting this store with @Inject but creating a new one for each Product component in its constructor. When user clicks buttons to change formats or colors, information in the store should automatically change.

Issue:
Everything works fine up to the point when in my component's function handleFoldingChange which calls an action on the store, after firing the action I accessed the value it is supposed to change. Suddenly, seemingly unrelated @computed functions (availableColors) stopped firing.

Reproduction:
The whole thing is fairly complicated and specific, but I've made a smaller reproduction here: https://jsfiddle.net/g7fpudq0/4/. If you click any of the buttons it will randomly change a format or color, and it will show that other variable like variant and availableColors update accordingly, but when you uncomment the lines under TODO: in handleFoldingChange, the behavior changes and values are no longer automatically updated.

Sorry for the long issue, but I'm at a complete loss here, any help is greatly appreciated. Thanks!

@urugator
Copy link
Collaborator

urugator commented May 8, 2018

Seems like bug ... the computed with transitive dependency becomes stale when (one of the) computed is accessed outside of action here is simplified reproduction
The problem is probably caused by observer, because I wasn't able to reproduce the issue with autorun alone and moreover, creating additional autorun "fixes" the staleness problem inside observer as demonstated in reproduction.

@darkowic
Copy link

@mweststrate here is a reproduction case using codesanbox https://codesandbox.io/s/1485398v7j

Greetings from React Europe ;)

@mweststrate
Copy link
Member

Confirmed, working on a fix

@mweststrate
Copy link
Member

Should be fixed in 4.3.0!

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

No branches or pull requests

4 participants