-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler-ssr): fix wrong attrs fallthrough on non-single-root v-i…
…f branches fix #5140
- Loading branch information
Showing
4 changed files
with
80 additions
and
22 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
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
60 changes: 60 additions & 0 deletions
60
packages/compiler-ssr/__tests__/ssrFallthroughAttrs.spec.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,60 @@ | ||
import { compile } from '../src' | ||
|
||
describe('ssr: attrs fallthrough', () => { | ||
test('basic', () => { | ||
expect(compile(`<div/>`).code).toMatchInlineSnapshot(` | ||
"const { ssrRenderAttrs: _ssrRenderAttrs } = require(\\"vue/server-renderer\\") | ||
return function ssrRender(_ctx, _push, _parent, _attrs) { | ||
_push(\`<div\${_ssrRenderAttrs(_attrs)}></div>\`) | ||
}" | ||
`) | ||
}) | ||
|
||
test('with comments', () => { | ||
expect(compile(`<!--!--><div/>`).code).toMatchInlineSnapshot(` | ||
"const { ssrRenderAttrs: _ssrRenderAttrs } = require(\\"vue/server-renderer\\") | ||
return function ssrRender(_ctx, _push, _parent, _attrs) { | ||
_push(\`<!--[--><!--!--><div\${_ssrRenderAttrs(_attrs)}></div><!--]-->\`) | ||
}" | ||
`) | ||
}) | ||
|
||
// #5140 | ||
test('should not inject to non-single-root if branches', () => { | ||
expect(compile(`<div v-if="true"/><div/>`).code).toMatchInlineSnapshot(` | ||
" | ||
return function ssrRender(_ctx, _push, _parent, _attrs) { | ||
_push(\`<!--[-->\`) | ||
if (true) { | ||
_push(\`<div></div>\`) | ||
} else { | ||
_push(\`<!---->\`) | ||
} | ||
_push(\`<div></div><!--]-->\`) | ||
}" | ||
`) | ||
}) | ||
|
||
test('fallthrough component content (root with coomments)', () => { | ||
expect(compile(`<!--root--><transition><div/></transition>`).code) | ||
.toMatchInlineSnapshot(` | ||
"const { ssrRenderAttrs: _ssrRenderAttrs } = require(\\"vue/server-renderer\\") | ||
return function ssrRender(_ctx, _push, _parent, _attrs) { | ||
_push(\`<!--[--><!--root--><div\${_ssrRenderAttrs(_attrs)}></div><!--]-->\`) | ||
}" | ||
`) | ||
}) | ||
|
||
test('should not inject to fallthrough component content if not root', () => { | ||
expect(compile(`<div/><transition><div/></transition>`).code) | ||
.toMatchInlineSnapshot(` | ||
" | ||
return function ssrRender(_ctx, _push, _parent, _attrs) { | ||
_push(\`<!--[--><div></div><div></div><!--]-->\`) | ||
}" | ||
`) | ||
}) | ||
}) |
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