-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
FlatTermSelector: Be more defensive about termIds #63461
Conversation
It's possible (likely through a bug elsehwere) for FlatTermSelector to completely crash the editor if it can't get termIds from the post being edited. This change prevents that crash. The error can happen when <FlatTermSelector> tries to access _termIds.join and _termIds.length even when _termIds is undefined. This is undefined if the current editor state doesn't have any changed for the relevent attribute [0] and the original post doesn't have the relevent attribute [1]. [0] https://github.com/WordPress/gutenberg/blob/4da057ecd6958d40b8f2a83db1152320e5f161e6/packages/editor/src/store/selectors.js#L329 [1] https://github.com/WordPress/gutenberg/blob/4da057ecd6958d40b8f2a83db1152320e5f161e6/packages/editor/src/store/selectors.js#L276
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. |
Size Change: +1 B (0%) Total Size: 1.75 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.
Thank you, @dsas!
The missing termIds
is probably caused by bug somewhere else, but extra hardening won't hurt.
Co-authored-by: dsas <dsas@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
What?
Be more defensive against bad data in
<FlatTermSelector>
that could cause a crash.Why?
It's possible (likely through a bug elsewhere) for
<FlatTermSelector>
to completely crash the editor if it can't gettermIds
from the post being edited. This change prevents that crash.The error can happen when
<FlatTermSelector>
tries to access_termIds.join
and_termIds.length
even when_termIds
is undefined. This is undefined if the current editor state doesn't have any changes for the relevant attribute and the original post doesn't have the relevant attribute. This shouldn't be possible normally.How?
Use the optional chaining operator.
Testing Instructions
It's difficult to construct an artificial test case, but on the happy path then nothing should change at all, using the post tags in the sidebar when editing a post should continue to work exactly as it does now.