Skip to content
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

DOM properties breaks in stringified nodes #1128

Closed
gzzhanghao opened this issue May 6, 2020 · 9 comments
Closed

DOM properties breaks in stringified nodes #1128

gzzhanghao opened this issue May 6, 2020 · 9 comments
Labels

Comments

@gzzhanghao
Copy link
Contributor

Version

v3.0.0-beta.9

Reproduction link

vue-next-template-explorer

Steps to reproduce

Set DOM properties in stringified nodes.

What is expected?

Set properties correctly.

What is actually happening?

Properties are treated as attribute.

@underfin
Copy link
Member

underfin commented May 6, 2020

I don't get the problem with you.Can you explain it detaily with this?I find nothing with problem after check the link you provider.

import { createVNode as _createVNode, createStaticVNode as _createStaticVNode, openBlock as _openBlock, createBlock as _createBlock } from "vue"

const _hoisted_1 = /*#__PURE__*/_createStaticVNode("<div><input type=\"checkbox\" indeterminate><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>")

export function render(_ctx, _cache) {
  return (_openBlock(), _createBlock("div", null, [
    _hoisted_1
  ]))
}

@gzzhanghao
Copy link
Contributor Author

@underfin The indeterminate property on the input element should be a DOM property, but it was set as an attribute here.

See: https://stackoverflow.com/q/9366087

@underfin
Copy link
Member

underfin commented May 6, 2020

Got it.The bahavior what <input type="checkbox" indeterminate/> is not support with browser.
You can use binding <input type="checkbox" :indeterminate="" /> to reslove this.

@posva
Copy link
Member

posva commented May 6, 2020

@gzzhanghao Please give more details next time you open an issue: be precise about what is expected and missing like the attribute name. without the second comment, it is very difficult to understand.

You are setting an HTML attribute, so it makes sense it is set as an attribute. Props are set as props when using v-bind so as @underfin suggested, use v-bind

@posva posva closed this as completed May 6, 2020
@yyx990803 yyx990803 reopened this May 6, 2020
@yyx990803
Copy link
Member

yyx990803 commented May 6, 2020

In Vue 3 the idea is Vue auto detects prop vs. attributes. I think there should be some intuition from the compiler to avoid stringifying nodes with prop-only bindings, even static.

@underfin
Copy link
Member

underfin commented May 6, 2020

it is better if it is possible stringfy other div node.

@gzzhanghao
Copy link
Contributor Author

@underfin @posva Sorry for the confusion. But the real problem here is that stringified node behaves differently with non-stringified one. It may cause confusion in development since the optimization happens automatically - things can break without any relevant update.

A possible solution is adding .prop modifier back, so we can inform the compiler that the node is not stringifiable.

BTW, :indeterminate="" compiles to invalid javascript:

_createBlock("input", { indeterminate:  }, null, 8 /* PROPS */, ["indeterminate"])

While :indeterminate works (with empty strings), it throws a compilation error:

// Vue template compilation error: v-bind is missing expression.(31)

_createBlock("input", { indeterminate: "" }, null, 8 /* PROPS */, ["indeterminate"])

@yyx990803
Copy link
Member

If binding as a prop it should be <input :indeterminate="true">

@gzzhanghao
Copy link
Contributor Author

gzzhanghao commented May 6, 2020

@yyx990803 Correct, but I think <input indeterminate> should work as well (just like <CustomComponent indeterminate />).

Meanwhile, I wonder if we should handle custom properties here, so we can put raw data objects on elements (source locations, for example).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants