Make WordPress Core

Opened 3 months ago

Closed 3 months ago

#65699 closed defect (bug) (fixed)

Editor: REST index preload is never consumed due to a field list mismatch

Reported by: adamsilverstein Owned by: adamsilverstein
Priority: normal Milestone: 7.1
Component: Editor Version: 7.1
Severity: normal Keywords: has-patch commit
Cc: Focuses:

Description

Loading the post editor or the site editor on trunk logs a warning in the browser console:

[api-fetch] [preload] Some preloads were never consumed:
['GET /?_fields=description%2Cgmt_offset%2Chome%2Cimage_...']

The editors preload /?_fields=... so the initial site entity request from @wordpress/core-data is served from cache. The preload is matched by exact URL, so the field list built in wp-admin/edit-form-blocks.php and wp-admin/site-editor.php has to match the list the client builds in packages/core-data/src/entities.js - same fields, same order.

The lists drifted after two Gutenberg changes were only partially backported:

Because the URLs no longer match, the preloaded response is never consumed and the editor makes a second, uncached request to / on every load. With the Gutenberg plugin active the problem disappears, since the plugin rewrites the preload path with the current field list via the block_editor_rest_api_preload_paths filter - which is how this went unnoticed.

The fix updates the field lists in both wp-admin files to match the bundled package exactly. Worth noting that the generated admin pages under wp-includes/build/pages/ carry their own stale copy of this list; that one comes from the packages/wp-build templates in Gutenberg, so it needs an upstream fix and will land with a package sync.

PR: ​https://github.com/WordPress/wordpress-develop/pull/12665

## Steps to reproduce

  1. On trunk with the Gutenberg plugin deactivated, open a post in the block editor.
  2. Open the dev tools console and note the [api-fetch] [preload] Some preloads were never consumed warning; the network tab shows a duplicate request to /?_fields=....
  3. Apply the patch and reload: the console shows [api-fetch][preload] All preloads consumed. and the duplicate request is gone.
  4. Repeat in the site editor.

Change History (7)

This ticket was mentioned in ​PR #12665 on ​WordPress/wordpress-develop by ​@adamsilverstein.


3 months ago
#1

Trac ticket: https://core.trac.wordpress.org/ticket/65699

## Description

Loading the post editor or site editor on trunk logs a warning in the console:

[api-fetch] [preload] Some preloads were never consumed:
['GET /?_fields=description%2Cgmt_offset%2Chome%2Cimage_...']

The editors preload /?_fields=... so the initial site entity request from @wordpress/core-data is served from cache. The preload is matched by exact URL, so the field list in the PHP has to match the list the client builds in packages/core-data/src/entities.js - same fields, same order. The lists drifted after two Gutenberg changes were only partially backported:

Because the URLs no longer match, the preloaded response is never consumed and the editor makes a second, uncached request to / on every load. With the Gutenberg plugin active the problem disappears, since the plugin's block_editor_rest_api_preload_paths filter rewrites the path with the current field list - which is how this went unnoticed.

This PR updates the field lists in edit-form-blocks.php and site-editor.php to match the bundled package exactly. It also removes a stray $paths[] = assignment in edit-form-blocks.php left over from a previous backport.

Note: the generated admin pages under wp-includes/build/pages/ (font library, options connectors) carry their own stale copy of this list; that comes from the packages/wp-build page templates in Gutenberg, so I will fix it upstream and it will land here with the next package sync.

## How has this been tested

  1. On trunk, open a post in the block editor with the Gutenberg plugin deactivated.
  2. In the dev tools console, note the [api-fetch] [preload] Some preloads were never consumed warning, and in the network tab note the duplicate request to /?_fields=....
  3. Apply the patch and reload: the console shows [api-fetch][preload] All preloads consumed. and the duplicate request is gone.
  4. Repeat in the site editor.

I also verified the PHP lists now match the _fields list in the bundled wp-includes/js/dist/core-data.js exactly, including order.

​@westonruter commented on ​PR #12665:


3 months ago
#2

I'm still seeing warning in the post editor:

[!WARNING]
[api-fetch][preload] Some preloads were never consumed: ['GET /?_fields=description%2Cgmt_offset%2Chome%2Cim…%2Cpage_for_posts%2Cpage_on_front%2Cshow_on_front']

I don't see the error in the Site Editor, either in trunk of this branch.

​@adamsilverstein commented on ​PR #12665:


3 months ago
#3

I'm still seeing warning in the post editor:

I don't see that in Playground - ​https://playground.wordpress.net/?core-pr=12665. I will double check locally before committing.

​@adamsilverstein commented on ​PR #12665:


3 months ago
#4

I verified this fixes the issue for me locally after a full build.

#5 @adamsilverstein
3 months ago

  • Keywords commit added
  • Milestone Awaiting Review → 7.1

#6 @adamsilverstein
3 months ago

  • Owner set to adamsilverstein
  • Status new → assigned

#7 @adamsilverstein
3 months ago

  • Resolution → fixed
  • Status assigned → closed

In 62846:

Editor: Sync the REST index preload field list with core-data.

Sync the REST index preload field list in the post and site editors with the list the client requests, fixing a mismatch that left the preloaded response unused and logged a console warning on every editor load.

Follow-up to [61703], [62806].

Props wildworks, westonruter.
Fixes #65699.

Note: See TracTickets for help on using tickets.