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

Conversation

cexbrayat
Copy link
Member

Currently, passing a Symbol to an attribute throws in runtime-dom with:

TypeError: Failed to execute 'setAttribute' on 'Element': parameter 2 is a symbol, which cannot be converted to a string.

This is because the underlying library used for conversion does not handle Symbol (see jsdom/webidl-conversions#14).

This issue cascades into VTU-next as shallowMount attempts to write props values as attributes.
See vuejs/test-utils#1076 for more context.

Currently, passing a `Symbol` to an attribute throws in `runtime-dom` with:

```
TypeError: Failed to execute 'setAttribute' on 'Element': parameter 2 is a symbol, which cannot be converted to a string.
```

This is because the underlying library used for conversion does not handle Symbol (see jsdom/webidl-conversions#14).

This issue cascades into VTU-next as `shallowMount` attempts to write props values as attributes.
See vuejs/test-utils#1076 for more context.
@@ -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?

@yyx990803
Copy link
Member

But why are we passing Symbols as attribute values in the first place?

@cexbrayat
Copy link
Member Author

This was spotted in VTU, as props are rendered as attributes when using shallow mount. We can work around it in VTU, but I was wondering if the cleanest way was not to fix it in core.

@lmiller1990
Copy link
Member

lmiller1990 commented Nov 29, 2021

Since this is a VTU shallowMount specific feature, I have no real problem patching it there instead (bit hacky, but shallowMount in general is quite a hack).

Either way, let's make a decision so we can unblock the people wanting to update their Ionic version see here for more.

@yyx990803
Copy link
Member

I think we should patch it in VTU then, since this doesn't really make sense in normal applications.

@yyx990803 yyx990803 closed this Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants