Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Change
html-macro
'schecked
attribute to specify checkedness #206Change
html-macro
'schecked
attribute to specify checkedness #206Changes from 4 commits
5ab4fdd
eccdd56
702a494
9739e77
a6c9e2a
8e08e79
6253741
8e11bbe
7099525
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I'm having doubts that this was the right direction. Why would anyone ever use
percy-dom
for server-side rendering? The server shouldn't be manipulating a DOM server-side. That should be actively discouraged, right?Therefore
percy-dom
has no reason to be overriding the default checkedness except to matchvirtual-node
's behavior, but why should it? They're doing two different things. One is encoding a virtual node tree as HTML, the other is creating, diffing, and patching DOM nodes based on two different virtual node trees.At this point, this example seems like a whole lot of faffing because we're doing the wrong thing.
Proposal:
percy-dom
is not for server-side rendering.percy-dom
explicitly do what makes sense for the context of the browser:checked
manipulates theHTMLInputElement.checked
property - it doesn't mess around with default checkedness as there's no reason to do so. People writing typical/idiomaticpercy
apps should never need to worry about it. And if for some reason they do, they shouldn't have to work around this strange behavior.What we gain from keeping this behavior:
percy-dom
maintains closer HTML in the browser as it does to if you were to callvirtual_node.to_string()
(I don't see why this is useful, and can't think of a way this would cause issues. Can you?)What is gained from tossing this behavior:
percy-dom
does to default checkedness: nothing.percy-dom
can avoid dealing with default checkedness entirely, as it's not useful for application-state-driven GUIs (which should always specify checkedness according to app state).percy-dom
doesn't have an expectation of being used for something it shouldn't be used for.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.
I don't remember where I wrote that quote, so I don't understand what you're referring to.
A DOM does require on the browser in any way. We should not couple these unrelated concepts.
Whether
percy
can manipulate a DOM should never depend on whether it is running in a browser.I'll name some reasons:
testing. It is an eventual goal that to be able to test the vast majority of your
percy
application outside of a browser. So, instead of usingweb-sys
, we would usegeneric-dom-traits
that usedweb-sys
in a browser andsomething else outside of the browser.
This would enable fast testing of things like "what happens when we click on this element but the onclick handler calls
event.prevent_default()
".For instance, we might use in-process-memory DOM implementation that was reliable enough that you trusted the results, and fast enough that one wouldn't hesitate to write as many test cases as they wanted
simulation / benchmarking / etc
It comes down to the framing. You're framing it as being about "default checkedness".
In that context, yes we currently have no reason to believe that we need
percy-dom
to do anything to the "default checkedness".However, if this is framed around "setting the checked attribute" and "the user thinks that they're setting the checked attribute", then that changes things.
So, the question becomes, would a user ever want to set the "checked" attribute?
If
<input foo="bar" />
sets thefoo
attribute, a user might expect<input checked=true />
to set the "checked" attribute.If we pointed the user at an application and asked "what do you think happens when we render
<input checked=true />
they should probably say "The checked attribute gets set".In practice this would only impact the user if they were doing
input.getAttribute('checked')
and got backnull
instead of"true"
.It's entirely possible that roughly 0 people will ever do this.
And, if they do, they can open an issue and we can do further design work.
So, I'm okay with, for now, having
percy-dom
only control thechecked
property, and not thechecked
attribute.Proposal
Don't do this. Instead, we can say that if a user truly wants to set the "checked" attribute they can use
.setAttribute
on the node themselves https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute .Sounds good.
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.
Neat.
I'll delete the example as it's no longer illustrative of doing something reasonable. If users want to set the default checkedness of an element, they should just get the DOM element and add/remove the attribute. It can be grabbed from the commit history if its useful later?
It's also worth mentioning that the situation with
value
is exactly the same as withchecked
, and having different behavior for them would be strange, at least long-term. If nothing explodes by releasing this change out into the wild, I think changing howpercy-dom
treatsvalue
should be changed to matchchecked
. For now, the book entries reflect the difference.I will leave it out. It was only in service of motivating the
checked
VDOM attribute behavior.It's unfortunate.
checked
HTML attribute should be calleddefaultChecked
or something to distinguish it.html!
with a HTML-like format to manipulate a DOM. It's misleading because an HTML document and a DOM have aliased but distinct concepts, such as thechecked
attribute and thechecked
property. ...It's a small enough issue that the choice might be worth the benefit of the intuitive markup.Unless we remove the
checked
attribute frompercy
(and use something likeis_checked
anddefault_checked
just to make it harder to assume what they mean) I think we're going to need to bite the bullet that devs will sometimes assume thatpercy-dom
does the wrong thing - with respect topercy
's intended utility.But at least
percy-dom
will be doing the sensible thing (as far as we can tell, at least), so it's "just" a learning speed bump. At leastpercy
isn't hard to use once the dev (hopefully) reads the book section to figure out what's going on.Some leftover thoughts:
I agree. We're talking past each other though. I don't think this is relevant to what I'm proposing.
Testing, simulation, benchmarking, etc. in environments without a browser seem neat. I just don't see what this has to do with server-side rendering though.
Server-side rendering is: generating a static HTML document and sending it off to the client. Manipulating a DOM is not useful in this process. Manipulating a virtual DOM is useful. But
percy
already has a distinction betweenvirtual-node
+html-macro
andpercy-dom
such that manipulating a virtual DOM server-side to generate HTML has no dependency on the idea of actually manipulating a real or simulated or mocked DOM.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.
Unless it would be hard, let's just change it to be a
embed-non-percy-node
example where we show you how to create your own node thatpercy
doesn't touch.Can just delete all of the checkedness stuff and instead just make the example create a
<div hello="world" />
or something usingweb-sys
and insert that intoa percy contain
.on_create_element
.Sounds good.
html!
macro is describing the DOM that you want.Then
percy-dom
manipulates it.The macro isn't manipulating the DOM, just declaring one.
So, it's designed to stay close to how a user would expect to be able to declare a DOM tree. Since HTML is likely the most common way to way to define a DOM tree, it's designed to feel like HTML.
This lets users avoid learning percy and instead just learn common specs/concepts. Transferable knowledge.
rough idea
I could see a potential future (would require design work) where the
html!
macro gave a compile time error if you usedchecked
.It would tell you to use
is_checked
or how to set the attribute if you really wanted to do that.That wouldn't help users that use
VirtualNode
directly, however.Yeah, especially if the macro compile time error points you to the docs.
Yeah I only realized that after I continued reading your comment
Here's what I had in mind:
user starts some sort of simulation application where they are running their percy application in an emulated browser
users triggers a bunch of clicks / input events / etc
user now wants to take the DOM tree from that emulated browser and turn it into a string
If you're really on default checkedness that DOM tree will be different from your virtual tree. Your virtual tree doesn't know whether the element is checked. Only the emulated DOM has info about whether the input is checked.
I haven't thought enough about this to know if it relates to our convo, so I'm more so communicating that I'm not certain that we should operate as if server-side rendering of a "real DOM" will never be useful.