Skip to content

Commit

Permalink
FlatTermSelector: Be more defensive about termIds
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dsas committed Jul 11, 2024
1 parent e5030c6 commit a4cb0b7
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function FlatTermSelector( { slug } ) {

const query = {
...DEFAULT_QUERY,
include: _termIds.join( ',' ),
include: _termIds?.join( ',' ),
per_page: -1,
};

Expand All @@ -103,7 +103,7 @@ export function FlatTermSelector( { slug } ) {
: false,
taxonomy: _taxonomy,
termIds: _termIds,
terms: _termIds.length
terms: _termIds?.length
? getEntityRecords( 'taxonomy', slug, query )
: EMPTY_ARRAY,
hasResolvedTerms: hasFinishedResolution( 'getEntityRecords', [
Expand Down

0 comments on commit a4cb0b7

Please sign in to comment.