Repository navigation
RichText: separate fallback instance ID for selection retrieval - #60277
Conversation
|
Size Change: -1.6 kB (0%) Total Size: 1.72 MB
ℹ️ View Unchanged
|
| selectionEnd.clientId === clientId && | ||
| selectionStart.attributeKey === identifier; | ||
| ( selectionStart.attributeKey === identifier || | ||
| selectionStart[ instanceIdKey ] === instanceId ); |
There was a problem hiding this comment.
This condition should also check for undefined attributeKey/undefined. If a block has two RichText components without an identifier, with different instance IDs, the condition will say that both are selected, because undefined === undefined. But only the one with matching instance ID should be selected.
There was a problem hiding this comment.
Right. Maybe we should just check the instance id here anyway?
There was a problem hiding this comment.
Like, using && instead of ||? That works, but I would personally prefer if instanceId was just a fallback for missing identifier. If identifier is there, it identifies the attribute with 100% precision and instanceId doesn't need to exist.
There was a problem hiding this comment.
Actually we better not do that because you might want to set selection with just the attribute keys. So this is only for back compat.
| selection.start = { | ||
| clientId, | ||
| attributeKey: identifier, | ||
| [ instanceIdKey ]: instanceId, |
There was a problem hiding this comment.
If there is a valid identifier, the instanceId is redundant. It's better to always set only one of them, not both.
There was a problem hiding this comment.
const [ idKey, idValue ] = identifier
? [ 'attributeKey', identifier ]
: [ instanceIdKey, instanceId ];
selection.start = {
[ idKey ]: idValue
}|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
…Press#60277) Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
What?
When a RichText instance does not have an
identifierprop defined (block attribute key), RichText falls back to an instance ID to set and retrieve selection to/from the store. This PR separates the instance ID to a private key, so that it's not accidentally used as an attribute key.For a long term solution, we should probably consider requiring the identifier props, maybe while also removing passing the attributes to RichText so it works more like InnerBlocks? Not sure.
Why?
Currently we set invalid attribute keys.
How?
Testing Instructions
E2e tests should pass.
Testing Instructions for Keyboard
Screenshots or screencast