Skip to content

fix(keystatic): avoid queuing missing files for deletion in parseEntry - #1686

Open
MilindChatrabhuji wants to merge 1 commit into
Thinkmill:mainfrom
MilindChatrabhuji:fix/item-data-missing-files-1627
Open

MilindChatrabhuji wants to merge 1 commit into
Thinkmill:mainfrom
MilindChatrabhuji:fix/item-data-missing-files-1627

Conversation

@MilindChatrabhuji

Copy link
Copy Markdown
Contributor

Summary

  • Fixes parseEntry (packages/keystatic/src/app/useItemData.ts) so non-existent asset, content, or directory file lookups are not recorded in usedFiles (initialFiles).
  • Prevents useUpsertItem and useDeleteItem from requesting deletion of paths that do not exist in the repository tree (which GitHub rejects with [GraphQL] A path was requested for deletion which does not exist as of commit oid ...).

Root Cause

In packages/keystatic/src/app/useItemData.ts, getFile added filepath to usedFiles and TrackedMap.get invoked #onGet(key) before checking whether the file actually existed in filesWithFakeFile / the underlying Map. When an entry referenced a renamed/missing asset file or resolved path not present in the loaded tree, the missing path remained in initialFiles, causing useUpsertItem (when not re-added) or useDeleteItem to include it in fileChanges.deletions.

Changes

  • packages/keystatic/src/app/useItemData.ts: guard usedFiles.add in getFile with filesWithFakeFile.has(filepath) and guard this.#onGet(key) in TrackedMap.get with super.has(key).
  • packages/keystatic/src/app/useItemData.test.ts: add unit tests covering missing/mismatched assets, existing referenced assets, unreferenced siblings, and missing content / TrackedMap lookups.
  • .changeset/fix-missing-initial-files-deletion.md: add patch changeset for @keystatic/core.

Addresses the missing-file GraphQL deletion failure (Symptom B) reported in #1627.

Validation

  • vitest run packages/keystatic/src/app/ packages/keystatic/src/form/field-assertions.test.ts packages/keystatic/src/form/fields/number/isAtStep.test.ts packages/keystatic/src/sha1/sha1.test.ts: 6 files passed, 34 tests passed
  • eslint packages/keystatic/src/app/useItemData.ts packages/keystatic/src/app/useItemData.test.ts: passed
  • prettier --check packages/keystatic/src/app/useItemData.ts packages/keystatic/src/app/useItemData.test.ts .changeset/fix-missing-initial-files-deletion.md: passed
  • preconstruct validate: passed

@changeset-bot

changeset-bot Bot commented Nov 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1853453

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@keystatic/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant