Skip to content

Commit 40eb0d5

Browse files
committed
wip: save
1 parent bb08ce3 commit 40eb0d5

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

packages/runtime-core/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,7 @@ export { startMeasure, endMeasure } from './profiling'
557557
* @internal
558558
*/
559559
export { initFeatureFlags } from './featureFlags'
560+
/**
561+
* @internal
562+
*/
563+
export { createInternalObject } from './internalObject'

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import {
77
createApp,
8+
defineComponent,
89
h,
910
isEmitListener,
1011
nextTick,
@@ -455,4 +456,42 @@ describe('vdom interop', () => {
455456
// fn should be called once
456457
expect(fn).toHaveBeenCalledTimes(1)
457458
})
459+
460+
test('vapor parent > vdom child', () => {
461+
const VDomChild = defineComponent({
462+
emits: ['click'],
463+
setup(_, { emit }) {
464+
return () => h('button', { onClick: () => emit('click') }, 'click me')
465+
},
466+
})
467+
468+
const fn = vi.fn()
469+
const VaporChild = defineVaporComponent({
470+
emits: ['click'],
471+
setup() {
472+
return createComponent(
473+
VDomChild as any,
474+
{ onClick: () => fn },
475+
null,
476+
true,
477+
)
478+
},
479+
})
480+
481+
const App = {
482+
setup() {
483+
return () => h(VaporChild as any)
484+
},
485+
}
486+
487+
const root = document.createElement('div')
488+
createApp(App).use(vaporInteropPlugin).mount(root)
489+
490+
expect(root.innerHTML).toBe('<button>click me</button>')
491+
const button = root.querySelector('button')!
492+
button.dispatchEvent(new Event('click'))
493+
494+
// fn should be called once
495+
expect(fn).toHaveBeenCalledTimes(1)
496+
})
458497
})

packages/runtime-vapor/src/vdomInterop.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import {
99
type Slots,
1010
type VNode,
1111
type VaporInteropInterface,
12+
createInternalObject,
1213
createVNode,
1314
currentInstance,
1415
ensureRenderer,
16+
isEmitListener,
1517
onScopeDispose,
1618
renderSlot,
1719
shallowRef,
@@ -162,7 +164,14 @@ function createVDOMComponent(
162164
// overwrite how the vdom instance handles props
163165
vnode.vi = (instance: ComponentInternalInstance) => {
164166
instance.props = wrapper.props
165-
instance.attrs = wrapper.attrs
167+
168+
const attrs = (instance.attrs = createInternalObject())
169+
for (const key in wrapper.attrs) {
170+
if (!isEmitListener(instance.emitsOptions, key)) {
171+
attrs[key] = wrapper.attrs[key]
172+
}
173+
}
174+
166175
instance.slots =
167176
wrapper.slots === EMPTY_OBJ
168177
? EMPTY_OBJ

0 commit comments

Comments
 (0)