Skip to content

Navigation: Use areInnerBlocksControlled to detect controlled inner blocks - #87096

Merged
mikachan merged 5 commits into
trunkfrom
update/navigation-are-inner-blocks-controlled
Nov 19, 2026
Merged

mikachan merged 5 commits into
trunkfrom
update/navigation-are-inner-blocks-controlled

Conversation

@mikachan

Copy link
Copy Markdown
Member

What?

Fixes #46265

The Navigation block's useInnerBlocks hook now uses the areInnerBlocksControlled selector to tell whether its inner blocks are controlled.

Why?

The hook relied on a quirk: getBlock() leaves out a controller's inner blocks, while getBlocks() includes them. The getBlock docs now warn against relying on that and point to areInnerBlocksControlled.

How?

  • Read the inner blocks once with getBlocks( clientId ) and split them into controlled and uncontrolled with areInnerBlocksControlled( clientId ). The hook returns the same values as before, so edit/index.jsx is unchanged.
  • Convert the hook to TypeScript and add unit tests for empty, uncontrolled and controlled inner blocks.

Testing Instructions

  1. In a post, open the Code editor and paste a Navigation block with inner blocks and no ref, for example:
    <!-- wp:navigation --><!-- wp:navigation-link {"label":"Home","url":"/"} /--><!-- /wp:navigation -->
  2. Switch back to the Visual editor. The block should render its link as an unsaved menu.
  3. Edit the link. A new Navigation menu should be created and the block should switch to it.
  4. Insert another Navigation block and choose an existing menu. Check that its items render and can be edited.
  5. Add a submenu or a Page List with child pages. Check that the submenu settings in the block's settings sidebar still appear.

Unit tests: npm run test:unit -- packages/block-library/src/navigatocks.jsdom.test.tsx

🤖 Generated with help from Claude Code, reviewed by me.

@mikachan mikachan added [Type] Code Quality Issues or PRs that relate to code quality [Block] Navigation Affects the Navigation Block labels Nov 19, 2026
@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: -19 B (0%)

Total Size: 8.68 MB

📦 View Changed
Filename Size Change
build/scripts/block-library/index.min.js 427 kB -19 B (0%)

e8b0130 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 83944d1 trunk % Change
timeToFirstByte 45.35 ms +11.14% -5.84% 43.95 ms +7.96% -3.64% 3.19%
largestContentfulPaint 72 ms +5.56% -5.56% 70 ms +5.71% -2.86% 2.86%
lcpMinusTtfb 25.6 ms +14.06% -3.52% 24.2 ms +8.88% -6.2% 5.79%
wpBeforeTemplate 23.42 ms +18.02% -6.4% 23.01 ms +12.78% -3.87% 1.78%
wpTemplate 18.06 ms +5.48% -5.92% 17.71 ms +4.29% -5.93% 1.98%
wpTotal 42.02 ms +11.61% -6.85% 40.56 ms +8.41% -3.5% 3.6%
wpMemoryUsage 7.75 MB +0% -0% 7.71 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 83944d1 trunk % Change
timeToFirstByte 36.1 ms +7.62% -1.8% 37.85 ms +5.15% -7.27% -4.62%
largestContentfulPaint 68 ms +0% -5.88% 68 ms +0% -5.88% 0%
lcpMinusTtfb 30.3 ms +6.93% -5.28% 29.3 ms +2.9% -1.88% 3.41%
wpBeforeTemplate 19.65 ms +7.63% -2.09% 20.34 ms +5.8% -4.03% -3.39%
wpTemplate 13.7 ms +1.75% -4.09% 13.68 ms +5.77% -4.31% 0.15%
wpTotal 33.17 ms +8.35% -1.72% 34.99 ms +5.6% -7.97% -5.2%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 83944d1 trunk % Change
mediaProcessingJpeg 332.13 ms +0.49% -1.41% 326.07 ms +0.99% -0.2% 1.86%
mediaProcessingAvif 4885.33 ms +0.07% -0.31% 4883.42 ms +0.27% -0.13% 0.04%
mediaProcessingJpegToAvif 3420.12 ms +0.21% -0.18% 3387.04 ms +0.46% -0.09% 0.98%

media-upload

Metric 83944d1 trunk % Change
jpegUploadProcessing 1466.83 ms +1.58% -0.71% 1463.88 ms +0.29% -0.39% 0.2%
pngUploadProcessing 244.59 ms +7.51% -2.63% 251.91 ms +5.08% -2.06% -2.91%
largeJpegUploadProcessing 1441.86 ms +0.67% -0.66% 1449.77 ms +0.57% -0.56% -0.55%
multipleImageUploadProcessing 1533.97 ms +1.21% -0.67% 1531.47 ms +0.58% -1.64% 0.16%

post-editor

Metric 83944d1 trunk % Change
serverResponse 312.3 ms +3.64% -5.43% 327.17 ms +3.37% -9.37% -4.55%
firstPaint 342.77 ms +4.55% -7.46% 347 ms +6.59% -10.71% -1.22%
domContentLoaded 646.94 ms +4.81% -0.85% 657.86 ms +1.11% -1.83% -1.66%
loaded 647.8 ms +4.8% -0.86% 658.79 ms +1.11% -1.81% -1.67%
firstContentfulPaint 373.24 ms +6.87% -3.48% 373.57 ms +1.38% -2.43% -0.09%
firstBlock 1724.74 ms +7.31% -1.9% 1743.74 ms +1.42% -0.26% -1.09%
type 16.24 ms +10.28% -6.9% 15.45 ms +7.64% -4.47% 5.11%
typeWithoutInspector 15.28 ms +6.15% -5.69% 15.35 ms +5.6% -15.18% -0.46%
typeWithTopToolbar 19.89 ms +3.07% -5.68% 18.99 ms +2.9% -8% 4.74%
typeContainer 6.8 ms +26.03% -11.03% 6.4 ms +10.62% -5.47% 6.25%
focus 96.09 ms +5.07% -2% 96.46 ms +3.48% -4.78% -0.38%
firstFocus 220.59 ms +0% -0% 208.84 ms +0% -0% 5.63%
selectAll 313.3 ms +5.74% -2.56% 312.54 ms +0.07% -1.45% 0.24%
undo 24.01 ms +5.25% -4.29% 23.03 ms +8.42% -2.52% 4.26%
listViewOpen 62.99 ms +7.91% -5.79% 58.88 ms +3.45% -2.73% 6.98%
inserterOpen 33.46 ms +13.78% -7.89% 32.29 ms +10.31% -8.39% 3.62%
inserterHover 9.55 ms +8.27% -9.11% 9.43 ms +4.35% -6.79% 1.27%
inserterSearch 7.25 ms +6.07% -7.86% 7.09 ms +4.51% -5.5% 2.26%
loadPatterns 504.82 ms +5.32% -1.68% 509.24 ms +1.1% -1.01% -0.87%
wpTotal 303.69 ms +3.78% -5.63% 318.48 ms +3.35% -9.62% -4.64%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 83944d1 trunk % Change
serverResponse 394.72 ms +0.63% -4.33% 398.93 ms +2.03% -7.83% -1.06%
firstPaint 450.94 ms +8.2% -11.46% 394.72 ms +4.23% -3.29% 14.24%
domContentLoaded 829.01 ms +1.7% -3.59% 807.45 ms +0.37% -1.33% 2.67%
loaded 830.1 ms +1.69% -3.58% 808.49 ms +0.35% -1.32% 2.67%
firstContentfulPaint 469.96 ms +6.09% -4.5% 448.45 ms +0.64% -1.21% 4.8%
firstBlock 2362.74 ms +6.21% -1.58% 2366.35 ms +0.93% -0.81% -0.15%
type 17.94 ms +3.57% -10.93% 18.49 ms +6.92% -14.33% -2.97%
navigate 108.71 ms +8.59% -1.09% 106.59 ms +3.87% -2.63% 1.99%
loadPatterns 1374.86 ms +6.55% -4.3% 1371.99 ms +5.61% -12.92% 0.21%
loadPages 930.03 ms +0.4% -1.84% 923.02 ms +2.47% -1.88% 0.76%
wpTotal 384.54 ms +0.69% -4.29% 389.38 ms +2.09% -8.03% -1.24%
wpMemoryUsage 12.82 MB +0% -0% 12.79 MB +0% -0% 0.25%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

e8b0130 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

should select synced pattern in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]') with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
    14 × locator resolved to <div tabindex="0" role="document" draggable="true" data-title="Pattern" data-type="core/block" data-is-drop-zone="true" aria-label="Block: Pattern" id="block-323967a4-4658-4039-91ec-8a35afcef5b1" data-block="323967a4-4658-4039-91ec-8a35afcef5b1" class="block-editor-block-list__block wp-block is-selected is-reusable block-library-block__reusable-block-container wp-block-block block-editor-block-list__layout">…</div>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:1464:5

e8b0130 Run

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the Navigation inner-block control detection update.

No open issues 🎉

What changed in this PR

Updates the Navigation block to detect controlled inner blocks through areInnerBlocksControlled, addressing #46265 without relying on differences between getBlock() and getBlocks().

Changes:

  • Reads inner blocks once and classifies them using the controlled-state selector.
  • Converts the hook to TypeScript while retaining its return structure.
  • Adds unit tests for empty, uncontrolled, and controlled inner blocks.
File Description
packages/​block-library/​src/​navigation/​edit/​use-inner-blocks.ts Adds the typed hook using explicit controlled-state detection.
packages/​block-library/​src/​navigation/​edit/​use-inner-blocks.js Removes the JavaScript implementation replaced by TypeScript.
packages/​block-library/​src/​navigation/​edit/​test/​use-inner-blocks.jsdom.test.tsx Tests empty and uncontrolled blocks and the transition to controlled blocks.

Review effort: Balanced

mikachan and others added 2 commits November 19, 2026 13:49
…ies and selection

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@getdave getdave left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any regressions here.

I pushed some additional code coverage recommended after review.

Thanks for maintaining this 👍

@Mamaduka Mamaduka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two notes, not a blocker here, but can be nice cleanup for follow-up.

@mikachan
mikachan enabled auto-merge (squash) November 19, 2026 15:11
@mikachan
mikachan merged commit 4fa7210 into trunk Nov 19, 2026
90 checks passed
@mikachan
mikachan deleted the update/navigation-are-inner-blocks-controlled branch November 19, 2026 15:25
@github-actions github-actions Bot added this to the Gutenberg 24.6 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Navigation Affects the Navigation Block [Package] Block library /packages/block-library [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use the areInnerBlocksControlled selector to detect Controlled blocks in Nav block

4 participants