Skip to content

fix: retry creating an entry when an unrelated commit moved the branch head - #1653

Merged
emmatown merged 1 commit into
Thinkmill:mainfrom
colingreig:fix/create-retry-stale-data
Nov 17, 2026
Merged

emmatown merged 1 commit into
Thinkmill:mainfrom
colingreig:fix/create-retry-stale-data

Conversation

@colingreig

@colingreig colingreig commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When saving hits STALE_DATA, useUpsertItem retries only if the entry's tree key is unchanged. For a create, currentLocalTreeKey is undefined while getTreeKey(...) always returns a string, so the comparison never matched and every create after an unrelated commit showed "This entry has been updated since it was opened".

With no local tree key, the remote key is now compared against the key of an absent entry:

-if (treeKey === args.currentLocalTreeKey) {
+const expectedTreeKey =
+  args.currentLocalTreeKey ?? getTreeKey(directoriesForTreeKey, new Map());
+if (treeKey === expectedTreeKey) {

A create retries when the entry (and its asset directories) still don't exist on the new head, and still shows the dialog if the same slug was created meanwhile. The retry uses the checked head as expectedHeadOid, so a further head move surfaces an error instead of overwriting.

CreateItemLocal and CreateItemCollab both pass currentLocalTreeKey: undefined into useUpsertItem, so both get the fix.

Tests

New packages/keystatic/src/app/updating.test.tsx (hook-level, mocked GitHub/urql layer):

  • create after an unrelated commit retries (fails before the fix)
  • create whose slug exists remotely shows the dialog
  • head moves again between the check and the retry: error, no overwrite (fails before the fix)
  • edit, entry unchanged: retries
  • edit, entry changed: dialog

Before the fix: 2 failed, 3 passed. After: 5 passed. Full keystatic vitest project: 58 files, 707 passed, 8 skipped. eslint, prettier and tsc clean. Includes a patch changeset for @keystatic/core.

Refs #1626

@colingreig
colingreig requested a review from emmatown as a code owner November 4, 2026 17:37
@changeset-bot

changeset-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 344f062

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

@colingreig

Copy link
Copy Markdown
Contributor Author

Bump on this. It fixes #1626 for any repo where bot or CI commits land while an editor has the Add page open.

Details:
The create path passes currentLocalTreeKey as undefined, so a create never retries after a STALE_DATA response. Any unrelated commit to the branch then shows the "This entry has been updated since it was opened" dialog. This PR compares against the absent-entry tree key instead. Tests cover create, edit, a real conflict and a head that moves again before the retry.

Locally the suite passes (707 passed, 8 skipped). CI for fork PRs is waiting on a maintainer to approve the workflow run.

Could someone approve the run and take a look? Happy to change anything.

Thanks!

@emmatown
emmatown merged commit e66c1b8 into Thinkmill:main Nov 17, 2026
13 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 17, 2026
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.

Creating an entry always fails with "This entry has been updated since it was opened" after any unrelated commit (GitHub mode)

2 participants