onErrorCaptured,
shallowRef
} from '@vue/runtime-test'
+import { createApp } from 'vue'
describe('Suspense', () => {
const deps: Promise<any>[] = []
expect(serializeInner(root)).toBe(`<div>two</div>`)
expect(calls).toEqual([`one mounted`, `one unmounted`, `two mounted`])
})
+
+ // #2214
+ // Since suspense renders its own root like a component, it should not patch
+ // its content in optimized mode.
+ test('should not miss nested element updates when used in templates', async () => {
+ const n = ref(1)
+ const Comp = {
+ setup() {
+ return { n }
+ },
+ template: `
+ <Suspense>
+ <div><span>{{ n }}</span></div>
+ </Suspense>
+ `
+ }
+ const root = document.createElement('div')
+ createApp(Comp).mount(root)
+ expect(root.innerHTML).toBe(`<div><span>1</span></div>`)
+
+ n.value++
+ await nextTick()
+ expect(root.innerHTML).toBe(`<div><span>2</span></div>`)
+ })
})
anchor,
parentComponent,
isSVG,
- optimized,
rendererInternals
)
}
null,
parentComponent,
suspense,
- isSVG,
- optimized
+ isSVG
)
// now check if we have encountered any async deps
if (suspense.deps > 0) {
anchor,
parentComponent,
null, // fallback tree will not have suspense context
- isSVG,
- optimized
+ isSVG
)
setActiveBranch(suspense, vnode.ssFallback!)
} else {
anchor: RendererNode | null,
parentComponent: ComponentInternalInstance | null,
isSVG: boolean,
- optimized: boolean,
{ p: patch, um: unmount, o: { createElement } }: RendererInternals
) {
const suspense = (n2.suspense = n1.suspense)!
null,
parentComponent,
suspense,
- isSVG,
- optimized
+ isSVG
)
if (suspense.deps <= 0) {
suspense.resolve()
anchor,
parentComponent,
null, // fallback tree will not have suspense context
- isSVG,
- optimized
+ isSVG
)
setActiveBranch(suspense, newFallback)
}
null,
parentComponent,
suspense,
- isSVG,
- optimized
+ isSVG
)
if (suspense.deps <= 0) {
suspense.resolve()
anchor,
parentComponent,
null, // fallback tree will not have suspense context
- isSVG,
- optimized
+ isSVG
)
setActiveBranch(suspense, newFallback)
}
anchor,
parentComponent,
suspense,
- isSVG,
- optimized
+ isSVG
)
// force resolve
suspense.resolve(true)
null,
parentComponent,
suspense,
- isSVG,
- optimized
+ isSVG
)
if (suspense.deps <= 0) {
suspense.resolve()
anchor,
parentComponent,
suspense,
- isSVG,
- optimized
+ isSVG
)
setActiveBranch(suspense, newBranch)
} else {
null,
parentComponent,
suspense,
- isSVG,
- optimized
+ isSVG
)
if (suspense.deps <= 0) {
// incoming branch has no async deps, resolve now.
parent: SuspenseBoundary | null
parentComponent: ComponentInternalInstance | null
isSVG: boolean
- optimized: boolean
container: RendererElement
hiddenContainer: RendererElement
anchor: RendererNode | null
parent,
parentComponent,
isSVG,
- optimized,
container,
hiddenContainer,
anchor,
activeBranch,
parentComponent,
container,
- isSVG,
- optimized
+ isSVG
} = suspense
// invoke @fallback event
anchor,
parentComponent,
null, // fallback tree will not have suspense context
- isSVG,
- optimized
+ isSVG
)
setActiveBranch(suspense, fallbackVNode)
}