From 012dc5a30366d3325c464c3b62da123147788237 Mon Sep 17 00:00:00 2001 From: lidlanca Date: Thu, 25 Feb 2021 18:25:39 -0500 Subject: [PATCH] fix(compiler-ssr) ensure that ssrHelpers are unique after merge from parent context (#3269) fix #3268 --- .../compiler-ssr/__tests__/ssrElement.spec.ts | 21 +++++++++++++++++++ .../compiler-ssr/src/ssrCodegenTransform.ts | 5 +++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/compiler-ssr/__tests__/ssrElement.spec.ts b/packages/compiler-ssr/__tests__/ssrElement.spec.ts index 1d3a2d53..796fd41f 100644 --- a/packages/compiler-ssr/__tests__/ssrElement.spec.ts +++ b/packages/compiler-ssr/__tests__/ssrElement.spec.ts @@ -71,6 +71,27 @@ describe('ssr: element', () => { `) }) + test("multiple _ssrInterpolate at parent and child import dependency once", () => { + expect( compile(`
{{ hello }}
`).code) + .toMatchInlineSnapshot(` + "const { ssrRenderAttrs: _ssrRenderAttrs, ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\") + + return function ssrRender(_ctx, _push, _parent, _attrs) { + let _temp0 + + _push(\`\${ + _ssrInterpolate(_ctx.hello) + }\${ + _ssrInterpolate((\\"value\\" in _temp0) ? _temp0.value : \\"\\") + }\`) + }" + `); + }); + test('should pass tag to custom elements w/ dynamic v-bind', () => { expect( compile(``, { diff --git a/packages/compiler-ssr/src/ssrCodegenTransform.ts b/packages/compiler-ssr/src/ssrCodegenTransform.ts index cebce743..7f53ee62 100644 --- a/packages/compiler-ssr/src/ssrCodegenTransform.ts +++ b/packages/compiler-ssr/src/ssrCodegenTransform.ts @@ -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)) }