-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix #3492: throw warning when use class component and suspense #3515
base: main
Are you sure you want to change the base?
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the comment: #3492 (comment)
1d0f0a4
to
0a8854a
Compare
@@ -0,0 +1,12 @@ | |||
declare class FinalizationRegistryType<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to import these utils from mobx-react-lite
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, it's a slightly artifical, but you can this[reactionTrackingRefSymbol] = React.createRef()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, mobx-react
already depends on mobx-react-lite
, it more or less only adds class support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will do it
@@ -165,6 +191,11 @@ function createReactiveRender(originalRender: any) { | |||
isRenderingPending = false | |||
// Create reaction lazily to support re-mounting #3395 | |||
const reaction = (reactiveRender[mobxAdminProperty] ??= createReaction()) | |||
|
|||
if (!this[reactionTrack]) { | |||
addReactionToTrack(this, reaction, {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
reactionTrackingRef.current!.reaction.dispose() | |
reactionTrackingRef.current = null |
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