fix: ignore cosmetic key-order drift in model comparisons#172
Merged
angeloashmore merged 5 commits intomainfrom May 2, 2026
Merged
fix: ignore cosmetic key-order drift in model comparisons#172angeloashmore merged 5 commits intomainfrom
angeloashmore merged 5 commits intomainfrom
Conversation
The Prismic API returns model JSON with metadata keys in a different order than we write them locally. This caused push/pull/status to flag purely cosmetic differences as updates, blocking subsequent pushes via the dirty-tree check until the user committed a no-op pull. Canonicalize models before diffing: sort keys by default, but preserve insertion order inside containers where it carries meaning (tab order under \`json\`, field order inside tabs and inside variation \`primary\`/\`items\`/\`fields\`). Fixes #170 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the orderedDepth integer with three named conditions: isFieldMap, isTabMap, isTabObject. Mirrors the model shape directly (\`json\` is a tab map; tab values are field maps; \`primary\`/\`items\`/ \`fields\` are field maps). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the recursive walker with two flat sorts: model's top-level keys, and each variation's top-level keys. The API only reorders these metadata keys; everything inside (\`json\`, \`primary\`, etc.) is left untouched, preserving the editor-significant order naturally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6e0c2f1. Configure here.
\`diffArrays\` returns items from its source array, so canonicalizing the inputs caused the key-sorted copies to flow through to the \`insertCustomType\`/\`updateSlice\`/etc. write paths in push and pull. Add an optional \`equals\` option to \`diffArrays\` and pass the canonicalize-then-stringify comparator from each call site. Originals are passed in unchanged, so writes get the user-authored objects. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Resolves: #170
Description
prismic pushandprismic pullwrite model JSON in different key orders, so after a successful push,prismic statusreports types and slices as "Differ" indefinitely — and the git-dirty safety check then blocks the next push until the user commits a cosmetic-only pull.Root cause:
diffArrayscompares withJSON.stringify, which is key-order sensitive. The API returns top-level model keys, top-level slice keys, and slice variation keys in a different order than we author them, but those keys have no semantic meaning.This change normalizes models before diffing — sort keys by default, but preserve insertion order inside containers where order is meaningful in the editor (
jsonfor tab order and field order within tabs, andprimary/items/fieldsfor field order within variations and groups). Disk content is untouched.Checklist
Preview
How to QA
prismic type create "Announcement"prismic field add uid --to-type announcementprismic field add text message --to-type announcement --label "Message"git add . && git commit -m "add announcement type"prismic push→ reports the type as pushed.prismic status→ should report "Already up to date." (previously reported "Differ").prismic pull→ should report "Already up to date." (previously rewrote the local file with reordered keys).prismic field reorderand confirmprismic statusstill detects the change.Need help on this PR? Tag
@codesmithwith what you need.Note
Medium Risk
Changes the equality logic used by
prismic push/pull/statusto decide whether models differ; an overly-aggressive canonicalization could cause real schema changes to be missed or reduce visibility of differences.Overview
Model diffs are now key-order insensitive.
diffArraysgains an optionalequalscomparator, andpush,pull, andstatuspass a comparator that comparescanonicalizeModel()output rather than rawJSON.stringify.Adds
canonicalizeModel()inmodels.tsto normalize custom type and slice models (including per-variation objects) by sorting object keys before comparison, reducing cosmetic-only churn and repeated “Differ” status after successful syncs.Reviewed by Cursor Bugbot for commit 99a29dc. Bugbot is set up for automated code reviews on this repo. Configure here.