Skip to content

fix: update stale relation snapshots on entity re-fetch#21

Merged
vparys merged 5 commits intomainfrom
fix/stale-relation-snapshots
Apr 16, 2026
Merged

fix: update stale relation snapshots on entity re-fetch#21
vparys merged 5 commits intomainfrom
fix/stale-relation-snapshots

Conversation

@vparys
Copy link
Copy Markdown
Member

@vparys vparys commented Apr 16, 2026

Summary

  • HasOne/HasMany handles previously skipped child snapshot updates when the entity already existed in the store, causing stale data after navigation (e.g. list → detail page)
  • Now compares embedded data against serverData (not data, to preserve local mutations) and updates when changed
  • RelationStore.getOrCreateHasMany also updates serverIds when called with new values
  • Extracts shared embeddedDataMatchesSnapshot to BaseHandle to avoid duplication

Test plan

  • Unit tests for HasOne stale data after re-fetch
  • Unit tests for HasMany stale serverIds and item data after re-fetch
  • Unit tests for list → detail navigation scenario
  • Existing tests pass (bun test)

vparys and others added 5 commits April 16, 2026 09:11
HasOne/HasMany handles previously skipped child snapshot updates when
the entity already existed in the store, causing stale data after
navigation (e.g. list → detail). Now compares embedded data against
serverData and updates when changed. RelationStore.getOrCreateHasMany
also updates serverIds when called with new values.
Remove duplicate function from HasOneHandle and HasManyListHandle,
export single shared copy from BaseHandle.
…riting committed state

After a persist (commit), re-rendering handles would read stale embedded
data from the parent snapshot and overwrite the just-committed child state.
Track the last propagated data reference per parent+field in SnapshotStore
and only propagate when the reference changes (i.e. parent was re-fetched).
mapTempIdToPersistedId was not rekeying the propagation tracking map,
causing hasEmbeddedDataChanged to return true after rekey and overwrite
committed child state with stale embedded data from the parent snapshot.
…with same data

Add embeddedDataMatchesSnapshot guard to HasOneHandle.ensureRelatedEntitySnapshot,
matching the existing protection in HasManyListHandle. Without this, a parent
re-fetch with unchanged server data (e.g. polling) creates a new object reference
that passes the hasEmbeddedDataChanged check and overwrites unpersisted local
mutations on the child entity.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vparys vparys merged commit ab2a113 into main Apr 16, 2026
3 checks passed
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.

2 participants