Fix #3492: throw warning when use class component and suspense#3515
Fix #3492: throw warning when use class component and suspense#3515guochengcheng04 wants to merge 2 commits intomobxjs:mainfrom
Conversation
🦋 Changeset detectedLatest commit: af5313d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
5e30c67 to
5ffc16f
Compare
|
@mweststrate hi bro, do you have any ideas about this PR? |
urugator
left a comment
There was a problem hiding this comment.
See the comment: #3492 (comment)
1d0f0a4 to
0a8854a
Compare
| @@ -0,0 +1,12 @@ | |||
| declare class FinalizationRegistryType<T> { | |||
There was a problem hiding this comment.
Any reason not to import these utils from mobx-react-lite?
There was a problem hiding this comment.
Note, it's a slightly artifical, but you can this[reactionTrackingRefSymbol] = React.createRef()
There was a problem hiding this comment.
Note, it's a slightly artifical, but you can
this[reactionTrackingRefSymbol] = React.createRef()
Yes, but I don't think it's necessary. When a function component uses ref, because it can't get the component instance, the class component can directly cache this to achieve the same effect
There was a problem hiding this comment.
Any reason not to import these utils from
mobx-react-lite?
If you think this is more reasonable, I can modify it here. Initially, a separate file was created for decoupling between different packages
There was a problem hiding this comment.
Yes, mobx-react already depends on mobx-react-lite, it more or less only adds class support.
| const reaction = (reactiveRender[mobxAdminProperty] ??= createReaction()) | ||
|
|
||
| if (!this[reactionTrack]) { | ||
| addReactionToTrack(this, reaction, {}) |
There was a problem hiding this comment.
Move at the end of you would have to clear createReaction, otherwisethis[reactionTrack] whenever reactiveRender[mobxAdminProperty] is cleared.
EDIT: Taking it back as you have to do it anyway, because the existence of this[reactionTrack] is used as a check whether the reaction was disposed.
| Component.prototype.forceUpdate.call(this) | ||
| this[reactionTrack].changedBeforeMount = false | ||
| } | ||
| } else { |
There was a problem hiding this comment.
In order for this to happen, you have to unset this[reactionTrack] in componentWillUnmount, like here
mobx/packages/mobx-react-lite/src/useObserver.ts
Lines 103 to 104 in f0e066f
And also
this[reactionTrack] must be unset when reaction is disposed in tracking utils, is it the case?
|
Btw, I didn't want to get into it initially, but for completeness, it can also be done without tracking utils in the following fashion: // timeout could be used as well
const queueMicrotask = window.queueMicrotask ?? (microtask) => Promise.resolve().then(microtask)
// in render
queueMicrotask(() => {
if (!mounted) {
disposeReaction()
}
})
// in componentDidMount
mounted = true
if (reactionDisposed) {
recreateReaction() // can be done lazily in render
forceUpdate()
} else if (reactionNotified) { // state changed in beetwen
forceUpdate()
}This is because |
0a8854a to
a20c074
Compare
|
@urugator all change have done, check please, thank you |
a20c074 to
bd148fe
Compare
|
@urugator Can you help me approve and publish? If need me to do anything please tell me |
@mweststrate @kubk hi, can we merge and publish to finish this pr? |
Fix #3492