Skip to content

fix: coerce non-string da-metadata values to avoid "[object Object]"#933

Draft
chrischrischris wants to merge 1 commit into
mainfrom
claude/musing-shaw-35684b
Draft

fix: coerce non-string da-metadata values to avoid "[object Object]"#933
chrischrischris wants to merge 1 commit into
mainfrom
claude/musing-shaw-35684b

Conversation

@chrischrischris
Copy link
Copy Markdown
Contributor

Summary

  • setDaMetadata is the single boundary into the daMetadata Y.Map, but it forwarded values verbatim. doc2aem later interpolates each value into <div>${value}</div>, so any non-string entry (object, Y type) ends up serialized as the literal string [object Object] in saved HTML — observed in the wild as:
    <div class="da-metadata"><div><div>acceptedhashes</div><div>[object Object]</div></div><div><div>rejectedhashes</div><div>[object Object]</div></div></div>
  • Coerce at the boundary: stringify objects via JSON.stringify, other non-strings via String(), and console.warn so the offending caller is visible in dev tools next time it happens.
  • Added two unit tests covering object and primitive coercion.

Notes for reviewers

  • I couldn't pinpoint which call site is producing non-string values. Every in-tree caller (addToHashMetadata and the version-restore loop in da-editor.js) already passes strings, and the lowercase keys (acceptedhashes/rejectedhashes) in the observed HTML don't match our ACCEPTED_KEY/REJECTED_KEY constants (acceptedHashes/rejectedHashes) — so the corrupt entries likely came from outside setDaMetadata entirely. The new console.warn should help surface the source.
  • A companion defensive fix is also worth doing in da-parser's doc2aem (parser.js:753), which neither stringifies nor HTML-escapes the keys/values. Happy to put up a PR there as a follow-up.

Test plan

  • npx web-test-runner test/unit/blocks/edit/utils/helpers.test.js — 64 passing, including new coercion tests.
  • Reproduce the original symptom (a corrupted doc with [object Object] in da-metadata), open it in da-live, edit, save, and confirm no new [object Object] rows are written.

🤖 Generated with Claude Code

setDaMetadata is the single boundary into the daMetadata Y.Map, but it
forwarded values verbatim. doc2aem later interpolates each value into a
<div>${value}</div>, so any non-string entry (object, Y type) ended up
serialized as the literal string "[object Object]" in saved HTML.

Coerce at the boundary: stringify objects via JSON.stringify, other
non-strings via String(), and warn so the offending caller surfaces.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@aem-code-sync
Copy link
Copy Markdown

aem-code-sync Bot commented May 13, 2026

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

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.

1 participant