Skip to content

Navigation: Resolve PHPStan baseline errors in the block nav menus theme opt-in - #86469

Merged
westonruter merged 2 commits into
trunkfrom
fix/navigation-theme-opt-in-phpstan
Nov 9, 2026
Merged

westonruter merged 2 commits into
trunkfrom
fix/navigation-theme-opt-in-phpstan

Conversation

@westonruter

Copy link
Copy Markdown
Member

What?

See #86088

Resolves all of the PHPStan baseline entries for lib/experimental/navigation-theme-opt-in.php by removing dead code and typing the dynamic nav menu item properties. Only one entry remains in the baseline, for lib/class-wp-rest-global-styles-controller-gutenberg.php.

Why?

The block-nav-menus theme opt-in was disabled in #34444 (see #34265) by replacing the current_theme_supports() checks with if ( true ) and if ( false ). PHPStan reports these as always-true and always-false conditions, unreachable code, and a string return type that is never used. The remaining errors were accesses to WP_Post::$type and WP_Post::$content, which are not declared on WP_Post but are added at runtime by wp_setup_nav_menu_item(). This addresses 6 of the errors initially baselined in #66693.

How?

  • gutenberg_output_block_nav_menu() gets its real ! current_theme_supports( 'block-nav-menus' ) check back in place of if ( true ), and its pre_wp_nav_menu hook is commented out instead. The function is kept intact but never runs. (if.alwaysTrue, deadCode.unreachable, return.unusedType)
  • gutenberg_remove_block_nav_menu_items() drops the if ( false ) early return. The intended opt-in check is kept in a comment for when the feature is re-enabled. (if.alwaysFalse)
  • The $item parameters of gutenberg_output_block_nav_menu_item() and gutenberg_output_block_menu_item_custom_fields() are typed as WP_Post&object{type: string, content?: string}. wp_setup_nav_menu_item() always sets type, but gutenberg_setup_block_nav_menu_item() sets content only for block menu items, so content is optional and read with a ?? '' fallback. (property.notFound)
    • type has to be required: an object shape whose properties are all optional is a supertype of WP_Post, so PHPStan reduces the intersection to plain WP_Post and the shape has no effect.
  • The $args parameter of gutenberg_output_block_nav_menu_item() is typed as stdClass&object{before: string, after: string}, matching the wp_nav_menu() defaults.
  • Removed the 6 corresponding entries from tools/phpstan/baseline.neon.

There is no change in behavior: block menu items are still always removed, and wp_nav_menu() still renders classic menus.

Testing Instructions

  1. Run composer phpstan and confirm it passes with no unmatched ignored errors.
  2. Run composer phpstan:baselines and confirm tools/phpstan/baseline.neon has no further changes.
  3. With a classic theme, assign a menu to a location and confirm it renders on the frontend as before.

Testing Instructions for Keyboard

Not applicable. There are no UI changes.

Screenshots or screencast

Not applicable.

Use of AI Tools

I used Claude Code (Claude Opus 5.5, medium effort) to analyze the baselined errors, probe the PHPStan types, and draft the change and this description. I reviewed the diff and take responsibility for it.

westonruter and others added 2 commits November 7, 2026 11:56
…cuiting

The `block-nav-menus` theme opt-in was disabled by replacing the
`current_theme_supports()` checks with `if ( true )` and `if ( false )`,
which PHPStan reports as always-true and always-false conditions,
unreachable code, and a string return type that is never used.

Restore the real `current_theme_supports()` check in
`gutenberg_output_block_nav_menu()` and comment out its `pre_wp_nav_menu`
hook instead, so the function is kept intact but never runs. In
`gutenberg_remove_block_nav_menu_items()`, drop the dead early return and
keep the intended opt-in check in a comment. Behavior is unchanged: block
menu items are still always removed, and `wp_nav_menu()` still renders
classic menus.

Remove the four baseline entries that are now resolved.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: 9bb536c7-7399-4262-80ed-cebfc277b43b
The `type` and `content` properties on nav menu items are not declared on
`WP_Post`; they are added at runtime by `wp_setup_nav_menu_item()`, which
always sets `type` but sets `content` only for block menu items. Document
them as object shape properties on the `WP_Post` parameters, with
`content` optional and read with a `''` fallback.

