fix(tiptap): preserve YAML array-of-objects component props in round-trip#485
Open
hendrikheil wants to merge 2 commits into
Open
fix(tiptap): preserve YAML array-of-objects component props in round-trip#485hendrikheil wants to merge 2 commits into
hendrikheil wants to merge 2 commits into
Conversation
…trip
## Root cause (two bugs)
**1. `propsMDCToComark` didn't unwrap `@nuxtjs/mdc` binding-syntax props**
`@nuxtjs/mdc` serialises non-primitive YAML block props (arrays of objects)
as Vue binding syntax — key `:authorsOne` with a JSON-stringified string
value `"[{\"name\":\"John\"}]"`. `propsMDCToComark` passed these through
unchanged, so the entire pipeline carried a JSON string instead of a real
array. This is the actual root cause of the inline-JSON corruption on save.
**2. `normalizeProps` was built on a "all props are strings" assumption**
`String(value).trim()` on every prop value was both wrong for complex values
and unnecessary — comark attrs are already the correct type and comark's
renderer handles numbers, booleans, arrays, and objects natively.
## Fixes
- `legacy.ts` — `propsMDCToComark`: detect `:key` binding props and
JSON.parse their values back to real JavaScript, stripping the `:` prefix.
- `props.ts` — `normalizeProps`: rewritten to pass values through untouched,
returning `ComarkElementAttributes` (the real domain type) directly instead
of `Array<[string, unknown]>`. Key trimming and empty-key filtering are
kept — they guard against user-typed custom props from the form editor.
- `tiptapToComark.ts`: both call sites updated, `Object.fromEntries` removed.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
@hendrikheil is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Editing a component with YAML block array-of-objects props in Studio corrupts them on save:
becomes:
::authors{:authorsOne="[{"name":"John Doe","role":"contributor"}]"} ::Closes #457. Supersedes #477.
Root cause (two bugs)
1.
propsMDCToComarkdidn't unwrap@nuxtjs/mdcbinding-syntax props@nuxtjs/mdcserialises non-primitive YAML block props (arrays, objects) as Vue binding syntax — key:authorsOne(:prefix) with a JSON-stringified string value"[{\"name\":\"John\"}]". ThepropsMDCToComarkbridge inlegacy.tspassed these through unchanged, so the entire pipeline carried a JSON string instead of a real JavaScript array. When comark rendered the ComarkElement back to markdown, it emitted the inline binding form{:authorsOne="[...]"}— exactly the corruption seen in production.2.
normalizePropswas built on a "all props are strings" assumptionString(value).trim()on every prop value was wrong in principle. Comark attrs are already the correct type from the parser (stringfor inline attrs,number/boolean/array/objectfor YAML block attrs), and comark's renderer handles all these types natively. The stringification was a latent correctness bug even when it wasn't the immediate cause of corruption.Fix
legacy.ts—propsMDCToComark(root cause fix): detect:keybinding props produced by@nuxtjs/mdcandJSON.parsetheir values back to real JavaScript values, stripping the:prefix.props.ts—normalizeProps(type correctness): rewritten to pass values through untouched, returningComarkElementAttributesdirectly instead ofArray<[string, unknown]>. Key trimming and empty-key filtering are preserved — they guard against user-typed custom props from the form editor which may have stray whitespace.tiptapToComark.ts: both call sites updated —Object.fromEntries(propsArray)middleman removed sincenormalizePropsnow returns the attrs object directly.Test plan
normalizeProps: values pass through as their original type (number stays number, array stays array, null stays null); key trimming and empty-key filtering workpropsMDCToComark::keybindings are unwrapped to real JS values; full round-trip through the legacy bridge renders YAML block format, not inline JSON🤖 Generated with Claude Code