wordpress-mobile / wordpress-mobile/GutenbergKit

Prevent post data refetch with finishResolution instead of middleware filtering

Open
#434 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Gutenberg
Dominant language
JavaScript
Stars
29
Forks
6
Avg merge
1d 9h
Merged PRs (30d)
41

Description

Summary

filterEndpointsMiddleware in src/utils/api-fetch.js exists to block Gutenberg's automatic GET /wp/v2/{restBase}/{id} fetch, which overwrites the title and content injected by the native host. This middleware requires restBase and restNamespace to construct the path to block, which adds complexity to the native-to-JS bridge contract (see #432).

The root cause is that receiveEntityRecords in useEditorSetup puts post data into the store but does not mark the resolution as finished. Gutenberg's data layer treats "data exists" and "resolution is finished" as independent — so when a component calls getEntityRecord('postType', type, id), the resolver fires a network fetch even though the data is already present.

Proposed fix

After pre-seeding the post data in src/components/editor/use-editor-setup.js, call finishResolution to tell the data layer the record is already resolved:

receiveEntityRecords('postType', post.type, post);
finishResolution('getEntityRecord', ['postType', post.type, post.id]);

WordPress core uses this same pattern internally — see @wordpress/core-data/src/resolvers.js where finishResolution is called after receiveEntityRecords for navigation fallbacks and templates.

Expected outcome

  • Gutenberg's getEntityRecord resolver skips the network fetch entirely since the resolution is already marked as finished.
  • filterEndpointsMiddleware can be removed (or simplified), along with the JS-side dependency on restBase/restNamespace in the middleware.
  • The POST_FALLBACKS constant in bridge.js may be simplified since the middleware no longer needs fallback values for path construction.

Context

  • #432 added restBase/restNamespace to the Android payload and hardened the middleware with fallback defaults. That fix is correct and addresses the immediate bug. This issue tracks the deeper fix that eliminates the need for the middleware approach.
  • The Android library also has hardcoded /wp/v2/posts/ paths in RESTAPIRepository.buildPostUrl() and EditorPreloadList.buildPostPath() — those are separate from this issue but related parity work (iOS already uses dynamic restBase/restNamespace for both).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/components/editor/use-editor-setup.js and compare its receiveEntityRecords flow with the finishResolution usage in @wordpress/core-data/src/resolvers.js. Then inspect src/utils/api-fetch.js and bridge.js; done means pre-seeded posts skip the getEntityRecord fetch and the middleware no longer needs restBase/restNamespace for path filtering.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.