File tree 2 files changed +24
-1
lines changed
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -69,4 +69,23 @@ describe('runtime-dom: attrs patching', () => {
69
69
patchProp ( el , 'value' , null , symbol )
70
70
expect ( el . value ) . toBe ( symbol . toString ( ) )
71
71
} )
72
+
73
+ // #11177
74
+ test ( 'should allow setting value to object, leaving stringification to the element/browser' , ( ) => {
75
+ // normal behavior
76
+ const el = document . createElement ( 'div' )
77
+ const obj = { toString : ( ) => 'foo' }
78
+ patchProp ( el , 'data-test' , null , obj )
79
+ expect ( el . dataset . test ) . toBe ( 'foo' )
80
+
81
+ const el2 = document . createElement ( 'div' )
82
+ let testvalue : null | typeof obj = null
83
+ // simulating a web component that implements its own setAttribute handler
84
+ el2 . setAttribute = ( name , value ) => {
85
+ testvalue = value
86
+ }
87
+ patchProp ( el2 , 'data-test' , null , obj )
88
+ expect ( el2 . dataset . test ) . toBe ( undefined )
89
+ expect ( testvalue ) . toBe ( obj )
90
+ } )
72
91
} )
Original file line number Diff line number Diff line change 2
2
NOOP ,
3
3
includeBooleanAttr ,
4
4
isSpecialBooleanAttr ,
5
+ isSymbol ,
5
6
makeMap ,
6
7
} from '@vue/shared'
7
8
import {
@@ -37,7 +38,10 @@ export function patchAttr(
37
38
el . removeAttribute ( key )
38
39
} else {
39
40
// attribute value is a string https://html.spec.whatwg.org/multipage/dom.html#attributes
40
- el . setAttribute ( key , isBoolean ? '' : String ( value ) )
41
+ el . setAttribute (
42
+ key ,
43
+ isBoolean ? '' : isSymbol ( value ) ? String ( value ) : value ,
44
+ )
41
45
}
42
46
}
43
47
}
You can’t perform that action at this time.
0 commit comments