-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Link editing: Account for link anchor no longer being present when generating unique link instance key #36357
Conversation
@@ -17,6 +17,9 @@ function getKey( _id ) { | |||
* @return {string} the unique key to use for this link control. | |||
*/ | |||
function useLinkInstanceKey( instance ) { | |||
if ( ! instance ) { |
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.
This can be null
or a anchorRef
. So we need to avoid the null case.
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.
Could we add a comment above to explicitly state that we're returning a undefined
here on purpose?
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.
Apologies @kevin940726, I just missed your comment here before I hit "merge". I was perhaps over-eager to get this fix in, in time for the 11.9 release!
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.
No worries 👍 , it's more like a nitpick anyway :).
Size Change: 0 B Total Size: 1.08 MB ℹ️ View Unchanged
|
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.
Thanks for fixing this up! I could reproduce the issue, and confirm that this PR resolves it. Let's merge this in so we can cherry pick it into the 11.9 release.
3399a71
to
a9cc4ff
Compare
I've just given this a rebase to get the tests passing. |
Cherry picked into the Gutenberg 11.9 release in: 3c11b5e |
Thanks @andrewserong (and @kevin940726!) 👏 |
Description
In #34742 we used the unique anchor reference of each link in rich text to force remount the Link UI when moving between links (see that PR for why this was done).
Unfortunately, I forgot to account for instances where the anchor has been removed. This caused a
null
value to be set as the key of aWeakMap
thus triggering a JS error.In such cases we should not attempt to generate a unique link key and instead should bale out of the function. This causes the
key
prop on<LinkControl>
to benull
and thus not be set.How has this been tested?
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).