This repository was archived by the owner on Jul 28, 2023. It is now read-only.
Create constants file for wp- prefixes#142
Merged
DAreRodz merged 1 commit intomain-wp-directives-pluginfrom Feb 2, 2023
Merged
Create constants file for wp- prefixes#142DAreRodz merged 1 commit intomain-wp-directives-pluginfrom
wp- prefixes#142DAreRodz merged 1 commit intomain-wp-directives-pluginfrom
Conversation
DAreRodz
commented
Jan 27, 2023
| const n = attributes[i].name; | ||
| if (n[0] === 'w' && n[1] === 'p' && n[2] === '-' && n[3]) { | ||
| if (n === 'wp-ignore') { | ||
| if (n[p.length] && n.slice(0, p.length) === p) { |
Collaborator
Author
There was a problem hiding this comment.
I've changed how we check the attribute prefix. It turns out that using String.prototype.slice is much faster than the other approaches we tested a while ago.
The previous method that checked fixed positions is ~72% slower than the current one using slice. 😄
This was referenced Jan 27, 2023
ockham
approved these changes
Feb 1, 2023
Collaborator
ockham
left a comment
There was a problem hiding this comment.
Code LGTM 👍 (I wasn't quite sure how to test though -- I take it we have some e2e coverage?)
Collaborator
Author
We have e2e tests for full vDOM hydration, islands, and some directives. If none of them has broken, I guess these changes work. 🤞 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What
Move all
wp-prefixes (or strings containing any of them) to a constants file.Why
To make it easier to change them if necessary (e.g.,
directivePrefixtodata-wp-).How
Creating a
constants.jsfile.https://github.com/WordPress/block-hydration-experiments/blob/4990097fef3f3c674eee195a3ea4bb2fd460c7cd/src/runtime/constants.js#L1-L3
I defined separated prefixes for components and directives, just in case we finally go for HTML-compliant directives (i.e., using custom data attributes).