fix(nuxt): handle multi-line slots in islands (#24212)

This commit is contained in:
Daniel Roe 2023-11-09 14:45:45 +01:00 committed by GitHub
parent bb533f8d25
commit c3cf55d963
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -97,7 +97,7 @@ function isBinding (attr: string): boolean {
function getBindings (bindings: Record<string, string>, vfor?: [string, string]): string {
if (Object.keys(bindings).length === 0) { return '' }
const content = Object.entries(bindings).filter(b => b[0] !== '_bind').map(([name, value]) => isBinding(name) ? `${name.slice(1)}: ${value}` : `${name}: \`${value}\``).join(',')
const content = Object.entries(bindings).filter(b => b[0] && b[0] !== '_bind').map(([name, value]) => isBinding(name) ? `${name.slice(1)}: ${value}` : `${name}: \`${value}\``).join(',')
const data = bindings._bind ? `mergeProps(${bindings._bind}, { ${content} })` : `{ ${content} }`
if (!vfor) {
return `:nuxt-ssr-slot-data="JSON.stringify([${data}])"`

View File

@ -34,6 +34,10 @@ describe('islandTransform - server and island components', () => {
<slot />
<slot name="named" :some-data="someData" />
<slot
name="other"
:some-data="someData"
/>
</div>
</template>
<script setup lang="ts">
@ -48,6 +52,7 @@ describe('islandTransform - server and island components', () => {
<div style=\\"display: contents;\\" nuxt-ssr-slot-name=\\"default\\" />
<div style=\\"display: contents;\\" nuxt-ssr-slot-name=\\"named\\" :nuxt-ssr-slot-data=\\"JSON.stringify([{ some-data: someData }])\\"/>
<div style=\\"display: contents;\\" nuxt-ssr-slot-name=\\"other\\" :nuxt-ssr-slot-data=\\"JSON.stringify([{ some-data: someData }])\\"/>
</div>
</template>
<script setup lang=\\"ts\\">