Admin UI: opening an item page refetches KsFetchAdminMeta and KsFetchItem ("Apollo Client stopped refetching")

Open Beginner friendly
#10,143 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
graphql, node.js, react, typescript

Research direction

Start with the Admin UI InMemoryCache in packages/core/src/admin-ui/context.tsx and the KsFetchAdminMeta and KsFetchItem queries described in the issue. Check how Apollo Client caches their shared KeystoneMeta and KeystoneAdminMeta objects. Done means opening an item page sends each query once and shows no stopped-refetching warning.

Written by the indexing model from the issue text.

Description

Steps to reproduce

  1. In a project on the published @keystone-6/core 9.0.0 (examples/assets-local with a fresh npm install will do), run keystone dev and create one item.
  2. Open the item's page in the Admin UI, with the browser's console and network panel open.

The item page sends both of its queries twice, and the console warns:

Apollo Client stopped refetching 'KsFetchAdminMeta' because the same incomplete cache result was already refetched.
Automatic refetching was halted to prevent an endless cycle of network requests.
Page GraphQL requests
Dashboard KsFetchAdminMeta, KsFetchListCounts
Item page KsFetchAdminMeta, KsFetchItem, KsFetchAdminMeta, KsFetchItem

In keystone dev, Next forwards the warning to the terminal as [browser] Apollo Client stopped refetching 'KsFetchAdminMeta'.

Expected

The item page sends KsFetchAdminMeta and KsFetchItem once each, without a warning.

Cause

Both queries select fields of the same object: KsFetchAdminMeta reads keystone { adminMeta { lists { … } } }, and KsFetchItem reads keystone { adminMeta { list(key: $listKey, itemId: $id) { … } } }. KeystoneMeta and KeystoneAdminMeta have no id, and the Admin UI's InMemoryCache (packages/core/src/admin-ui/context.tsx) has no typePolicies, so storing KsFetchItem's result replaces the cached adminMeta object, and its lists field is lost.
KsFetchAdminMeta then finds its cache result incomplete and refetches, which KsFetchItem overwrites again, until Apollo Client 4 stops the loop.

With new InMemoryCache({ typePolicies: { KeystoneMeta: { merge: true }, KeystoneAdminMeta: { merge: true } } }) the item page sends each query once and the warning is gone (tried in the same project).

Context

macOS, Node 24.18.0; @keystone-6/core 9.0.0 with its @apollo/client 4.3.8. Nothing breaks: the page and the navigation work. The cost is the two extra requests on every item page, and KsFetchAdminMeta is the Admin UI's largest query.

Dominant language
TypeScript
Stars
10k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
38

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

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.

More from keystonejs/keystone

All issues in keystonejs/keystone

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.