-
-
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
Implement dynamic tags #1266
Implement dynamic tags #1266
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments myself to clarify / justify some of my decisions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Looks like this opens up a few questions about how to handle certain macro checks like value
handling and void elements. I don't think they are blockers but I think we should have a plan for them to reduce surprising results when devs use dynamic tags
The scope of this PR just got a fair bit broader. I hope you don't mind 😅 |
@jstarry I think at this point it makes sense to add a few tests to check the runtime behaviour of dynamic tags (tags are actually present, void elements, and value attribute handling). |
@siku2 right now the vtag integration tests are all in |
Don't mind if you don't mind haha. Sometimes it's fun when PR's uncover other things that can be fixed up! |
Alright, I added some tests and also some runtime checks which make sure that dynamic tags uphold the same invariants as the literal ones. There are now 2 cases where a dynamic tag will panic:
This is done essentially the same way as the compile checks, just at runtime. I'm not a huge fan of the hardcoded tag names especially because they're in two places now but so far no better solution has come to mind.
I also noticed that my runtime checks break when the tag names aren't lowercased. So I made sure that the names are converted. But this got me thinking: "what about the literal case?" and sure enough we can break the compile-time checks by doing something like this: html! {
<bR>
<span>{ "haha, void element go brrrrr" }</span>
</bR>
} I assumed that |
By only running it for web-sys. I know, I know. But seriously, stdweb doesn't seem to have a way to get Element.tagName...
I think I just opened another can of worms... Currently neither literal nor dynamic tags support this entire range. I 'reverted' f37ebd3#diff-66b9cb4f2a74cf8a59ae2ccb91775f3aR115 for now so dynamic tags support the same characters as literals. |
Sounds good to me, I doubt this change would bite anyone and it also helps enforce our compile checks in the macro! So we have a triple standard now:
Each approach is handled a bit differently. Maybe we could encode this more explicitly by adding a runtime check flag to tag elements? I think your implementation is great for now, but I do think Yew should strive for reducing surprises in the development process as much as possible. Do you mind writing up an issue for the slight disparities between the 3 approaches I listed above? |
That's exactly what I was thinking.
Hard agree on this too 👍
Will do! That way I can take a bit of a break and get back to this if someone else hasn't already done it. I'll just add the lowercase check for the literal case and then I think this PR is just about ready to go. |
Just realised it can't be a compile error because there are tags like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point. Your code looks great, thanks for the rigor on this!!
Description
Provides an implementation of dynamic tags.
Fixes #1049
Checklist:
./ci/run_stable_checks.sh