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

v3 - proper slug change validation #698

Merged
merged 2 commits into from
Sep 27, 2024
Merged

Conversation

mathiazom
Copy link
Contributor

@mathiazom mathiazom commented Sep 20, 2024

See #696

The originally approach to prevent slug changes after publication was too naive. It only checked if the current document was a draft or not. This meant that the slug could be changed for a published document by first changing a different field (e.g. the page title), and then change the slug field.

The new approach relies on validation to perform a client fetch to check if a published document exists with the same id (without the drafts. prefix) with a different slug. This is less clear than the readonly state, but the readonly property does not seem to allow async.

image

Checklist

Please ensure that you’ve completed the following checkpoints before submitting your pull request:

  • Documentation: Relevant documentation has been added or updated (if applicable).
  • Testing: Have you tested your changes thoroughly?

Copy link

vercel bot commented Sep 20, 2024

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

Name Status Preview Comments Updated (UTC)
variant-no ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 23, 2024 10:37am
variant-se-2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 23, 2024 10:37am

@@ -1,5 +1,6 @@
import { SlugValidationContext, defineField } from "sanity";
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is starting to look a little bloated, and we've got a lot of if, else, and, or. Do we have time to clean it up for easier dev experience upon handoff?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted the validation logic into a separate utility function now. We could also move it to a different file if you want.

@mathiazom mathiazom merged commit 6ae8f10 into v3 Sep 27, 2024
6 checks passed
@mathiazom mathiazom deleted the feat/v3-proper-slug-change-check branch September 27, 2024 07:42
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.

3 participants