Skip to content

fix(runtime-dom): handle Symbol attributes #4964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/runtime-dom/__tests__/patchAttrs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ describe('runtime-dom: attrs patching', () => {
expect(el.getAttribute('foo')).toBe(null)
})

test('symbol attributes', () => {
const el = document.createElement('button')
patchProp(el, 'aria-label', null, Symbol('Close'))
expect(el.getAttribute('aria-label')).toBe('Symbol(Close)')
})

// #949
test('onxxx but non-listener attributes', () => {
const el = document.createElement('div')
Expand Down
8 changes: 7 additions & 1 deletion packages/runtime-dom/src/modules/attrs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
includeBooleanAttr,
isSpecialBooleanAttr,
isSymbol,
makeMap,
NOOP
} from '@vue/shared'
Expand Down Expand Up @@ -36,7 +37,12 @@ export function patchAttr(
if (value == null || (isBoolean && !includeBooleanAttr(value))) {
el.removeAttribute(key)
} else {
el.setAttribute(key, isBoolean ? '' : value)
// Symbols are explicitly stringified as the underlying library
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug only manifests when using shallowMount in Test Utils, which is implemented using transfromVNodeArgs. That function is behind a __DEV__ flag: https://github.com/vuejs/vue-next/blob/b4eb7e3866d7dc722d93a48f4faae1696d4e7023/packages/runtime-core/src/vnode.ts#L481

So we might want to put this check behind the same __DEV__ flag?

// does not handle them https://github.com/jsdom/webidl-conversions/issues/14
el.setAttribute(
key,
isBoolean ? '' : isSymbol(value) ? value.toString() : value
)
}
}
}
Expand Down