-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix MDN reference for kind attribute #1298
Conversation
The Here's the relevant code that uses the yew/yew/src/virtual_dom/vtag.rs Lines 296 to 311 in cdded9a
I think "kind" is used because of |
@siku2 just found out while looking through tests |
This is mentioned 2-3 times /// ... We use workarounds for:
/// `type/kind`, `value` and `checked`. I searched a while but wasn't able to figure out what exactly these workarounds are. |
@zoechi, I think that could be made a bit clearer too... yew/yew/src/virtual_dom/vtag.rs Lines 40 to 69 in cdded9a
These attributes require special handling so they're stored outside of the |
I was searching for an explanation why these properties require special handling |
Oh right, sorry. I misunderstood. The documentation for
There is a difference between the HTML attribute As for yew/yew/src/virtual_dom/vtag.rs Lines 60 to 62 in cdded9a
It's basically the same reason as for value .
I don't actually know why |
Maybe this should go in the module/crate documentation (just once, rather than many times). |
@siku2 I'm not able to make progress here, but I think that it would be great to have this properly solved and documented and if there is special behavior that also properly tested. In
How could I (referring to "I interpret" from the quote above) deviate from the default browser behavior when all virtual_dom does is to pass HTML which is then interpreted by the browser.
Perhaps I'm missing something here but all virtual_dom does is generating HTML which only deals with attributes (not properties). So all special behavior I can find here is that What I can imagine this all referring to is virtual_dom reading from the DOM when diffing, but I wasn't yet able to find out if and where this could happen. |
Yew's yew/yew/src/virtual_dom/vtag.rs Lines 252 to 269 in cdded9a
Notice how it uses the following bit of code to set an attribute: element
.set_attribute(&key, &value)
.expect("invalid attribute key"); "element" here refers to the actual Everything in the When looking at the code watch out for the following:
|
@siku2 thanks a lot. I now understand much better what's going on. To me it now looks like ( If it's a
So the actual "workarounds" are mostly about how these methods in For a consumer of Yew this is only relevant when the imperative Would it make sense to add assertions in |
When you say "assertions" do you mean using the |
Actually, I don't know yet what ways Rust offers for that. What I meant is something that warns or panics perhaps only in development to not pay the performance cost in production. So according to https://doc.rust-lang.org/std/macro.assert.html probably |
My feeling is that we could leverage the type system to achieve this. This means you get compile-time errors instead of runtime errors. |
That's correct, yes. As a side note, these methods
I'm definitely in favour of something like that. @teymour-aldridge, I don't think we should use |
@siku2 I agree that we don't want anything panicing here! |
I think we could have an enum containing attributes. enum Attribute {
SomethingValid(<value>),
<... so on so forth>
CustomAttribute(String, String)
} |
Something like that. |
Also I think it's important to add that there should be a hidden implementation that doesn't do any of this for the macro. We don't need the performance penalty there since we can already do the sorting at compile time. |
@teymour-aldridge the user could still do |
If it can properly be solved using the type system, I'm all for it. |
@zoechi I think the performance penalty of something like this is negligible: pub fn add_attribute<T: ToString>(&mut self, name: &str, value: &T) {
match name {
"value" => self.set_value(value),
"kind" => self.set_kind(value),
_ => self.attributes.insert(name.to_owned(), value.to_string()),
}
} I'm not absolutely certain about this but I think Rust is able to remove the match entirely for the very common case where name is a literal. I'm all for using Rust's type system but I don't see how it could be used here without making the API awkward to use. |
@siku2 I think you're right. Looks simple enough, even with an additional check if it's an |
I was wondering about
Are there any plans to add |
@zoechi That's actually a really good idea. What would be a good use case for this though? Yew already has other means of accessing elements (using |
Most properties reflect to attributes. There are some exceptions. The main difference I'm aware of is that properties take/provide values in proper types (string, number, bool, object) while attributes only support string. I'll sleep it over and hope to be wiser tomorrow about the consequences/advantages this could have for Yew. |
I think this conversation is great, I would love if we had more clarity on how Yew handles attributes vs properties. @zoechi do you mind writing up a new issue for this? As for this PR, I'm in favour of removing the "kind" alias for input "type". It's confusing and non-standard. |
@jstarry Sure, I'll summarize in a new issue. |
I'm going to close this PR and create an issue instead. |
Cool. |
Description
Just a code comment fix.
I think this is a copy-paste error and instead of
InputElement
it should beTextTrack
because that's the only reference for a
kind
attribute I could find in MDNFixes # (issue)
Checklist:
./ci/run_stable_checks.sh