`type` is required in the shape rather than optional: an object shape
whose properties are all optional is a supertype of `WP_Post`, so PHPStan
reduces the intersection to plain `WP_Post` and the shape has no effect.

Also document the `before` and `after` strings of the `wp_nav_menu()`
arguments object.

Remove the last two baseline entries for this file.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: 9bb536c7-7399-4262-80ed-cebfc277b43b
@westonruter westonruter added the [Type] Code Quality Issues or PRs that relate to code quality label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 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: westonruter <westonruter@git.wordpress.org>
Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@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.

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric adbfa1e trunk % Change
timeToFirstByte 56.05 ms +5.35% -3.21% 54.4 ms +13.6% -3.31% 3.03%
largestContentfulPaint 96 ms +8.33% -6.25% 94 ms +4.26% -6.38% 2.13%
lcpMinusTtfb 36.55 ms +16.96% -5.88% 36.8 ms +14.4% -7.2% -0.68%
wpBeforeTemplate 29.62 ms +9.05% -1.86% 28.77 ms +15.71% -1.98% 2.95%
wpTemplate 22.02 ms +2.54% -2.72% 21.98 ms +3.28% -4.14% 0.18%
wpTotal 52.22 ms +5.57% -3.18% 50.74 ms +14.17% -3.17% 2.92%
wpMemoryUsage 7.72 MB +0% -0% 7.69 MB +0% -0% 0.41%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric adbfa1e trunk % Change
timeToFirstByte 46.7 ms +10.06% -1.82% 45.85 ms +5.34% -1.42% 1.85%
largestContentfulPaint 100 ms +6% -0% 98 ms +4.08% -2.04% 2.04%
lcpMinusTtfb 54.2 ms +2.49% -2.03% 51.95 ms +3.66% -2.21% 4.33%
wpBeforeTemplate 26.99 ms +6.93% -1.82% 26.52 ms +1.92% -1.36% 1.77%
wpTemplate 16.59 ms +7.59% -3.07% 16.4 ms +2.01% -2.74% 1.16%
wpTotal 43.72 ms +9.63% -1.9% 42.64 ms +5.72% -1.34% 2.53%
wpMemoryUsage 6.41 MB +0% -0% 6.38 MB +0% -0% 0.51%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric adbfa1e trunk % Change
mediaProcessingJpeg 405.75 ms +2.66% -0.25% 397.24 ms +1.58% -0.38% 2.14%
mediaProcessingAvif 6147.36 ms +0.16% -0.1% 6157.71 ms +0.53% -0.21% -0.17%
mediaProcessingJpegToAvif 4227.51 ms +0.35% -0.17% 4249.06 ms +0.82% -0.03% -0.51%

media-upload

Metric adbfa1e trunk % Change
jpegUploadProcessing 1464.35 ms +33.78% -0.63% 1456.38 ms +1.63% -0.98% 0.55%
pngUploadProcessing 171.54 ms +6.79% -5.5% 178.07 ms +33.14% -2.33% -3.67%
largeJpegUploadProcessing 1451.72 ms +0.83% -0.66% 1479.23 ms +1% -0.62% -1.86%
multipleImageUploadProcessing 2025.68 ms +0.43% -0.51% 2020.73 ms +0.83% -0.36% 0.24%

post-editor

