This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nuxt): remove fragment from
createClientOnly
(#7774)
Co-authored-by: Daniel Roe <[email protected]> Co-authored-by: [email protected] <[email protected]>
- Loading branch information
1 parent
2c8c212
commit e6ca07b
Showing
10 changed files
with
262 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/fixtures/basic/components/client/MultiRootNode.client.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<template> | ||
<div v-bind="$attrs" class="multi-root-node-count"> | ||
{{ count }} | ||
</div> | ||
<button class="multi-root-node-button" @click="add"> | ||
add 1 to count | ||
</button> | ||
</template> | ||
|
||
<script setup> | ||
const count = ref(0) | ||
const add = () => count.value++ | ||
</script> |
19 changes: 19 additions & 0 deletions
19
test/fixtures/basic/components/client/MultiRootNodeScript.client.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<template> | ||
<div v-bind="$attrs" class="multi-root-node-script-count"> | ||
{{ count }} | ||
</div> | ||
<button class="multi-root-node-script-button" @click="add"> | ||
add 1 to count | ||
</button> | ||
</template> | ||
|
||
<script> | ||
export default defineNuxtComponent({ | ||
setup () { | ||
const count = ref(0) | ||
const add = () => count.value++ | ||
return { count, add } | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
<div>Hello world !</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script lang="ts"> | ||
export default defineNuxtComponent({ | ||
name: 'ClientScript', | ||
props: { | ||
foo: { | ||
type: String | ||
} | ||
}, | ||
setup (_p, ctx) { | ||
const count = ref(0) | ||
const add = () => count.value++ | ||
ctx.expose({ add }) | ||
return { | ||
count, | ||
add | ||
} | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div class="client-only-css"> | ||
client only script component {{ foo }} | ||
</div> | ||
<button @click="add"> | ||
{{ count }} | ||
</button> | ||
<slot name="test" /> | ||
</div> | ||
</template> | ||
|
||
<style> | ||
:root { | ||
--client-only: "client-only"; | ||
} | ||
</style> | ||
|
||
<style scoped> | ||
.client-only-css { | ||
color: rgb(50, 50, 50); | ||
} | ||
</style> |
18 changes: 18 additions & 0 deletions
18
test/fixtures/basic/components/client/SetupScript.client.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script setup lang="ts"> | ||
const props = defineProps<{ foo: string }>() | ||
const count = ref(0) | ||
const add = () => count.value++ | ||
defineExpose({ add }) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div>client only script setup component {{ props.foo }}</div> | ||
<button @click="add"> | ||
{{ count }} | ||
</button> | ||
|
||
<slot name="test" /> | ||
</div> | ||
</template> |
14 changes: 14 additions & 0 deletions
14
test/fixtures/basic/components/client/StringChildStateful.client.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script setup lang="ts"> | ||
const state = ref(0) | ||
const add = () => state.value++ | ||
defineExpose({ | ||
state, | ||
add | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div>Hi i should be rendered {{ state }}</div> | ||
</template> |
18 changes: 18 additions & 0 deletions
18
test/fixtures/basic/components/client/StringChildStatefulScript.client.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script lang="ts"> | ||
export default defineNuxtComponent({ | ||
setup (_p, ctx) { | ||
const state = ref(0) | ||
const add = () => state.value++ | ||
ctx.expose({ add, state }) | ||
return { | ||
state | ||
} | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div>Hi i should be rendered {{ state }}</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,67 @@ | ||
<template> | ||
<div> | ||
<ClientOnlyScript class="client-only-script" foo="bar" /> | ||
<ClientOnlySetupScript class="client-only-script-setup" foo="hello"> | ||
<ClientScript ref="clientScript" class="client-only-script" foo="bar" /> | ||
<ClientSetupScript | ||
ref="clientSetupScript" | ||
class="client-only-script-setup" | ||
foo="hello" | ||
> | ||
<template #test> | ||
<div class="slot-test"> | ||
Hello | ||
</div> | ||
</template> | ||
</ClientOnlySetupScript> | ||
</ClientSetupScript> | ||
<ClientOnly> | ||
Should not be server rendered. | ||
<template #fallback> | ||
<div>Fallback</div> | ||
</template> | ||
</ClientOnly> | ||
<!-- ensure multi root node components are correctly rendered (Fragment) --> | ||
<ClientMultiRootNode class="multi-root-node" /> | ||
<ClientMultiRootNodeScript class="multi-root-node-script" /> | ||
|
||
<!-- ensure components with a single single child are correctly rendered --> | ||
<ClientStringChildStateful ref="stringStatefulComp" class="string-stateful" /> | ||
<ClientStringChildStatefulScript | ||
ref="stringStatefulScriptComp" | ||
class="string-stateful-script" | ||
/> | ||
<ClientNoState class="no-state" /> | ||
<!-- ensure directives are correctly passed --> | ||
<ClientStringChildStateful v-show="show" class="string-stateful-should-be-hidden" /> | ||
<ClientSetupScript v-show="show" class="client-script-should-be-hidden" foo="bar" /> | ||
<ClientStringChildStatefulScript | ||
v-show="show" | ||
class="string-stateful-script-should-be-hidden" | ||
/> | ||
<ClientNoState v-show="show" class="no-state-hidden" /> | ||
|
||
<button class="test-ref-1" @click="stringStatefulComp.add"> | ||
increment count | ||
</button> | ||
<button class="test-ref-2" @click="stringStatefulScriptComp.add"> | ||
increment count | ||
</button> | ||
<button class="test-ref-3" @click="clientScript.add"> | ||
increment count | ||
</button> | ||
<button class="test-ref-4" @click="clientSetupScript.add"> | ||
increment count | ||
</button> | ||
|
||
<button id="show-all" @click="show = true"> | ||
Show all | ||
</button> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const stringStatefulComp = ref(null) | ||
const stringStatefulScriptComp = ref(null) | ||
const clientScript = ref(null) | ||
const clientSetupScript = ref(null) | ||
const show = ref(false) | ||
</script> |