File tree Expand file tree Collapse file tree 3 files changed +61
-2
lines changed Expand file tree Collapse file tree 3 files changed +61
-2
lines changed Original file line number Diff line number Diff line change @@ -557,3 +557,7 @@ export { startMeasure, endMeasure } from './profiling'
557
557
* @internal
558
558
*/
559
559
export { initFeatureFlags } from './featureFlags'
560
+ /**
561
+ * @internal
562
+ */
563
+ export { createInternalObject } from './internalObject'
Original file line number Diff line number Diff line change 1
- import { type Ref , nextTick , ref } from '@vue/runtime-dom'
1
+ import {
2
+ type Ref ,
3
+ createApp ,
4
+ defineComponent ,
5
+ h ,
6
+ nextTick ,
7
+ ref ,
8
+ } from '@vue/runtime-dom'
2
9
import {
3
10
createComponent ,
4
11
defineVaporComponent ,
@@ -8,6 +15,7 @@ import {
8
15
setProp ,
9
16
setStyle ,
10
17
template ,
18
+ vaporInteropPlugin ,
11
19
} from '../src'
12
20
import { makeRender } from './_utils'
13
21
import { stringifyStyle } from '@vue/shared'
@@ -361,4 +369,42 @@ describe('attribute fallthrough', () => {
361
369
const el = host . children [ 0 ]
362
370
expect ( el . classList . length ) . toBe ( 0 )
363
371
} )
372
+
373
+ it ( 'should not fallthrough emit handlers to vdom child' , ( ) => {
374
+ const VDomChild = defineComponent ( {
375
+ emits : [ 'click' ] ,
376
+ setup ( _ , { emit } ) {
377
+ return ( ) => h ( 'button' , { onClick : ( ) => emit ( 'click' ) } , 'click me' )
378
+ } ,
379
+ } )
380
+
381
+ const fn = vi . fn ( )
382
+ const VaporChild = defineVaporComponent ( {
383
+ emits : [ 'click' ] ,
384
+ setup ( ) {
385
+ return createComponent (
386
+ VDomChild as any ,
387
+ { onClick : ( ) => fn } ,
388
+ null ,
389
+ true ,
390
+ )
391
+ } ,
392
+ } )
393
+
394
+ const App = {
395
+ setup ( ) {
396
+ return ( ) => h ( VaporChild as any )
397
+ } ,
398
+ }
399
+
400
+ const root = document . createElement ( 'div' )
401
+ createApp ( App ) . use ( vaporInteropPlugin ) . mount ( root )
402
+
403
+ expect ( root . innerHTML ) . toBe ( '<button>click me</button>' )
404
+ const button = root . querySelector ( 'button' ) !
405
+ button . dispatchEvent ( new Event ( 'click' ) )
406
+
407
+ // fn should be called once
408
+ expect ( fn ) . toHaveBeenCalledTimes ( 1 )
409
+ } )
364
410
} )
Original file line number Diff line number Diff line change @@ -9,9 +9,11 @@ import {
9
9
type Slots ,
10
10
type VNode ,
11
11
type VaporInteropInterface ,
12
+ createInternalObject ,
12
13
createVNode ,
13
14
currentInstance ,
14
15
ensureRenderer ,
16
+ isEmitListener ,
15
17
onScopeDispose ,
16
18
renderSlot ,
17
19
shallowRef ,
@@ -162,7 +164,14 @@ function createVDOMComponent(
162
164
// overwrite how the vdom instance handles props
163
165
vnode . vi = ( instance : ComponentInternalInstance ) => {
164
166
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
+
166
175
instance . slots =
167
176
wrapper . slots === EMPTY_OBJ
168
177
? EMPTY_OBJ
You can’t perform that action at this time.
0 commit comments