]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-ssr): should not render key/ref bindings in ssr
authorEvan You <yyx990803@gmail.com>
Fri, 27 Nov 2020 17:35:00 +0000 (12:35 -0500)
committerEvan You <yyx990803@gmail.com>
Fri, 27 Nov 2020 17:37:26 +0000 (12:37 -0500)
packages/compiler-ssr/__tests__/ssrElement.spec.ts
packages/compiler-ssr/src/transforms/ssrTransformElement.ts

index 50b7060a58cc6770ac7f18ab91bfb13440cd3a72..1d3a2d53d13a360457398de725020fabdecd8540 100644 (file)
@@ -94,6 +94,18 @@ describe('ssr: element', () => {
       ).toMatchInlineSnapshot(`"\`<div id=\\"foo\\" class=\\"bar\\"></div>\`"`)
     })
 
+    test('ignore static key/ref', () => {
+      expect(
+        getCompiledString(`<div key="1" ref="el"></div>`)
+      ).toMatchInlineSnapshot(`"\`<div></div>\`"`)
+    })
+
+    test('ignore v-bind key/ref', () => {
+      expect(
+        getCompiledString(`<div :key="1" :ref="el"></div>`)
+      ).toMatchInlineSnapshot(`"\`<div></div>\`"`)
+    })
+
     test('v-bind:class', () => {
       expect(getCompiledString(`<div id="foo" :class="bar"></div>`))
         .toMatchInlineSnapshot(`
@@ -139,7 +151,7 @@ describe('ssr: element', () => {
       `)
     })
 
-    test('v-bind:key (boolean)', () => {
+    test('v-bind:arg (boolean)', () => {
       expect(getCompiledString(`<input type="checkbox" :checked="checked">`))
         .toMatchInlineSnapshot(`
         "\`<input type=\\"checkbox\\"\${
@@ -148,7 +160,7 @@ describe('ssr: element', () => {
       `)
     })
 
-    test('v-bind:key (non-boolean)', () => {
+    test('v-bind:arg (non-boolean)', () => {
       expect(getCompiledString(`<div :id="id" class="bar"></div>`))
         .toMatchInlineSnapshot(`
         "\`<div\${
@@ -157,7 +169,7 @@ describe('ssr: element', () => {
       `)
     })
 
-    test('v-bind:[key]', () => {
+    test('v-bind:[arg]', () => {
       expect(getCompiledString(`<div v-bind:[key]="value"></div>`))
         .toMatchInlineSnapshot(`
         "\`<div\${
index e036671fcda0c73f20614cb08279a86936160cf3..cfc02530fa5ccab2022725c788ac2dfa18db9211 100644 (file)
@@ -198,6 +198,9 @@ export const ssrTransformElement: NodeTransform = (node, context) => {
               if (isStaticExp(key)) {
                 let attrName = key.content
                 // static key attr
+                if (attrName === 'key' || attrName === 'ref') {
+                  continue
+                }
                 if (attrName === 'class') {
                   openTag.push(
                     ` class="`,
@@ -274,6 +277,9 @@ export const ssrTransformElement: NodeTransform = (node, context) => {
         if (node.tag === 'textarea' && prop.name === 'value' && prop.value) {
           rawChildrenMap.set(node, escapeHtml(prop.value.content))
         } else if (!hasDynamicVBind) {
+          if (prop.name === 'key' || prop.name === 'ref') {
+            continue
+          }
           // static prop
           if (prop.name === 'class' && prop.value) {
             staticClassBinding = JSON.stringify(prop.value.content)