Skip to content

Commit 08b4e88

Browse files
committed
fix(compiler-ssr): avoid unnecessary withCtx import
1 parent a0e2c12 commit 08b4e88

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

packages/compiler-ssr/__tests__/ssrComponent.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { compile } from '../src'
33
describe('ssr: components', () => {
44
test('basic', () => {
55
expect(compile(`<foo id="a" :prop="b" />`).code).toMatchInlineSnapshot(`
6-
"const { resolveComponent: _resolveComponent, withCtx: _withCtx } = require(\\"vue\\")
6+
"const { resolveComponent: _resolveComponent } = require(\\"vue\\")
77
const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\")
88
99
return function ssrRender(_ctx, _push, _parent) {
@@ -20,7 +20,7 @@ describe('ssr: components', () => {
2020
test('dynamic component', () => {
2121
expect(compile(`<component is="foo" prop="b" />`).code)
2222
.toMatchInlineSnapshot(`
23-
"const { resolveDynamicComponent: _resolveDynamicComponent, withCtx: _withCtx } = require(\\"vue\\")
23+
"const { resolveDynamicComponent: _resolveDynamicComponent } = require(\\"vue\\")
2424
const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\")
2525
2626
return function ssrRender(_ctx, _push, _parent) {
@@ -30,7 +30,7 @@ describe('ssr: components', () => {
3030

3131
expect(compile(`<component :is="foo" prop="b" />`).code)
3232
.toMatchInlineSnapshot(`
33-
"const { resolveDynamicComponent: _resolveDynamicComponent, withCtx: _withCtx } = require(\\"vue\\")
33+
"const { resolveDynamicComponent: _resolveDynamicComponent } = require(\\"vue\\")
3434
const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\")
3535
3636
return function ssrRender(_ctx, _push, _parent) {
@@ -285,7 +285,7 @@ describe('ssr: components', () => {
285285

286286
expect(compile(`<keep-alive><foo/></keep-alive>`).code)
287287
.toMatchInlineSnapshot(`
288-
"const { resolveComponent: _resolveComponent, withCtx: _withCtx } = require(\\"vue\\")
288+
"const { resolveComponent: _resolveComponent } = require(\\"vue\\")
289289
const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\")
290290
291291
return function ssrRender(_ctx, _push, _parent) {

packages/compiler-ssr/src/transforms/ssrTransformComponent.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ export const ssrTransformComponent: NodeTransform = (node, context) => {
9696
// Using the cloned node, build the normal VNode-based branches (for
9797
// fallback in case the child is render-fn based). Store them in an array
9898
// for later use.
99-
buildSlots(clonedNode, context, (props, children) => {
100-
vnodeBranches.push(createVNodeSlotBranch(props, children, context))
101-
return createFunctionExpression(undefined)
102-
})
99+
if (clonedNode.children.length) {
100+
buildSlots(clonedNode, context, (props, children) => {
101+
vnodeBranches.push(createVNodeSlotBranch(props, children, context))
102+
return createFunctionExpression(undefined)
103+
})
104+
}
103105

104106
const props =
105107
node.props.length > 0

0 commit comments

Comments
 (0)