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

trace(): log when computed becomes suspended #2998

Merged
merged 4 commits into from
Jun 24, 2021

Conversation

urugator
Copy link
Collaborator

trace logs when computed becomes suspended as discussed in:
#2859 (comment)

requiresObserver no longer throws, but warns, so it's consistent with computedRequiresReaction, observableRequiresReaction, etc

Improved console messages.

@changeset-bot
Copy link

changeset-bot bot commented Jun 21, 2021

🦋 Changeset detected

Latest commit: 9eca68b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mobx Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

---

`trace()`: log when computed becomes suspended
`requiresObserver` warns instead of throwing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see this change in the PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo ... requiresReaction ... the condition with die is deleted and merged to condition with warn:

 warnAboutUntrackedRead_() {
        if (!__DEV__) return
---     if (this.requiresReaction_ === true) {
---             die(`[mobx] Computed value ${this.name_} is read outside a reactive context`)
---     }
        if (this.isTracing_ !== TraceMode.NONE) {
            console.log(
                `[mobx.trace] '${this.name_}' is being read outside a reactive context. Doing a full recompute`
                `[mobx.trace] Computed value '${this.name_}' is being read outside a reactive context. Doing a full recompute.`
            )
        }
---     if (globalState.computedRequiresReaction) {
+++     if (globalState.computedRequiresReaction || this.requiresReaction_) {
            console.warn(
---            `[mobx] Computed value ${this.name_} is being read outside a reactive context. Doing a full recompute`
+++            `[mobx] Computed value '${this.name_}' is being read outside a reactive context. Doing a full recompute.`
            )
        }
    }

@mweststrate
Copy link
Member

Looking good, thanks!

@mweststrate mweststrate merged commit db21d85 into mobxjs:main Jun 24, 2021
This was referenced Jun 24, 2021
nanaya added a commit to nanaya/osu-web that referenced this pull request Sep 10, 2021
Wasted a lot of time figuring out why tracing isn't working just to find out there was missing log when computed becomes suspended (mobxjs/mobx#2998, fixed in 6.3.3).
nanaya added a commit to nanaya/osu-web that referenced this pull request Sep 10, 2021
Wasted a lot of time figuring out why tracing isn't working just to find out there was missing log when computed becomes suspended (mobxjs/mobx#2998, fixed in 6.3.3).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants