diff --git a/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap b/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap index f55c27a9c6e..45a46210aa1 100644 --- a/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap +++ b/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap @@ -1,5 +1,16 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`stringify static html > eligible content (elements > 20) + non-eligible content 1`] = ` +"const { createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue + +return function render(_ctx, _cache) { + return (_openBlock(), _createElementBlock("div", null, _cache[0] || (_cache[0] = [ + _createStaticVNode("", 20), + _createElementVNode("div", { key: "1" }, "1", -1 /* HOISTED */) + ]))) +}" +`; + exports[`stringify static html > escape 1`] = ` "const { toDisplayString: _toDisplayString, normalizeClass: _normalizeClass, createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue diff --git a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts index fbf5718e65e..eeb13b993d4 100644 --- a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts +++ b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts @@ -122,6 +122,17 @@ describe('stringify static html', () => { expect(code).toMatchSnapshot() }) + test('eligible content (elements > 20) + non-eligible content', () => { + const { code } = compileWithStringify( + `
${repeat( + ``, + StringifyThresholds.NODE_COUNT, + )}
1
`, + ) + + expect(code).toMatchSnapshot() + }) + test('should work for multiple adjacent nodes', () => { const { ast, code } = compileWithStringify( `
${repeat( diff --git a/packages/compiler-dom/src/transforms/stringifyStatic.ts b/packages/compiler-dom/src/transforms/stringifyStatic.ts index 05535a2c312..8744497d090 100644 --- a/packages/compiler-dom/src/transforms/stringifyStatic.ts +++ b/packages/compiler-dom/src/transforms/stringifyStatic.ts @@ -108,7 +108,7 @@ export const stringifyStatic: HoistTransform = (children, context, parent) => { if (isParentCached) { ;((parent.codegenNode as VNodeCall).children as CacheExpression).value = - createArrayExpression([staticCall]) + createArrayExpression([staticCall, ...children.slice(currentIndex)]) } else { // replace the first node's hoisted expression with the static vnode call ;(currentChunk[0].codegenNode as CacheExpression).value = staticCall