mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
feat(nuxt): allow keeping fallback for NuxtClientFallback
(#20336)
This commit is contained in:
parent
ebbda2cbe4
commit
603e7e7fb1
@ -30,6 +30,9 @@ This component is experimental and in order to use it you must enable the `exper
|
|||||||
- **default**: `div`
|
- **default**: `div`
|
||||||
- **placeholder** | **fallback**: Specify fallback content to be rendered if the slot fails to render.
|
- **placeholder** | **fallback**: Specify fallback content to be rendered if the slot fails to render.
|
||||||
- **type**: `string`
|
- **type**: `string`
|
||||||
|
- **keepFallback**: Keep the fallback content if it failed to render server-side.
|
||||||
|
- **type**: `boolean`
|
||||||
|
- **default**: `false`
|
||||||
|
|
||||||
```vue
|
```vue
|
||||||
<template>
|
<template>
|
||||||
|
@ -21,6 +21,10 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
placeholderTag: {
|
placeholderTag: {
|
||||||
type: String
|
type: String
|
||||||
|
},
|
||||||
|
keepFallback: {
|
||||||
|
type: Boolean,
|
||||||
|
default: () => false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['ssr-error'],
|
emits: ['ssr-error'],
|
||||||
@ -33,13 +37,14 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (mounted.value) { return ctx.slots.default?.() }
|
|
||||||
if (ssrFailed.value) {
|
if (ssrFailed.value) {
|
||||||
const slot = ctx.slots.placeholder || ctx.slots.fallback
|
if (!mounted.value || props.keepFallback) {
|
||||||
if (slot) { return slot() }
|
const slot = ctx.slots.placeholder || ctx.slots.fallback
|
||||||
const fallbackStr = props.placeholder || props.fallback
|
if (slot) { return slot() }
|
||||||
const fallbackTag = props.placeholderTag || props.fallbackTag
|
const fallbackStr = props.placeholder || props.fallback
|
||||||
return createElementBlock(fallbackTag, null, fallbackStr)
|
const fallbackTag = props.placeholderTag || props.fallbackTag
|
||||||
|
return createElementBlock(fallbackTag, null, fallbackStr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ctx.slots.default?.()
|
return ctx.slots.default?.()
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,10 @@ const NuxtClientFallbackServer = defineComponent({
|
|||||||
},
|
},
|
||||||
placeholderTag: {
|
placeholderTag: {
|
||||||
type: String
|
type: String
|
||||||
|
},
|
||||||
|
keepFallback: {
|
||||||
|
type: Boolean,
|
||||||
|
default: () => false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['ssr-error'],
|
emits: ['ssr-error'],
|
||||||
|
@ -345,6 +345,8 @@ describe('pages', () => {
|
|||||||
// ensure components reactivity once mounted
|
// ensure components reactivity once mounted
|
||||||
await page.locator('#increment-count').click()
|
await page.locator('#increment-count').click()
|
||||||
expect(await page.locator('#sugar-counter').innerHTML()).toContain('Sugar Counter 12 x 1 = 12')
|
expect(await page.locator('#sugar-counter').innerHTML()).toContain('Sugar Counter 12 x 1 = 12')
|
||||||
|
// keep-fallback strategy
|
||||||
|
expect(await page.locator('#keep-fallback').all()).toHaveLength(1)
|
||||||
// #20833
|
// #20833
|
||||||
expect(await page.locator('body').innerHTML()).not.toContain('Hello world !')
|
expect(await page.locator('body').innerHTML()).not.toContain('Hello world !')
|
||||||
await page.close()
|
await page.close()
|
||||||
|
10
test/fixtures/basic/pages/client-fallback.vue
vendored
10
test/fixtures/basic/pages/client-fallback.vue
vendored
@ -38,6 +38,16 @@
|
|||||||
<ClientFallbackStatefulSetup />
|
<ClientFallbackStatefulSetup />
|
||||||
<ClientFallbackNonStatefulSetup />
|
<ClientFallbackNonStatefulSetup />
|
||||||
<ClientFallbackNonStateful />
|
<ClientFallbackNonStateful />
|
||||||
|
<NuxtClientFallback keep-fallback>
|
||||||
|
<div>
|
||||||
|
<BreakInSetup />
|
||||||
|
</div>
|
||||||
|
<template #fallback>
|
||||||
|
<div id="keep-fallback">
|
||||||
|
keep fallback in client
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NuxtClientFallback>
|
||||||
</div>
|
</div>
|
||||||
<button id="increment-count" @click="multiplier++">
|
<button id="increment-count" @click="multiplier++">
|
||||||
increment count
|
increment count
|
||||||
|
Loading…
Reference in New Issue
Block a user