wordpress-mobile / wordpress-mobile/GutenbergKit
Prevent post data refetch with finishResolution instead of middleware filtering
Nobody has claimed this yet.
- 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
getEntityRecordresolver skips the network fetch entirely since the resolution is already marked as finished. filterEndpointsMiddlewarecan be removed (or simplified), along with the JS-side dependency onrestBase/restNamespacein the middleware.- The
POST_FALLBACKSconstant inbridge.jsmay be simplified since the middleware no longer needs fallback values for path construction.
Context
- #432 added
restBase/restNamespaceto 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 inRESTAPIRepository.buildPostUrl()andEditorPreloadList.buildPostPath()— those are separate from this issue but related parity work (iOS already uses dynamicrestBase/restNamespacefor both).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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