Skip to content

Commit 5f70576

Browse files
committed
fix(runtime-vapor): handle vapor attrs fallthrough to vdom component
1 parent bb4ae25 commit 5f70576

File tree

4 files changed

+55
-25
lines changed

4 files changed

+55
-25
lines changed

packages/runtime-vapor/__tests__/componentAttrs.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,4 +445,33 @@ describe('attribute fallthrough', () => {
445445
// fn should be called once
446446
expect(fn).toHaveBeenCalledTimes(1)
447447
})
448+
449+
it('should fallthrough attrs to vdom child', () => {
450+
const VDomChild = defineComponent({
451+
setup() {
452+
return () => h('div')
453+
},
454+
})
455+
456+
const VaporChild = defineVaporComponent({
457+
setup() {
458+
return createComponent(
459+
VDomChild as any,
460+
{ foo: () => 'vapor foo' },
461+
null,
462+
true,
463+
)
464+
},
465+
})
466+
467+
const App = {
468+
setup() {
469+
return () => h(VaporChild as any, { foo: 'foo', bar: 'bar' })
470+
},
471+
}
472+
473+
const root = document.createElement('div')
474+
createApp(App).use(vaporInteropPlugin).mount(root)
475+
expect(root.innerHTML).toBe('<div foo="vapor foo" bar="bar"></div>')
476+
})
448477
})

packages/runtime-vapor/__tests__/componentSlots.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,11 @@ describe('component: slots', () => {
241241
}),
242242
).render()
243243

244-
expect(props).toEqual({ foo: 100, baz: 'qux' })
244+
// foo has higher priority than bindObj.foo
245+
expect(props).toEqual({ foo: 0, baz: 'qux' })
245246

246247
foo.value = 2
247248
await nextTick()
248-
expect(props).toEqual({ foo: 100, baz: 'qux' })
249-
250-
delete bindObj.value.foo
251-
await nextTick()
252249
expect(props).toEqual({ foo: 2, baz: 'qux' })
253250
})
254251

packages/runtime-vapor/src/component.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,6 @@ export function createComponent(
150150
resetInsertionState()
151151
}
152152

153-
// vdom interop enabled and component is not an explicit vapor component
154-
if (appContext.vapor && !component.__vapor) {
155-
const frag = appContext.vapor.vdomMount(
156-
component as any,
157-
rawProps,
158-
rawSlots,
159-
)
160-
if (!isHydrating && _insertionParent) {
161-
insert(frag, _insertionParent, _insertionAnchor)
162-
}
163-
return frag
164-
}
165-
166153
if (
167154
isSingleRoot &&
168155
component.inheritAttrs !== false &&
@@ -181,6 +168,19 @@ export function createComponent(
181168
}
182169
}
183170

171+
// vdom interop enabled and component is not an explicit vapor component
172+
if (appContext.vapor && !component.__vapor) {
173+
const frag = appContext.vapor.vdomMount(
174+
component as any,
175+
rawProps,
176+
rawSlots,
177+
)
178+
if (!isHydrating && _insertionParent) {
179+
insert(frag, _insertionParent, _insertionAnchor)
180+
}
181+
return frag
182+
}
183+
184184
const instance = new VaporComponentInstance(
185185
component,
186186
rawProps as RawProps,

packages/runtime-vapor/src/componentProps.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ export function getAttrFromRawProps(rawProps: RawProps, key: string): unknown {
178178
if (key === '$') return
179179
// need special merging behavior for class & style
180180
const merged = key === 'class' || key === 'style' ? ([] as any[]) : undefined
181+
182+
// rawProps has high priority
183+
if (hasOwn(rawProps, key)) {
184+
if (merged) {
185+
merged.push(rawProps[key]())
186+
} else {
187+
return rawProps[key]()
188+
}
189+
}
190+
181191
const dynamicSources = rawProps.$
182192
if (dynamicSources) {
183193
let i = dynamicSources.length
@@ -196,13 +206,7 @@ export function getAttrFromRawProps(rawProps: RawProps, key: string): unknown {
196206
}
197207
}
198208
}
199-
if (hasOwn(rawProps, key)) {
200-
if (merged) {
201-
merged.push(rawProps[key]())
202-
} else {
203-
return rawProps[key]()
204-
}
205-
}
209+
206210
if (merged && merged.length) {
207211
return merged
208212
}

0 commit comments

Comments
 (0)