From 08b4e8815da4e8911058ccbab986bea6365c3352 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 29 Apr 2020 16:21:54 -0400 Subject: [PATCH] fix(compiler-ssr): avoid unnecessary withCtx import --- packages/compiler-ssr/__tests__/ssrComponent.spec.ts | 8 ++++---- .../src/transforms/ssrTransformComponent.ts | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/compiler-ssr/__tests__/ssrComponent.spec.ts b/packages/compiler-ssr/__tests__/ssrComponent.spec.ts index c0275dc9..8c5fb0d8 100644 --- a/packages/compiler-ssr/__tests__/ssrComponent.spec.ts +++ b/packages/compiler-ssr/__tests__/ssrComponent.spec.ts @@ -3,7 +3,7 @@ import { compile } from '../src' describe('ssr: components', () => { test('basic', () => { expect(compile(``).code).toMatchInlineSnapshot(` - "const { resolveComponent: _resolveComponent, withCtx: _withCtx } = require(\\"vue\\") + "const { resolveComponent: _resolveComponent } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { @@ -20,7 +20,7 @@ describe('ssr: components', () => { test('dynamic component', () => { expect(compile(``).code) .toMatchInlineSnapshot(` - "const { resolveDynamicComponent: _resolveDynamicComponent, withCtx: _withCtx } = require(\\"vue\\") + "const { resolveDynamicComponent: _resolveDynamicComponent } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { @@ -30,7 +30,7 @@ describe('ssr: components', () => { expect(compile(``).code) .toMatchInlineSnapshot(` - "const { resolveDynamicComponent: _resolveDynamicComponent, withCtx: _withCtx } = require(\\"vue\\") + "const { resolveDynamicComponent: _resolveDynamicComponent } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { @@ -285,7 +285,7 @@ describe('ssr: components', () => { expect(compile(``).code) .toMatchInlineSnapshot(` - "const { resolveComponent: _resolveComponent, withCtx: _withCtx } = require(\\"vue\\") + "const { resolveComponent: _resolveComponent } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { diff --git a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts index 95eace9a..31ee943c 100644 --- a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts +++ b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts @@ -96,10 +96,12 @@ export const ssrTransformComponent: NodeTransform = (node, context) => { // Using the cloned node, build the normal VNode-based branches (for // fallback in case the child is render-fn based). Store them in an array // for later use. - buildSlots(clonedNode, context, (props, children) => { - vnodeBranches.push(createVNodeSlotBranch(props, children, context)) - return createFunctionExpression(undefined) - }) + if (clonedNode.children.length) { + buildSlots(clonedNode, context, (props, children) => { + vnodeBranches.push(createVNodeSlotBranch(props, children, context)) + return createFunctionExpression(undefined) + }) + } const props = node.props.length > 0