This repository was archived by the owner on Jul 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 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', () => {
6969 patchProp ( el , 'value' , null , symbol )
7070 expect ( el . value ) . toBe ( symbol . toString ( ) )
7171 } )
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+ } )
7291} )
Original file line number Diff line number Diff line change 22 NOOP ,
33 includeBooleanAttr ,
44 isSpecialBooleanAttr ,
5+ isSymbol ,
56 makeMap ,
67} from '@vue/shared'
78import {
@@ -37,7 +38,10 @@ export function patchAttr(
3738 el . removeAttribute ( key )
3839 } else {
3940 // 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+ )
4145 }
4246 }
4347}
You can’t perform that action at this time.
0 commit comments