-
Notifications
You must be signed in to change notification settings - Fork 11
Automatically detect if a block is using directives #126
Comments
wp-island
functionality
Actually, there are two functionalities related to this:
@ockham, @dmsnell: Let's discuss what mechanisms we can use for each of them 🙂 Maybe it's worth noting that both of them are optional, as we can always ask the developer to give that information to us. But the more we absorb, the better DX. |
Based on my experiments, I'm expecting that we'll have a loop iterating over all HTML tags in a given block, which will be looking for I was thinking to add logic to enqueue the relevant JS file(s) based on this, since it seemed like the most straight-forward way 😄 |
Given the cost of scanning HTML on every page render, it's likely that any solution will use more than one stage of detection: is it possible that this block contains directives? does this block contain directives? So maybe a quick scan with a naive search, e.g. Regarding attribute directives I'll repeat here that one thing we might consider is trying to add some known activator to indicate that a given tag has directives attached to it. Something like Far less a problem in client code where computation is spread out, the server is doing this processing for every page it hands out and any and all mechanisms to find directives is going to add its cost, but that's something to consider and acknowledge, not something that's a show-stopper. |
I was thinking about that, but block class names start with
At what part of the system do you envision those activators added? Are they delegated to the developer or added automatically at some point? |
This is a side-effect of using same prefix. I don't have estimates to quantify performance impacts so we just need to get testing with some realistic code and see what magnitude we're discussing. An attribute like Also I didn't mean to be overly prescriptive in how a first-pass would be performed, only wanted to note that some kind of pass would likely be important given that we currently aren't talking about having any particular kind of thing we can use to narrow our search. Unfortunately working to try and remove the
My first thought was that developers could add them as an opt-in (or if they use React components those directive components could add them). That's probably not a good idea because people wouldn't always do it. We could try and add them automatically somehow, as a cache would work, or store them in the block JSON attributes on save. This could mess with folks in unexpected ways (broken editor, unexpected attributes, attribute name collisions), but it would leave these flags out of the HTML. |
Another option would be to use a different prefix to avoid collisions. Like This idea aligns better if we end up referring to this as a framework rather than just an API, an idea we are still tinkering with. The name of that prefix could match the framework's name (or its acronym). |
If we finally decide to propose Discussion: #132 |
Meant to come in and say I like the use of It wasn't clear to me that adding custom attributes is a violation, but after some searching I found the violation stated clearly with an example.
with the purpose of this rule
Still, it's one line in the spec and support is wide around the web for random attributes. I've noticed that while browsers tend to not allow setting arbitrary attribute names via I don't think using something like |
it seems to me that |
I guess my mind wants to avoid any unnecessary boilerplate, even a five characters-long string like
Yeah, I guess you're probably right. And convincing the WordPress community to go against the spec seems like a difficult task. I've mentioned your opinion in the other issue as well. Thanks for your input, Dennis! |
It's okay. What your feeling is valid, but we must untrain our intuitions and learn to focus on the important things that matter 😄
I think the spec issue is probably overblown wording it this way. There's likely no system in the world that would break by adding custom attributes without the Where I'd frame it is more like, given that both choices would work out, knowing that I think most libraries here violate the spec because prefer seeing So ultimately the choice is likely best made on other reasons than the spec; whereas the spec can be seen as a tie-breaker or a subtle nudge one way or the other. |
Now that the directives use the I'm going to close this conversation now. The task has been added to the new roadmap, and we'll open a new issue or discussion in Gutenberg once we need to start discussing its implications. |
As mentioned by @SantosGuillamot here, we could Automatically detect if a block is using directives and add the
wp-island
functionality without forcing block developers to manually declare it in theirblock.json
file.The text was updated successfully, but these errors were encountered: