File tree 2 files changed +33
-9
lines changed
2 files changed +33
-9
lines changed Original file line number Diff line number Diff line change @@ -198,6 +198,24 @@ describe('vnode', () => {
198
198
expect ( cloned2 ) . toEqual ( node2 )
199
199
expect ( cloneVNode ( node2 ) ) . toEqual ( node2 )
200
200
expect ( cloneVNode ( node2 ) ) . toEqual ( cloned2 )
201
+
202
+ // #1041 should use reoslved key/ref
203
+ expect ( cloneVNode ( createVNode ( 'div' , { key : 1 } ) ) . key ) . toBe ( 1 )
204
+ expect ( cloneVNode ( createVNode ( 'div' , { key : 1 } ) , { key : 2 } ) . key ) . toBe ( 2 )
205
+ expect ( cloneVNode ( createVNode ( 'div' ) , { key : 2 } ) . key ) . toBe ( 2 )
206
+
207
+ // ref normalizes to [currentRenderingInstance, ref]
208
+ expect ( cloneVNode ( createVNode ( 'div' , { ref : 'foo' } ) ) . ref ) . toEqual ( [
209
+ null ,
210
+ 'foo'
211
+ ] )
212
+ expect (
213
+ cloneVNode ( createVNode ( 'div' , { ref : 'foo' } ) , { ref : 'bar' } ) . ref
214
+ ) . toEqual ( [ null , 'bar' ] )
215
+ expect ( cloneVNode ( createVNode ( 'div' ) , { ref : 'bar' } ) . ref ) . toEqual ( [
216
+ null ,
217
+ 'bar'
218
+ ] )
201
219
} )
202
220
203
221
describe ( 'mergeProps' , ( ) => {
Original file line number Diff line number Diff line change @@ -312,9 +312,9 @@ function _createVNode(
312
312
_isVNode : true ,
313
313
type,
314
314
props,
315
- key : props && props . key !== undefined ? props . key : null ,
315
+ key : props && props . key != null ? props . key : null ,
316
316
ref :
317
- props && props . ref !== undefined
317
+ props && props . ref != null
318
318
? [ currentRenderingInstance ! , props . ref ]
319
319
: null ,
320
320
scopeId : currentScopeId ,
@@ -362,18 +362,24 @@ export function cloneVNode<T, U>(
362
362
vnode : VNode < T , U > ,
363
363
extraProps ?: Data & VNodeProps
364
364
) : VNode < T , U > {
365
+ const props = ( extraProps
366
+ ? vnode . props
367
+ ? mergeProps ( vnode . props , extraProps )
368
+ : extend ( { } , extraProps )
369
+ : vnode . props ) as any
365
370
// This is intentionally NOT using spread or extend to avoid the runtime
366
371
// key enumeration cost.
367
372
return {
368
373
_isVNode : true ,
369
374
type : vnode . type ,
370
- props : extraProps
371
- ? vnode . props
372
- ? mergeProps ( vnode . props , extraProps )
373
- : extend ( { } , extraProps )
374
- : vnode . props ,
375
- key : vnode . key ,
376
- ref : vnode . ref ,
375
+ props,
376
+ key : props && props . key != null ? props . key : null ,
377
+ ref :
378
+ props && props . ref != null
379
+ ? isArray ( props . ref )
380
+ ? props . ref
381
+ : [ currentRenderingInstance ! , props . ref ]
382
+ : null ,
377
383
scopeId : vnode . scopeId ,
378
384
children : vnode . children ,
379
385
target : vnode . target ,
You can’t perform that action at this time.
0 commit comments