Skip to content

Navigation: Show the stored link while a bound entity loads - #84006

Draft
jeryj wants to merge 2 commits into
trunkfrom
fix/navigation-link-pending-binding-url
Draft

jeryj wants to merge 2 commits into
trunkfrom
fix/navigation-link-pending-binding-url

Conversation

@jeryj

@jeryj jeryj commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What?

Follow up to #83408 and #85945.

Keeps the Link UI showing the selected link while the record for a newly bound entity is still loading, instead of briefly treating the link as empty.

Why?

Since #83408, a navigation link can be pointed at an entity of another type, for example a page link changed to a category. The URL is bound to the entity (core/term-data or core/post-data), and the binding has no URL until that entity's record loads. Pages are usually already in the store, but categories, tags and other types are not, so after selecting one the Link UI briefly:

  • showed the "No link selected" badge,
  • brought back the "Create page" and "Add block" tools,
  • swapped the title for the page's HTML title from the rich preview (for example "Uncategorized – Site name").

It then corrected itself once the record request finished, so the wrong state lasts as long as that request.

The same gap also left the Link UI open after a post was added from the "Add page" appender. LinkControl keys the link preview on the URL, so when the bound URL arrived the preview remounted, taking the focus with it to <body>. With nothing in the popover focused, clicking anywhere else no longer closed it. #85945 fixed that in LinkControl by extending its URL fallback to post links. With the Link UI now passing the stored URL while the record loads, that fallback is no longer needed.

How?

  • useEntityBinding returns a new isBoundEntityPending flag, true while hasFinishedResolution( 'getEntityRecord', … ) is false for the bound record. This tells a loading record apart from a deleted one, so a deleted entity still shows as missing.
  • While the record is pending, the navigation Link UI uses the URL stored on the block (getBlockAttributes( clientId ).url) and the link label as the entity title. Once the record loads, the bound value takes over as before.
  • LinkControl's entityUrlFallbackRef / previewValue workaround, which covered taxonomy links and, since Link Control: Keep focus in the preview while a chosen post's record loads #85945, post links, is removed. Its TODO asked for removal once the binding returns a URL while resolving, which the Link UI now provides.

The inspector sidebar's "Link to" preview also uses useLinkPreview with the bound URL and may show the same brief state. It is not changed or tested here.

Testing Instructions

  1. Open a post and insert a Navigation block with at least one link.
  2. In the browser dev tools, throttle the network (for example "Slow 4G") so the gap is easy to see.
  3. Click the "Add page" appender in the Navigation block.
  4. Search for "Uncategorized" and select the category result.
  5. While the category loads, the preview should show "Uncategorized" with the category URL. It should not show "No link selected", "Create page" or "Add block", and the title should not change to the page's HTML title.
  6. Once loaded, the "Category" badge appears.
  7. Repeat on trunk to see the in-between state.

Automated coverage:

  • New e2e test in navigation.spec.js holds the category request open and checks the preview during and after the wait. It fails on trunk and passes here.
  • The e2e test from Link Control: Keep focus in the preview while a chosen post's record loads #85945, which adds a post from a submenu's "Add page" appender and checks that clicking outside closes the Link UI, still passes without the LinkControl fallback.
  • New unit tests for isBoundEntityPending in use-entity-binding.jsdom.test.js: loading, loaded, deleted, no binding, and the tag → post_tag mapping.

Testing Instructions for Keyboard

  1. Insert a Navigation block, then press Tab until the "Add page" appender has focus, and press Enter.
  2. Type "Uncategorized", press the Down arrow until the category result is highlighted, and press Enter.
  3. Confirm the preview shows the category link with no "No link selected" badge while it loads, and that focus stays in the link popover.

Use of AI Tools

This PR was written with Claude Code (Claude Opus 5.5): debugging the in-between state with a diagnostic e2e trace, writing the tests and the fix. I reviewed the changes.

🤖 Generated with Claude Code

https://claude.ai/code/session_013RXB2AJtSuC5Gdi1ZUy8wf

@jeryj jeryj added [Block] Navigation Affects the Navigation Block [Type] Bug An existing feature does not function as intended labels Oct 1, 2026
@github-actions github-actions Bot added [Package] Block library /packages/block-library [Package] Block editor /packages/block-editor labels Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

📦 Bundle size

Size Change: -24 B (0%)

