-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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(runtime-core): properly handle async component update before resolve #11619
base: main
Are you sure you want to change the base?
Conversation
Size ReportBundles
Usages
|
@@ -1438,7 +1438,7 @@ function baseCreateRenderer( | |||
nonHydratedAsyncRoot.asyncDep!.then(() => { | |||
// the instance may be destroyed during the time period | |||
if (!instance.isUnmounted) { | |||
componentUpdateFn() | |||
instance.update() |
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.
instance.update() | |
update() |
Thank you for addressing the issue. |
@@ -1438,7 +1438,7 @@ function baseCreateRenderer( | |||
nonHydratedAsyncRoot.asyncDep!.then(() => { | |||
// the instance may be destroyed during the time period | |||
if (!instance.isUnmounted) { | |||
componentUpdateFn() | |||
update() |
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.
There is another problem here. The update()
is executed 2 times.
This behavior is not related to this PR. But it needs to be fixed.
The flow is as follows:
- When
locateNonHydratedAsyncRoot
is called,subComponent.asyncResolved
isfalse
,nonHydratedAsyncRoot
has a value, and athen
callback is registered. - The
then
callback is triggered and callsupdate
. - We go back to step 1, but
subComponent.asyncResolved
is stillfalse
because thethen
at this line is registered later and executes after the previously registeredthen
. Thethen
callback is registered again. - Same as step 2.
- Now
subComponent.asyncResolved
istrue
, andnonHydratedAsyncRoot
isundefined
. - The remaining update logic runs.
In this process, the then
callback gets registered twice, and update
is called twice.
The following code can be used to prevent this behavior.
nonHydratedAsyncRoot.asyncDep!.then(() => {
// the instance may be destroyed during the time period
queuePostRenderEffect(()=>{
if (!instance.isUnmounted) update()
},parentSuspense)
})
I'm pretty sure the previous fix is proper. |
@edison1105 I tried to fix it again, maybe it should be handled like this
You are right! I was wrong. I thought that when patching suspense, I had to confirm which component was pending, but this has nothing to do with pendingBranch. |
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
close #11617
this pr playground