Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sanity): use optimistic locking when publishing documents #6711

Merged
merged 3 commits into from
May 22, 2024

Conversation

juice49
Copy link
Contributor

@juice49 juice49 commented May 17, 2024

Description

This branch adds optimistic locking when publishing documents via the Actions API by adopting its ifDraftRevisionId and ifPublishedRevisionId guards. These guards are a recent addition to the Actions API.

Optimistic locking ensures the editor can see the latest state of both the draft document they are publishing, and the published document they are choosing to replace.

Additionally, this branch adds a check prior to publishing that ensures Studio has a draft snapshot. This check is already in place when publishing via the Mutations API. It stands to reason that the editor must be able to see the draft they are choosing to publish.

What to review

Is the usage of the ifDraftRevisionId and ifPublishedRevisionId guards correct?

Testing

  • I've copied the existing unit tests from the Mutations API based publish operation to the Actions API based publish operation.
  • These tests use snapshots to ensure the expected revision guards are used.
  • I've added a test to ensure execute throws if the client has no draft snapshot.
  • You can find these tests in packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/publish.test.ts.

Copy link

vercel bot commented May 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 17, 2024 11:48am
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 17, 2024 11:48am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 17, 2024 11:48am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 11:48am

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented May 17, 2024

Component Testing Report Updated May 17, 2024 11:53 AM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 35s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 25s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 31s 11 7 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 14s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 36s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 16s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 3s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 6s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 20s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 14s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 30s 12 0 0

Copy link
Member

@bjoerge bjoerge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@juice49 juice49 added this pull request to the merge queue May 22, 2024
Merged via the queue into next with commit 6fe8c69 May 22, 2024
39 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