This repository was archived by the owner on May 28, 2026. It is now read-only.
fix: guard against invalid orderRank data to prevent studio crashes#126
Merged
Conversation
When an `orderRank` field contains invalid or corrupted data (non-string values, malformed lexorank strings), the LexoRank parser would throw an unhandled error and crash the studio. Changes: - New: Created `parseOrderRank()` helper in `src/helpers/parseOrderRank.ts` that safely parses LexoRank strings with try-catch error handling and configurable fallback values - Updated: `reorderDocuments.ts` to use `parseOrderRank()` when accessing rank values from entities - Updated: `initialRank.ts` to use `parseOrderRank()` when generating initial ranks - Added: Console warnings when invalid orderRank data is encountered to help users identify corrupted documents - Tests: Unit tests for `parseOrderRank()` covering valid parsing, non-string values, and parse failures. Regression tests for `reorderDocuments` and `initialRank` with bad data. All 14 tests passing. Behavior: - Invalid `orderRank` values now gracefully fall back to safe defaults (`LexoRank.min()` or `LexoRank.max()`) - Console warnings appear when bad data is encountered: `[orderable-document-list] Invalid orderRank value...` - Studio remains stable and functional even with corrupted data - Users can query `*[_type == "yourType" && !isString(orderRank)]` to find and fix corrupted documents Closes sanity-io#89
Contributor
Author
|
Note there was code in the DocumentListWrapper to try and stop the display of everything when a string was found -- but it never got there because of 'when' in the load order the plugin was firing.
|
stipsan
approved these changes
Jan 23, 2026
stipsan
left a comment
Member
There was a problem hiding this comment.
Thank you! This is a great find 💖
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
When an
orderRankfield contains invalid or corrupted data (non-string values, malformed lexorank strings), the LexoRank parser would throw an unhandled error and crash the studio.Changes:
parseOrderRank()helper insrc/helpers/parseOrderRank.tsthat safely parses LexoRank strings with try-catch error handling andconfigurable fallback values
reorderDocuments.tsto useparseOrderRank()when accessingrank values from entities
initialRank.tsto useparseOrderRank()when generatinginitial ranks
help users identify corrupted documents
parseOrderRank()covering valid parsing, non-string values, and parse failures. Regression tests forreorderDocumentsandinitialRankwith bad data. All 14 tests passing.Behavior:
orderRankvalues now gracefully fall back to safe defaults(
LexoRank.min()orLexoRank.max())[orderable-document-list] Invalid orderRank value...*[_type == "yourType" && !isString(orderRank)]to find and fix corrupted documentsCloses #89
Description
What to review
Testing