fix: guard native inserter against non-string pattern categories#553
Open
dcalhoun wants to merge 1 commit into
Open
fix: guard native inserter against non-string pattern categories#553dcalhoun wants to merge 1 commit into
dcalhoun wants to merge 1 commit into
Conversation
XCFramework BuildThis PR's XCFramework is available for testing. Add the following to your .package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/553")Built from ab2865e |
dcalhoun
force-pushed
the
fix/native-inserter-non-string-pattern-categories
branch
from
July 16, 2026 18:18
ab93f03 to
78f21e1
Compare
`formatPatternsForNativeInserter` called `cat.startsWith( '_' )` on every entry of a pattern's `categories`, assuming each was a slug string. User/ synced patterns can momentarily expose raw numeric term IDs instead: while core-data resolves the id→slug lookup table, `mapUserPattern` in `@wordpress/block-editor` falls back to returning the raw `catId` (a number). Opening the native inserter during that resolver gap crashed with `TypeError: cat.startsWith is not a function` (JETPACK-IOS-1KAQ). Filter categories to strings before calling `startsWith`, and add a regression test covering numeric/null categories. Fixes JETPACK-IOS-1KAQ Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dcalhoun
force-pushed
the
fix/native-inserter-non-string-pattern-categories
branch
from
July 16, 2026 18:21
78f21e1 to
ab2865e
Compare
dcalhoun
marked this pull request as ready for review
July 16, 2026 18:44
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
Guard against a race condition whenever opening the native block inserter quickly after editor launch. Fixes #552. Fix CMM-2168.
Why?
The race condition led to an editor crash, forcing users to close and re-open the editor.
formatPatternsForNativeInsertercalledcat.startsWith( '_' )on every entry of a pattern'scategories, assuming each was a slug string. For user/synced patterns this assumption can briefly break whilemapUserPatternin@wordpress/block-editorbuildscategoriesby mapping each numericwp_pattern_categoryterm ID through the__experimentalUserPatternCategorieslookup table, falling back to the raw numeric ID when that table hasn't resolved yet.If the native inserter is opened during that gap, a category is still a number, and
number.startsWithisundefined→ crash (SentryJETPACK-IOS-1KAQ). Waiting a moment lets the lookup table resolve, which is why the crash is timing-dependent.How?
Filter
categoriesto strings before callingstartsWith. This ensures yet-to-be-resolved pattern entities with category ID numbers rather than string slugs are filtered out before performing string actions.Testing Instructions
pbpaste | git apply.git checkout HEAD~1 -- src/utils/blocks.js.git checkout HEAD -- src/utils/blocks.js.Reproduction diff
Accessibility Testing Instructions
N/A — no UI changes. This removes a crash on an existing flow.
Screenshots or screencast