Skip to content

cleanDataKeys: seo object deleted entirely when title/description are redundant, losing keywords #401

@pballhausen

Description

@pballhausen

cleanDataKeys() in schema.ts deletes the entire seo object when seo.title/seo.description match the top-level fields - silently discarding seo.keywords and any other nested properties.

Reproduction

---
title: My Post
description: A summary.
seo:
  title: My Post
  description: A summary.
  keywords:
    - example
    - seo
---

After Studio saves → seo is completely gone, keywords lost.

Root cause

// schema.ts – cleanDataKeys()
if (
  (!seo.title || seo.title === document.title)
  && (!seo.description || seo.description === document.description)
) {
  Reflect.deleteProperty(result, 'seo') // deletes keywords too
}

Question: should cleanDataKeys modify user data at all?

The "optimization" of removing redundant seo.title/seo.description is arguably not the serializer's job. The user explicitly put those values there — keeping them is safe, removing them risks data loss (as demonstrated). A content formatter should preserve what the user wrote, not silently decide what's redundant.

If stripping is desired, the minimal safe fix would be to only strip individual redundant fields, never the whole object:

const seo = { ...(document.seo as Record<string, unknown>) }
if (!seo.title || seo.title === document.title) delete seo.title
if (!seo.description || seo.description === document.description) delete seo.description
if (Object.keys(seo).length === 0) {
  Reflect.deleteProperty(result, 'seo')
} else {
  result.seo = seo
}

But the safest approach would be to not strip anything from seo and let the data stay as-is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions