Skip to content

Commit f30017e

Browse files
committed
fix(compiler-vapor): resolve Suspense as built-in component
1 parent 58e368d commit f30017e

2 files changed

Lines changed: 72 additions & 5 deletions

File tree

packages/compiler-vapor/src/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ export function isTeleportTag(tag: string): boolean {
153153
export function isBuiltInComponent(tag: string): string | undefined {
154154
if (isTeleportTag(tag)) {
155155
return 'VaporTeleport'
156+
} else if (tag === 'Suspense' || tag === 'suspense') {
157+
// TODO: replace with VaporSuspense once it's implemented
158+
return 'Suspense'
156159
} else if (isKeepAliveTag(tag)) {
157160
return 'VaporKeepAlive'
158161
} else if (isTransitionTag(tag)) {

packages/runtime-vapor/__tests__/hydration.spec.ts

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5914,7 +5914,6 @@ describe('Vapor Mode hydration', () => {
59145914
`
59155915
const appCode = `
59165916
<script setup>
5917-
import { Suspense } from 'vue'
59185917
const components = _components
59195918
</script>
59205919
<template>
@@ -5996,7 +5995,6 @@ describe('Vapor Mode hydration', () => {
59965995
`
59975996
const appCode = `
59985997
<script setup>
5999-
import { Suspense } from 'vue'
60005998
const components = _components
60015999
</script>
60026000
<template>
@@ -6079,7 +6077,6 @@ describe('Vapor Mode hydration', () => {
60796077
`
60806078
const appCode = `
60816079
<script setup>
6082-
import { Suspense } from 'vue'
60836080
const components = _components
60846081
</script>
60856082
<template>
@@ -6177,7 +6174,6 @@ describe('Vapor Mode hydration', () => {
61776174
`
61786175
const appCode = `
61796176
<script setup>
6180-
import { Suspense } from 'vue'
61816177
const data = _data
61826178
const components = _components
61836179
</script>
@@ -6320,7 +6316,6 @@ describe('Vapor Mode hydration', () => {
63206316
`
63216317
const appCode = `
63226318
<script setup>
6323-
import { Suspense } from 'vue'
63246319
const data = _data
63256320
const components = _components
63266321
</script>
@@ -9321,6 +9316,75 @@ describe('VDOM interop', () => {
93219316
`)
93229317
})
93239318

9319+
test('hydrate static Suspense with vapor child before trailing sibling', async () => {
9320+
const serverData = ref({
9321+
tail: 'tail',
9322+
})
9323+
const clientData = ref({
9324+
html: '',
9325+
tail: 'tail',
9326+
})
9327+
const appCode = `<script setup>
9328+
const data = _data
9329+
const components = _components
9330+
</script>
9331+
<template>
9332+
<div>
9333+
<p>before</p>
9334+
<Suspense>
9335+
<components.Child />
9336+
<template #fallback></template>
9337+
</Suspense>
9338+
<span>{{ data.tail }}</span>
9339+
</div>
9340+
</template>`
9341+
const serverChildCode = `<div id="dmermaid"><svg></svg></div>`
9342+
const clientChildCode = `<script setup>
9343+
const data = _data
9344+
</script>
9345+
<template><div v-html="data.html"></div></template>`
9346+
9347+
const SSRChild = compileVaporComponent(
9348+
serverChildCode,
9349+
serverData,
9350+
undefined,
9351+
true,
9352+
)
9353+
const SSRApp = compileVaporComponent(
9354+
appCode,
9355+
serverData,
9356+
{ Child: SSRChild },
9357+
true,
9358+
)
9359+
const html = await VueServerRenderer.renderToString(
9360+
runtimeDom.createSSRApp(SSRApp),
9361+
)
9362+
9363+
const ClientChild = compileVaporComponent(clientChildCode, clientData)
9364+
const ClientApp = compileVaporComponent(appCode, clientData, {
9365+
Child: ClientChild,
9366+
})
9367+
const container = document.createElement('div')
9368+
container.innerHTML = html
9369+
document.body.appendChild(container)
9370+
const app = createVaporSSRApp(ClientApp)
9371+
app.use(runtimeVapor.vaporInteropPlugin)
9372+
app.mount(container)
9373+
9374+
expect(`Hydration node mismatch`).not.toHaveBeenWarned()
9375+
expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(`
9376+
"<div><p>before</p><div id="dmermaid"><svg></svg></div><span>tail</span></div>"
9377+
`)
9378+
9379+
clientData.value.html = '<svg data-updated="true"></svg>'
9380+
clientData.value.tail = 'tail-updated'
9381+
await nextTick()
9382+
9383+
expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(`
9384+
"<div><p>before</p><div id="dmermaid"><svg data-updated="true"></svg></div><span>tail-updated</span></div>"
9385+
`)
9386+
})
9387+
93249388
test('hydrate async Suspense VNode via createDynamicComponent and show fallback', async () => {
93259389
const data = ref({
93269390
showSuspense: true,

0 commit comments

Comments
 (0)