perf: pre-allocated array teleport island + utils

This commit is contained in:
tbitw2549 2024-10-22 22:38:57 +03:00
parent 944e758daf
commit cca39cd535
2 changed files with 6 additions and 6 deletions

View File

@ -35,23 +35,23 @@ export default defineComponent({
} }
return () => { return () => {
const vnodes: VNode[] = [] const vnodes: VNode[] = new Array(1)
if (nuxtApp.ssrContext?.islandContext && slots.default) { if (nuxtApp.ssrContext?.islandContext && slots.default) {
vnodes.push(h('div', { vnodes[0] = h('div', {
'style': 'display: contents;', 'style': 'display: contents;',
'data-island-uid': '', 'data-island-uid': '',
'data-island-slot': props.name, 'data-island-slot': props.name,
}, { }, {
// Teleport in slot to not be hydrated client-side with the staticVNode // Teleport in slot to not be hydrated client-side with the staticVNode
default: () => [createVNode(Teleport, { to: `island-slot=${componentName};${props.name}` }, slots.default?.())], default: () => [createVNode(Teleport, { to: `island-slot=${componentName};${props.name}` }, slots.default?.())],
})) })
} else { } else {
vnodes.push(h('div', { vnodes[0] = h('div', {
'style': 'display: contents;', 'style': 'display: contents;',
'data-island-uid': '', 'data-island-uid': '',
'data-island-slot': props.name, 'data-island-slot': props.name,
})) })
} }
if (slots.fallback) { if (slots.fallback) {

View File

@ -89,7 +89,7 @@ export function vforToArray (source: any): any[] {
if (import.meta.dev && !Number.isInteger(source)) { if (import.meta.dev && !Number.isInteger(source)) {
console.warn(`The v-for range expect an integer value but got ${source}.`) console.warn(`The v-for range expect an integer value but got ${source}.`)
} }
const array: number[] = [] const array: number[] = new Array(source)
for (let i = 0; i < source; i++) { for (let i = 0; i < source; i++) {
array[i] = i array[i] = i
} }