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

fix(runtime-core): properly handle async component update before resolve #11619

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions packages/runtime-core/__tests__/components/Suspense.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
onErrorCaptured,
onMounted,
onUnmounted,
onUpdated,
ref,
render,
resolveDynamicComponent,
Expand Down Expand Up @@ -2161,6 +2162,81 @@ describe('Suspense', () => {
await Promise.all(deps)
})

//#11617
test('update async component before resolve then update again', async () => {
const arr: boolean[] = []
const Child = {
props: ['loading'],
async setup(props: any) {
onUpdated(() => {
arr.push(props.loading)
})
await 1
return () => {
const loading = props.loading
return h('div', null, loading ? '1' : '2')
}
},
}

const Parent = defineComponent({
setup() {
const loading = ref(false)
const delay = (delayInms: any) => {
return new Promise(resolve => setTimeout(resolve, delayInms))
}
onMounted(async () => {
loading.value = true
await delay(1000)
loading.value = false
await nextTick()
expect(arr).toEqual([true, false])
})
return () => {
return h(Child, { loading: loading.value })
}
},
})

const RouterView = {
props: {
name: { type: Object },
},
setup(props: any) {
return () => {
const name = props.name
return h(name)
}
},
}
const App = {
setup() {
const Dummy = {
setup() {
return () => {
return h('div', null, 'dummy')
}
},
}

const flag: any = shallowRef(Dummy)

onMounted(() => {
flag.value = Parent
})
return () => {
return h(Suspense, null, {
default: () => h(RouterView, { name: flag.value }),
})
}
},
}

const root: any = nodeOps.createElement('div')

render(h(App), root)
})

describe('warnings', () => {
// base function to check if a combination of slots warns or not
function baseCheckWarn(
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1444,9 +1444,9 @@ function baseCreateRenderer(
// and continue the rest of operations once the deps are resolved
nonHydratedAsyncRoot.asyncDep!.then(() => {
// the instance may be destroyed during the time period
if (!instance.isUnmounted) {
componentUpdateFn()
}
queuePostRenderEffect(() => {
if (!instance.isUnmounted) update()
}, parentSuspense)
})
return
}
Expand Down
Loading