Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt): pass params to client-only slot #6584

Merged
merged 5 commits into from
Aug 17, 2022
Merged
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
4 changes: 2 additions & 2 deletions packages/nuxt/src/app/components/client-only.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export function createClientOnly (component) {
.then((setupState) => {
return typeof setupState !== 'function'
? { ...setupState, mounted$ }
: () => {
: (...args) => {
return mounted$.value
// use Fragment to avoid oldChildren is null issue
? h(Fragment, null, [h(setupState(props, ctx), ctx.attrs)])
? h(Fragment, null, [h(setupState(...args), ctx.attrs)])
: h('div', ctx.attrs)
}
})
Expand Down
8 changes: 8 additions & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ describe('pages', () => {

await expectNoClientErrors('/another-parent')
})

it('/client-only-components', async () => {
const html = await $fetch('/client-only-components')
expect(html).toContain('<div class="client-only-script" foo="bar">')
expect(html).toContain('<div class="client-only-script-setup" foo="hello">')

await expectNoClientErrors('/client-only-components')
})
})

describe('head tags', () => {
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/basic/components/ClientOnlyScript.client.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script lang="ts">
export default defineNuxtComponent({
name: 'ClientOnlyScript',
props: {
foo: {
type: String
}
}
})
</script>

<template>
<div>
<div>client only script component {{ foo }}</div>
<slot name="test" />
</div>
</template>
10 changes: 10 additions & 0 deletions test/fixtures/basic/components/ClientOnlySetupScript.client.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script setup lang="ts">
const props = defineProps<{ foo: string }>()
</script>

<template>
<div>
<div>client only script setup component {{ props.foo }}</div>
<slot name="test" />
</div>
</template>
12 changes: 12 additions & 0 deletions test/fixtures/basic/pages/client-only-components.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<div>
<ClientOnlyScript class="client-only-script" foo="bar" />
<ClientOnlySetupScript class="client-only-script-setup" foo="hello">
<template #test>
<div class="slot-test">
Hello
</div>
</template>
</ClientOnlySetupScript>
</div>
</template>