Metric adbfa1e trunk % Change
serverResponse 318.04 ms +0.86% -7.62% 292.7 ms +11.41% -1.75% 8.66%
firstPaint 279.3 ms +37.79% -28.81% 267.24 ms +8.09% -11.9% 4.51%
domContentLoaded 661.98 ms +3.31% -0.72% 662.74 ms +1.07% -0.68% -0.11%
loaded 662.76 ms +3.34% -0.71% 663.49 ms +1.07% -0.67% -0.11%
firstContentfulPaint 394.37 ms +0.99% -1.36% 389.58 ms +1.8% -1.76% 1.23%
firstBlock 1679.37 ms +1.49% -1.6% 1664.93 ms +1.56% -0.47% 0.87%
type 13.83 ms +2.75% -9.47% 14.49 ms +2.35% -3.45% -4.55%
typeWithoutInspector 13.67 ms +3.8% -7.61% 13.74 ms +3.57% -10.99% -0.51%
typeWithTopToolbar 18.18 ms +1.6% -4.95% 17.29 ms +5.21% -3.53% 5.15%
typeContainer 6.92 ms +3.61% -3.18% 6.68 ms +1.95% -2.69% 3.59%
focus 91.3 ms +9.69% -0.32% 91.78 ms +1.24% -7.11% -0.52%
firstFocus 205.12 ms +0% -0% 189.51 ms +0% -0% 8.24%
selectAll 300.49 ms +3.53% -0.62% 292.12 ms +3.69% -1.11% 2.87%
undo 23.6 ms +3.9% -3.01% 24.12 ms +2.86% -2.57% -2.16%
listViewOpen 59.63 ms +6.81% -3.2% 57.53 ms +8.38% -5.75% 3.65%
inserterOpen 31.37 ms +8.07% -7.36% 33.35 ms +1.83% -4.02% -5.94%
inserterHover 9.18 ms +8.93% -5.23% 8.83 ms +7.59% -9.63% 3.96%
inserterSearch 6.92 ms +9.54% -3.32% 7.2 ms +5.28% -8.61% -3.89%
loadPatterns 501.84 ms +3.25% -3.16% 499.22 ms +4.87% -1.82% 0.52%
wpTotal 309.36 ms +0.92% -7.77% 283.99 ms +11.81% -1.76% 8.93%
wpMemoryUsage 14.77 MB +0% -0% 14.74 MB +0% -0% 0.23%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric adbfa1e trunk % Change
serverResponse 313.64 ms +1.59% -9.67% 306.61 ms +5.79% -5.38% 2.29%
firstPaint 364.11 ms +10.39% -15.98% 290.4 ms +5.69% -10.14% 25.38%
domContentLoaded 693.29 ms +1.32% -2.25% 705.56 ms +1.91% -1.48% -1.74%
loaded 694.07 ms +1.31% -2.24% 706.41 ms +1.91% -1.47% -1.75%
firstContentfulPaint 406.82 ms +5.61% -2.58% 407.93 ms +1.19% -1.3% -0.27%
firstBlock 2008.98 ms +3.08% -1.18% 2070.42 ms +1.41% -0.25% -2.97%
type 15.14 ms +9.71% -8.72% 15.34 ms +4.11% -8.34% -1.3%
navigate 89.57 ms +15.32% -0.57% 89.65 ms +13.34% -7.09% -0.09%
loadPatterns 1090.69 ms +3.57% -3.81% 1022.73 ms +7.76% -9.08% 6.64%
loadPages 1019.32 ms +2.93% -3.43% 1018.7 ms +2.87% -1.66% 0.06%
wpTotal 305.37 ms +1.61% -9.99% 298.12 ms +5.97% -5.52% 2.43%
wpMemoryUsage 12.79 MB +0% -0% 12.76 MB +0% -0% 0.26%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

f7900b9 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.

Navigates the items list via UP/DOWN arrow keys in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByLabel('Page Two')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByLabel('Page Two') with timeout 5000ms
  - waiting for getByLabel('Page Two')
    14 × locator resolved to <button type="button" tabindex="-1" aria-pressed="false" id="view-list-0-160-item-wrapper" class="dataviews-view-list__item" aria-labelledby="view-list-0-160-label" aria-describedby="view-list-0-160-description"></button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:146:49
Page List converts to Navigation Links with entity bindings in /test/e2e/specs/editor/blocks/navigation.spec.js, passed after 1 failed attempt.
Error: expect(locator).toContainText(expected) failed

Locator: getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ })
Expected substring: "test-page-1"
Received string:    "Link to:Cat/catPagePublished"
Timeout: 5000ms

Call log:
  - Expect "toContainText" getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ }) with timeout 5000ms
  - waiting for getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ })
    14 × locator resolved to <button type="button" aria-expanded="false" aria-haspopup="dialog" class="components-button link-preview-button is-next-40px-default-size is-secondary">…</button>
       - unexpected value "Link to:Cat/catPagePublished"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation.spec.js:1949:31

allows widgets to be moved between widget areas using the dropdown in the block toolbar in /test/e2e/specs/widgets/editing-widgets.spec.js, passed after 1 failed attempt.

does not select blocks in the canvas preview when editing from the sidebar (Site Editor v2) in /test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator: getByRole('combobox', { name: 'Search or type URL' })
Expected: focused
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeFocused" getByRole('combobox', { name: 'Search or type URL' }) with timeout 5000ms
  - waiting for getByRole('combobox', { name: 'Search or type URL' })

    at LinkControl.useLinkControlSearch (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:416:47)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:179:21
does not select blocks in the canvas preview when editing from the sidebar in /test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator: getByRole('combobox', { name: 'Search or type URL' })
Expected: focused
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeFocused" getByRole('combobox', { name: 'Search or type URL' }) with timeout 5000ms
  - waiting for getByRole('combobox', { name: 'Search or type URL' })

    at LinkControl.useLinkControlSearch (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:416:47)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:179:21
should only mutate text data on input in /test/e2e/specs/editor/various/rich-text.spec.js, passed after 1 failed attempt.
Error: expect(received).toEqual(expected) // deep equality

- Expected  - 1
+ Received  + 4

- Array []
+ Array [
+   "Typing should only mutate once.",
+   "Typing mutated more than character data: attributes",
+ ]
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/rich-text.spec.js:460:20
should place the caret at the click position when clicking a block that is not selected in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

@@ -1,9 +1,9 @@
  Array [
    Object {
      "attributes": Object {
-       "content": "First!",
+       "content": "First",
      },
      "name": "core/paragraph",
    },
    Object {
      "attributes": Object {

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:952:41

f7900b9 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

The six identified PHPStan baseline issues were addressed with safer annotations and fallbacks while preserving the existing navigation behavior.

No open issues 🎉

What changed in this PR

This pull request resolves six PHPStan baseline errors in the navigation theme opt-in code while preserving the currently disabled block-nav-menus behavior.

Changes:

  • Restores the theme-support condition and disables the inactive navigation rendering hook.
  • Removes unreachable conditional code.
  • Adds PHPStan object-shape annotations and safe fallbacks for dynamic menu-item properties.
  • Removes the six resolved entries from the PHPStan baseline.
File Description
tools/​phpstan/​baseline.neon Removes the resolved PHPStan baseline entries for the navigation theme opt-in.
lib/​experimental/​navigation-theme-opt-in.php Updates navigation menu shims, removes dead code, and adds PHPStan annotations for dynamic menu properties.

Review effort: Lite

@huzaifaalmesbah huzaifaalmesbah 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.

Looks good, thanks! Restoring the real theme support check and commenting out the hook keeps the behavior the same, and the content? shape with the ?? '' fallback is a nice touch.

@ramonjd ramonjd 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.

nice cleanup

@westonruter
westonruter merged commit 7b2242f into trunk Nov 9, 2026
111 checks passed
@westonruter
westonruter deleted the fix/navigation-theme-opt-in-phpstan branch November 9, 2026 03:36
@github-actions github-actions Bot added this to the Gutenberg 24.5 milestone Nov 9, 2026
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
…eme opt-in (WordPress#86469)

* Navigation: Disable block nav menu output by unhooking, not short-circuiting

The `block-nav-menus` theme opt-in was disabled by replacing the
`current_theme_supports()` checks with `if ( true )` and `if ( false )`,
which PHPStan reports as always-true and always-false conditions,
unreachable code, and a string return type that is never used.

Restore the real `current_theme_supports()` check in
`gutenberg_output_block_nav_menu()` and comment out its `pre_wp_nav_menu`
hook instead, so the function is kept intact but never runs. In
`gutenberg_remove_block_nav_menu_items()`, drop the dead early return and
keep the intended opt-in check in a comment. Behavior is unchanged: block
menu items are still always removed, and `wp_nav_menu()` still renders
classic menus.

Remove the four baseline entries that are now resolved.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>

* Navigation: Type the dynamic nav menu item properties

The `type` and `content` properties on nav menu items are not declared on
`WP_Post`; they are added at runtime by `wp_setup_nav_menu_item()`, which
always sets `type` but sets `content` only for block menu items. Document
them as object shape properties on the `WP_Post` parameters, with
`content` optional and read with a `''` fallback.

`type` is required in the shape rather than optional: an object shape
whose properties are all optional is a supertype of `WP_Post`, so PHPStan
reduces the intersection to plain `WP_Post` and the shape has no effect.

Also document the `before` and `after` strings of the `wp_nav_menu()`
arguments object.

Remove the last two baseline entries for this file.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>

---------

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants