Skip to content

Conversation

Copy link

Copilot AI commented Sep 25, 2025

Problem

The slug field was automatically regenerating from the post title on every edit, which is detrimental to SEO because it breaks existing URLs and causes 404 errors for previously indexed content. This behavior differs from WordPress and other CMS platforms where slugs are set once during creation and preserved on subsequent edits.

Root Cause

The SlugComponent.tsx contained a useEffect hook that would update the slug whenever the title field changed, regardless of whether it was a new or existing post. While the backend formatSlugHook had the correct logic to only generate slugs for new posts, the frontend component was overriding this behavior.

Solution

Modified the slug component to implement WordPress-like behavior by:

  1. Tracking document state using a hasSeenNonEmptySlug ref to distinguish between new and existing documents
  2. Preserving existing slugs by only auto-generating when:
    • The document has never had a slug (new document), OR
    • The current slug is empty (user manually cleared it)
  3. Maintaining existing functionality for manual slug editing and lock/unlock behavior

Example Behavior

Before (problematic):

1. Create post with title "My First Post" → slug: "my-first-post" ✓
2. Edit title to "My Updated Post" → slug: "my-updated-post" ❌ (breaks SEO)

After (fixed):

1. Create post with title "My First Post" → slug: "my-first-post" ✓
2. Edit title to "My Updated Post" → slug: "my-first-post" ✓ (preserved)

Testing

The fix has been validated through comprehensive test scenarios covering:

  • New post creation with auto-slug generation
  • Existing post title edits preserving slugs
  • Manual slug clearing and regeneration
  • Lock/unlock functionality
  • Edge cases with empty titles and slugs

All existing functionality remains intact while fixing the core SEO issue.

Original prompt

This section details on the original issue you should resolve

<issue_title>bug: slug changes on every post's title edit</issue_title>
<issue_description>Changing slugs is highly detrimental to SEO because the old slug will return a 404 error. In WordPress, when you first set a title, it will be used as the slug, and subsequent changes will not modify the slug.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #5

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 3 commits September 25, 2025 20:33
Co-authored-by: gioruu <121963326+gioruu@users.noreply.github.com>
Co-authored-by: gioruu <121963326+gioruu@users.noreply.github.com>
Co-authored-by: gioruu <121963326+gioruu@users.noreply.github.com>
Copilot AI changed the title [WIP] bug: slug changes on every post's title edit Fix slug auto-generation to preserve existing slugs on title edits Sep 25, 2025
Copilot AI requested a review from gioruu September 25, 2025 20:46
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.

bug: slug changes on every post's title edit

2 participants