-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(transition/ssr): make transition appear work with SSR (#8859)
close #6951
- Loading branch information
1 parent
16ecb44
commit 5ea8a8a
Showing
6 changed files
with
241 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { compile } from '../src' | ||
|
||
describe('transition', () => { | ||
test('basic', () => { | ||
expect(compile(`<transition><div>foo</div></transition>`).code) | ||
.toMatchInlineSnapshot(` | ||
"const { ssrRenderAttrs: _ssrRenderAttrs } = require(\\"vue/server-renderer\\") | ||
return function ssrRender(_ctx, _push, _parent, _attrs) { | ||
_push(\`<div\${_ssrRenderAttrs(_attrs)}>foo</div>\`) | ||
}" | ||
`) | ||
}) | ||
|
||
test('with appear', () => { | ||
expect(compile(`<transition appear><div>foo</div></transition>`).code) | ||
.toMatchInlineSnapshot(` | ||
"const { ssrRenderAttrs: _ssrRenderAttrs } = require(\\"vue/server-renderer\\") | ||
return function ssrRender(_ctx, _push, _parent, _attrs) { | ||
_push(\`<template><div\${_ssrRenderAttrs(_attrs)}>foo</div></template>\`) | ||
}" | ||
`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/compiler-ssr/src/transforms/ssrTransformTransition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
ComponentNode, | ||
findProp, | ||
NodeTypes, | ||
TransformContext | ||
} from '@vue/compiler-dom' | ||
import { processChildren, SSRTransformContext } from '../ssrCodegenTransform' | ||
|
||
const wipMap = new WeakMap<ComponentNode, Boolean>() | ||
|
||
export function ssrTransformTransition( | ||
node: ComponentNode, | ||
context: TransformContext | ||
) { | ||
return () => { | ||
const appear = findProp(node, 'appear', false, true) | ||
wipMap.set(node, !!appear) | ||
} | ||
} | ||
|
||
export function ssrProcessTransition( | ||
node: ComponentNode, | ||
context: SSRTransformContext | ||
) { | ||
// #5351: filter out comment children inside transition | ||
node.children = node.children.filter(c => c.type !== NodeTypes.COMMENT) | ||
|
||
const appear = wipMap.get(node) | ||
if (appear) { | ||
context.pushStringPart(`<template>`) | ||
processChildren(node, context, false, true) | ||
context.pushStringPart(`</template>`) | ||
} else { | ||
processChildren(node, context, false, true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters