This repository was 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
fix(nuxt): remove fragment from createClientOnly
#7774
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fd5a0f8
fix(nuxt): remove Fragment and use h() to render component render
huang-julien 56812d0
fix(nuxt): use createElementBlock if children is null or string
huang-julien 4e4757a
test(basic): reinforce .client components test
huang-julien d1be61e
fix(nuxt): use createElementBlock for string child components
huang-julien 569f3d4
fix(nuxt): fix attrs
huang-julien 7beb94f
test: lint + fix dev test + component ref test
huang-julien f56f329
fix(test): prefer toContain over toBe + typo + split locator
huang-julien 5c1dd06
docs: add extra comment
danielroe 11f034a
test: add .client suffix name
8d8f033
fix: use createElementVNode + reinforce tests
0e9ccd3
Merge branch 'main' into fix/client-only
huang-julien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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.vue
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,60 @@ | ||
<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" | ||
/> | ||
<!-- ensure directives are correctly passed --> | ||
<ClientStringChildStateful v-show="false" class="string-stateful-should-be-hidden" /> | ||
<ClientSetupScript v-show="false" class="client-script-should-be-hidden" foo="bar" /> | ||
<ClientStringChildStatefulScript | ||
v-show="false" | ||
class="string-stateful-script-should-be-hidden" | ||
/> | ||
<ClientNoState class="no-state" /> | ||
|
||
<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> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const stringStatefulComp = ref(null) | ||
const stringStatefulScriptComp = ref(null) | ||
const clientScript = ref(null) | ||
const clientSetupScript = ref(null) | ||
</script> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.