Total Size: 8.56 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 542 kB -90 B (-0.02%)
build/scripts/block-library/index.min.js 402 kB +66 B (+0.02%)

f5ac6c8 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 72b6fd5 trunk % Change
timeToFirstByte 57.5 ms +5.65% -6.17% 55.65 ms +13.3% -3.05% 3.32%
largestContentfulPaint 92 ms +8.7% -2.17% 90 ms +6.67% -2.22% 2.22%
lcpMinusTtfb 34.9 ms +13.18% -4.44% 33.25 ms +6.02% -3.46% 4.96%
wpBeforeTemplate 29.6 ms +13.89% -3.04% 29.32 ms +12.82% -1.91% 0.95%
wpTemplate 22.67 ms +7.32% -8.69% 22.18 ms +2.3% -3.61% 2.21%
wpTotal 53.6 ms +5.95% -6.36% 51.84 ms +13.18% -3.13% 3.4%
wpMemoryUsage 7.70 MB +0% -0% 7.67 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 72b6fd5 trunk % Change
timeToFirstByte 43.25 ms +8.79% -3.82% 47.25 ms +10.48% -3.39% -8.47%
largestContentfulPaint 92 ms +4.35% -4.35% 104 ms +3.85% -5.77% -11.54%
lcpMinusTtfb 47.5 ms +3.47% -1.79% 53.65 ms +3.45% -4.1% -11.46%
wpBeforeTemplate 27.2 ms +6.8% -2.72% 27.29 ms +10.55% -3.88% -0.33%
wpTemplate 12.76 ms +4.78% -6.66% 16.77 ms +6.5% -4.53% -23.91%
wpTotal 40.42 ms +7.62% -4.77% 44.06 ms +9.9% -3.31% -8.26%
wpMemoryUsage 6.28 MB +0% -0% 6.36 MB +0% -0% -1.22%
wpDbQueries 9 +0% -0% 13 +0% -0% -30.77%

media-processing

Metric 72b6fd5 trunk % Change
mediaProcessingJpeg 417.56 ms +0.33% -2.97% 410.61 ms +0.42% -2.03% 1.69%
mediaProcessingAvif 6134.73 ms +0.23% -0.03% 6187.43 ms +0.07% -0.24% -0.85%
mediaProcessingJpegToAvif 4241.93 ms +0.34% -0.14% 4266.09 ms +0.29% -0.14% -0.57%

media-upload

Metric 72b6fd5 trunk % Change
jpegUploadProcessing 1939.11 ms +1.2% -23.79% 1502.76 ms +29.81% -2.71% 29.04%
pngUploadProcessing 240.33 ms +6.93% -27.1% 220.43 ms +19.33% -24.66% 9.03%
largeJpegUploadProcessing 1950.04 ms +0.57% -0.99% 1481.2 ms +30.57% -1.15% 31.65%
multipleImageUploadProcessing 2026.72 ms +0.6% -0.36% 2039.43 ms +1.62% -1.34% -0.62%

post-editor

Metric 72b6fd5 trunk % Change
serverResponse 512.27 ms +8.1% -1.83% 511.54 ms +11.23% -3.57% 0.14%
firstPaint 408.5 ms +27.5% -29.13% 499.01 ms +7.09% -50.01% -18.14%
domContentLoaded 890.7 ms +2.73% -2.69% 916.88 ms +2.48% -2.45% -2.86%
loaded 891.88 ms +2.74% -2.7% 918.11 ms +2.45% -2.46% -2.86%
firstContentfulPaint 504.61 ms +4.09% -13.78% 528.85 ms +2.09% -3.39% -4.58%
firstBlock 3027.36 ms +1.14% -0.98% 3104.72 ms +1.34% -1.64% -2.49%
type 18.38 ms +8.98% -3.75% 18.51 ms +4.43% -7.67% -0.7%
typeWithoutInspector 20.05 ms +1.25% -4.69% 17.67 ms +9.73% -1.81% 13.47%
typeWithTopToolbar 23.93 ms +5.6% -8.48% 22.03 ms +13.53% -4.77% 8.62%
typeContainer 8.43 ms +11.63% -11.74% 9.02 ms +1.88% -6.98% -6.54%
focus 125.55 ms +2.15% -5.09% 121.24 ms +7.37% -2.78% 3.55%
firstFocus 250.78 ms +0% -0% 241.03 ms +0% -0% 4.05%
selectAll 475.38 ms +3.3% -1.6% 486.33 ms +3.81% -1.7% -2.25%
undo 31.68 ms +7.1% -6.22% 33.32 ms +9.3% -6.42% -4.92%
listViewOpen 78.56 ms +1.43% -1.43% 79.57 ms +8.45% -4.25% -1.27%
inserterOpen 46.88 ms +4.63% -16.42% 43.6 ms +4.17% -12.64% 7.52%
inserterHover 12.23 ms +6.79% -8.99% 11.43 ms +5.77% -8.22% 7%
inserterSearch 7.9 ms +3.92% -3.16% 7.63 ms +8.65% -3.28% 3.54%
loadPatterns 689.6 ms +5.03% -2.22% 624.15 ms +4.72% -2.34% 10.49%
wpTotal 502.23 ms +7.89% -1.95% 501.34 ms +11.46% -3.56% 0.18%
wpMemoryUsage 14.73 MB +0% -0% 14.72 MB +0% -0% 0.1%
wpDbQueries 55 +0% -1.82% 55 +0% -1.82% 0%

site-editor

Metric 72b6fd5 trunk % Change
serverResponse 260.02 ms +7.09% -5.85% 281.98 ms +3.15% -8.19% -7.79%
firstPaint 166.15 ms +12.19% -13.84% 183.01 ms +7.83% -23.2% -9.21%
domContentLoaded 583.33 ms +1.96% -1.27% 585.09 ms +3.4% -0.98% -0.3%
loaded 584.03 ms +2.02% -1.24% 585.91 ms +3.39% -0.98% -0.32%
firstContentfulPaint 333.25 ms +5.5% -6.23% 335.09 ms +2.55% -9.28% -0.55%
firstBlock 2434.07 ms +1.1% -2.04% 2410.02 ms +1.79% -1.73% 1%
type 13.41 ms +3.88% -8.13% 12.95 ms +4.02% -4.94% 3.55%
navigate 92.18 ms +4.76% -18.62% 86.59 ms +6.22% -1.19% 6.46%
loadPatterns 754.47 ms +12.14% -2.46% 798.81 ms +33.5% -6.66% -5.55%
loadPages 926.01 ms +4.02% -1.95% 946.7 ms +1.84% -0.81% -2.19%
wpTotal 253.09 ms +7.46% -5.89% 275.01 ms +3.27% -8.33% -7.97%
wpMemoryUsage 12.77 MB +0% -0% 12.73 MB +0% -0% 0.27%
wpDbQueries 44.5 +1.12% -1.12% 44.5 +1.12% -1.12% 0%

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

