Skip to content

Commit f51014a

Browse files
authored
Merge branch 'main' into edison/refactor/vBindShorthand
2 parents fbfc668 + 836b829 commit f51014a

File tree

7 files changed

+75
-6
lines changed

7 files changed

+75
-6
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileTemplate.spec.ts.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,27 @@ export function render(_ctx, _cache) {
1212
}"
1313
`;
1414

15+
exports[`prefixing props edge case in inline mode 1`] = `
16+
"import { defineComponent as _defineComponent } from 'vue'
17+
import { unref as _unref, openBlock as _openBlock, createBlock as _createBlock } from "vue"
18+
19+
20+
export default /*@__PURE__*/_defineComponent({
21+
props: {
22+
Foo: { type: Object, required: true }
23+
},
24+
setup(__props: any) {
25+
26+
27+
28+
return (_ctx: any,_cache: any) => {
29+
return (_openBlock(), _createBlock(_unref(__props["Foo"]).Bar))
30+
}
31+
}
32+
33+
})"
34+
`;
35+
1536
exports[`should not hoist srcset URLs in SSR mode 1`] = `
1637
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode } from "vue"
1738
import { ssrRenderAttr as _ssrRenderAttr, ssrRenderComponent as _ssrRenderComponent } from "vue/server-renderer"

packages/compiler-sfc/__tests__/compileTemplate.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,22 @@ test('non-identifier expression in legacy filter syntax', () => {
512512
babelParse(compilationResult.code, { sourceType: 'module' })
513513
}).not.toThrow()
514514
})
515+
516+
test('prefixing props edge case in inline mode', () => {
517+
const src = `
518+
<script setup lang="ts">
519+
defineProps<{ Foo: { Bar: unknown } }>()
520+
</script>
521+
<template>
522+
<Foo.Bar/>
523+
</template>
524+
`
525+
const { descriptor } = parse(src)
526+
const { content } = compileScript(descriptor, {
527+
id: 'xxx',
528+
inlineTemplate: true,
529+
})
530+
531+
expect(content).toMatchSnapshot()
532+
expect(content).toMatch(`__props["Foo"]).Bar`)
533+
})

packages/compiler-sfc/src/compileScript.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,8 @@ export function compileScript(
833833
let templateMap
834834
// 9. generate return statement
835835
let returned
836+
// ensure props bindings register before compile template in inline mode
837+
const propsDecl = genRuntimeProps(ctx)
836838
if (
837839
!options.inlineTemplate ||
838840
(!sfc.template && ctx.hasDefaultExportRender)
@@ -965,7 +967,6 @@ export function compileScript(
965967
runtimeOptions += `\n __ssrInlineRender: true,`
966968
}
967969

968-
const propsDecl = genRuntimeProps(ctx)
969970
if (propsDecl) runtimeOptions += `\n props: ${propsDecl},`
970971

971972
const emitsDecl = genRuntimeEmits(ctx)

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ describe('ssr: v-show', () => {
1111
const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
1212
1313
return function ssrRender(_ctx, _push, _parent, _attrs) {
14-
_push(\`<div\${_ssrRenderAttrs(_mergeProps({
14+
_push(\`<div\${_ssrRenderAttrs(_mergeProps(_attrs, {
1515
style: (_ctx.foo) ? null : { display: "none" }
16-
}, _attrs))}></div>\`)
16+
}))}></div>\`)
1717
}"
1818
`)
1919
})
@@ -92,6 +92,24 @@ describe('ssr: v-show', () => {
9292
`)
9393
})
9494

95+
test('with style + display', () => {
96+
expect(compileWithWrapper(`<div v-show="foo" style="display:flex" />`).code)
97+
.toMatchInlineSnapshot(`
98+
"const { ssrRenderStyle: _ssrRenderStyle, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
99+
100+
return function ssrRender(_ctx, _push, _parent, _attrs) {
101+
_push(\`<div\${
102+
_ssrRenderAttrs(_attrs)
103+
}><div style="\${
104+
_ssrRenderStyle([
105+
{"display":"flex"},
106+
(_ctx.foo) ? null : { display: "none" }
107+
])
108+
}"></div></div>\`)
109+
}"
110+
`)
111+
})
112+
95113
test('with v-bind', () => {
96114
expect(
97115
compileWithWrapper(

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ export const ssrTransformElement: NodeTransform = (node, context) => {
8888
const hasCustomDir = node.props.some(
8989
p => p.type === NodeTypes.DIRECTIVE && !isBuiltInDirective(p.name),
9090
)
91+
92+
// v-show has a higher priority in ssr
93+
const vShowPropIndex = node.props.findIndex(
94+
i => i.type === NodeTypes.DIRECTIVE && i.name === 'show',
95+
)
96+
if (vShowPropIndex !== -1) {
97+
const vShowProp = node.props[vShowPropIndex]
98+
node.props.splice(vShowPropIndex, 1)
99+
node.props.push(vShowProp)
100+
}
101+
91102
const needMergeProps = hasDynamicVBind || hasCustomDir
92103
if (needMergeProps) {
93104
const { props, directives } = buildProps(

packages/reactivity/src/arrayInstrumentations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function iterator(
215215
iter._next = iter.next
216216
iter.next = () => {
217217
const result = iter._next()
218-
if (result.value) {
218+
if (!result.done) {
219219
result.value = wrapValue(result.value)
220220
}
221221
return result

packages/runtime-dom/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ import type { VModelDirective } from './directives/vModel'
3838
*
3939
* To enable proper types, add `"dom"` to `"lib"` in your `tsconfig.json`.
4040
*/
41-
type DomStub = {}
42-
type DomType<T> = typeof globalThis extends { window: unknown } ? T : DomStub
41+
type DomType<T> = typeof globalThis extends { window: unknown } ? T : never
4342

4443
declare module '@vue/reactivity' {
4544
export interface RefUnwrapBailTypes {

0 commit comments

Comments
 (0)