]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-ssr) ensure that ssrHelpers are unique after merge from parent context...
authorlidlanca <lidlanca@yahoo.com>
Thu, 25 Feb 2021 23:25:39 +0000 (18:25 -0500)
committerGitHub <noreply@github.com>
Thu, 25 Feb 2021 23:25:39 +0000 (18:25 -0500)
fix #3268

packages/compiler-ssr/__tests__/ssrElement.spec.ts
packages/compiler-ssr/src/ssrCodegenTransform.ts

index 1d3a2d53d13a360457398de725020fabdecd8540..796fd41f70bfc9c8625940ed786462806b09ff70 100644 (file)
@@ -71,6 +71,27 @@ describe('ssr: element', () => {
       `)
     })
 
+    test("multiple _ssrInterpolate at parent and child import dependency once", () => {
+      expect( compile(`<div>{{ hello }}<textarea v-bind="a"></textarea></div>`).code)
+      .toMatchInlineSnapshot(`
+        "const { ssrRenderAttrs: _ssrRenderAttrs, ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\")
+
+        return function ssrRender(_ctx, _push, _parent, _attrs) {
+          let _temp0
+
+          _push(\`<div\${
+            _ssrRenderAttrs(_attrs)
+          }>\${
+            _ssrInterpolate(_ctx.hello)
+          }<textarea\${
+            _ssrRenderAttrs(_temp0 = _ctx.a, \\"textarea\\")
+          }>\${
+            _ssrInterpolate((\\"value\\" in _temp0) ? _temp0.value : \\"\\")
+          }</textarea></div>\`)
+        }"
+      `);
+    });
+
     test('should pass tag to custom elements w/ dynamic v-bind', () => {
       expect(
         compile(`<my-foo v-bind="obj"></my-foo>`, {
index cebce7433bf364d21f85dfd520c172ca4afa8ff3..7f53ee62c4eade3129d8a61ab8262817b6bdf957 100644 (file)
@@ -56,10 +56,11 @@ export function ssrCodegenTransform(ast: RootNode, options: CompilerOptions) {
 
   // Finalize helpers.
   // We need to separate helpers imported from 'vue' vs. '@vue/server-renderer'
-  ast.ssrHelpers = [
+  ast.ssrHelpers = Array.from(new Set([  
     ...ast.helpers.filter(h => h in ssrHelpers),
     ...context.helpers
-  ]
+  ]))
+  
   ast.helpers = ast.helpers.filter(h => !(h in ssrHelpers))
 }