List in /test/e2e/specs/editor/blocks/query.spec.js, passed after 1 failed attempt.
Error: apiRequestContext.fetch: socket hang up
Call log:
  - → GET http://localhost:8891/wp-json/wp/v2/pages?per_page=100&status=publish%2Cfuture%2Cdraft%2Cpending%2Cprivate%2Ctrash
    - user-agent: Playwright/1.63.0 (x64; ubuntu 24.04) node/24.20 CI/1
    - accept: */*
    - accept-encoding: gzip,deflate,br
    - X-WP-Nonce: 39240b932f
    - cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_da433b7faafd8180ebeb1624ceeeab7e=admin%7C1793468260%7Chg10PGZvIhF32QtuPNbFxAP53zaxTvYS0E2juyceJtv%7Cbeb68543c7c225ce401018eafa19fe65b2ea6d0e4d9cf71ad8ba2d17c0316d04; wp-settings-time-1=1793295528

    at RequestUtils.rest (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/rest.ts:111:39)
    at RequestUtils.deleteAllPages (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/pages.ts:44:27)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/query.spec.js:8:17
can be converted when nested to paragraphs in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 1
+ Received  + 1

  <!-- wp:paragraph -->
- <p>one</p>
+ <p>ne</p>
  <!-- /wp:paragraph -->

  <!-- wp:paragraph -->
  <p>two</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:417:52
does not double up an event React already delivers in /test/e2e/specs/editor/various/editable-root-compat.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/editable-root-compat.spec.js:291:5
inserts a block in proper place after having clicked `Browse All` from inline inserter in /test/e2e/specs/editor/various/inserting-blocks.spec.js, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for getByRole('button', { name: 'Add block' })
    - locator resolved to <button type="button" aria-pressed="false" aria-haspopup="true" aria-expanded="false" aria-label="Add block" class="components-button block-editor-inserter__toggle is-next-40px-default-size has-icon">…</button>
  - attempting click action
    - waiting for element to be visible, enabled and stable
  - element was detached from the DOM, retrying

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/inserting-blocks.spec.js:557:5
region-scoped focus that refrains on traversals in /test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts, passed after 1 failed attempt.
Error: expect(locator).toHaveCount(expected) failed

Locator:  locator('[data-wp-router-region="lifecycle-a"] :focus')
Expected: 0
Received: 1
Timeout:  5000ms

Call log:
  - Expect "toHaveCount" locator('[data-wp-router-region="lifecycle-a"] :focus') with timeout 5000ms
  - waiting for locator('[data-wp-router-region="lifecycle-a"] :focus')
    14 × locator resolved to 1 element
       - unexpected value "1"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:1652:37
should create paragraph on Enter in quote block in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for getByRole('option', { name: 'List', exact: true })

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:751:67
should insert a line break on shift+enter in a non trailing list item in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 10
+ Received  + 10

  <!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
- <li>a</li>
+ <li></li>
- <!-- /wp:list-item -->
-
+ <!-- /wp:list-item --></ul>
- <!-- wp:list-item -->
+ <!-- /wp:list -->
+
+ <!-- wp:paragraph -->
- <li>b<br></li>
+ <p>b<br></p>
- <!-- /wp:list-item -->
+ <!-- /wp:paragraph -->

- <!-- wp:list-item -->
+ <!-- wp:paragraph -->
- <li>c</li>
+ <p>c</p>
- <!-- /wp:list-item --></ul>
- <!-- /wp:list -->
+ <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:1233:52
should keep the list type when indenting an ordered list item in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 1
+ Received  + 1

@@ -1,8 +1,8 @@
  <!-- wp:list {"ordered":true} -->
  <ol class="wp-block-list"><!-- wp:list-item -->
- <li>one<!-- wp:list {"ordered":true} -->
+ <li>ne<!-- wp:list {"ordered":true} -->
  <ol class="wp-block-list"><!-- wp:list-item -->
  <li>two</li>
  <!-- /wp:list-item --></ol>
  <!-- /wp:list --></li>
  <!-- /wp:list-item --></ol>

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:916:52
should merge a following sibling list into the outermost list with Delete from a nested item (#77245) in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

@@ -8,11 +8,11 @@
          "innerBlocks": Array [
            Object {
              "innerBlocks": Array [
                Object {
                  "attributes": Object {
-                   "content": "b‸",
+                   "content": "b",
                  },
                  "name": "core/list-item",
                },
              ],
              "name": "core/list",
@@ -25,11 +25,11 @@
    },
    Object {
      "innerBlocks": Array [
        Object {
          "attributes": Object {
-           "content": "1",
+           "content": "‸1",
          },
          "innerBlocks": Array [
            Object {
              "innerBlocks": Array [
                Object {

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:2854:41
should split indented list item in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 1
+ Received  + 1

@@ -1,8 +1,8 @@
  <!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
- <li>one<!-- wp:list -->
+ <li>ne<!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
  <li>two</li>
  <!-- /wp:list-item -->

  <!-- wp:list-item -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:668:52

f5ac6c8 Run

jeryj and others added 2 commits October 29, 2026 12:07
When a navigation link switches to an entity type whose record isn't loaded yet (for example, a page link changed to a category), the URL binding returns no URL until the record request finishes. The Link UI treated the link as empty in the meantime: it showed "No link selected", brought back the "Create page" and "Add block" tools, and swapped the title for the page's HTML title from the rich preview.

`useEntityBinding` now reports `isBoundEntityPending` from the record's resolution state, which tells a loading record apart from a deleted one. While it is pending, the Link UI uses the URL stored on the block and the link label as the entity title. This makes the taxonomy-only URL fallback in LinkControl unnecessary, so it is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013RXB2AJtSuC5Gdi1ZUy8wf
@jeryj
jeryj force-pushed the fix/navigation-link-pending-binding-url branch from e1a6852 to f5ac6c8 Compare October 29, 2026 17:30

This branch has not been deployed

No deployments
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 editor /packages/block-editor [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant