Repository navigation
fix: render and edit consecutive blockquote blocks as one quote - #1905
Conversation
Portable Text is flat, so a multi-paragraph <blockquote> (e.g. from a WordPress core/quote import) is stored as consecutive blocks with style "blockquote". Both consumers treated each block as its own quote: - portableTextToProsemirror created one blockquote node per block, so the editor showed a single quote as several disconnected quotes, and merging them reverted on reload (prosemirrorToPortableText correctly serializes a multi-paragraph quote back to consecutive blocks). - The PortableText component rendered one <blockquote> element per block on the public site. Group consecutive blockquote-styled blocks in both places: the editor converter merges a run into a single blockquote node with one paragraph per block, and the renderer merges a run into a synthetic blockquoteGroup node rendered as one <blockquote>. Single-block quotes render byte-for-byte as before; quote-styled list items keep belonging to their list. Fixes emdash-cms#1884
🦋 Changeset detectedLatest commit: 80ff94f The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
The approach is sound: Portable Text is flat, so treating a run of style: "blockquote" blocks as a single quote on load and on render is the right fix for #1884. The render-side grouping helper and BlockquoteGroup.astro look correct, and the core portableTextToProsemirror converter change is clean and well-tested.
However, EmDash has two PT⇄PM converters. The PR updates the one in packages/core/src/content/converters/portable-text-to-prosemirror.ts (used by the admin editor), but the inline visual editor (packages/core/src/components/InlinePortableTextEditor.tsx) keeps its own portableTextToPM / pmToPortableText implementation. That converter still turns every style: "blockquote" block into its own blockquote node, so on-site visual editing still exhibits the exact "merge reverts on reload" behaviour the PR claims to fix. The inline editor is what PortableText.astro renders when editMeta is present, so this is a real gap.
I also looked for SQL/route/locale/i18n/changeset issues — none apply here (this is front-end rendering/conversion code), and the changeset correctly targets the emdash package.
Findings
-
[needs fixing]
packages/core/src/components/InlinePortableTextEditor.tsx:357-368This
elsebranch dispatches every non-list block toconvertPTBlock, which still creates oneblockquotenode perstyle: "blockquote"block. BecauseInlinePortableTextEditor.tsxdefines its ownportableTextToPMinstead of using the updated coreportableTextToProsemirror, the inline visual editor does not get the blockquote-run grouping fix. Multi-paragraph quotes loaded in the on-site editor still split into separate quotes, and any merge reverts on reload.Apply the same run-grouping logic used in
packages/core/src/content/converters/portable-text-to-prosemirror.tshere, before falling through toconvertPTBlock:if (isPTTextBlock(block) && block.listItem) { const listBlocks: PTTextBlock[] = []; const listType = block.listItem; while (i < blocks.length) { const cur = blocks[i]; if (cur && isPTTextBlock(cur) && cur.listItem === listType) { listBlocks.push(cur); i++; } else break; } content.push(convertPTList(listBlocks, listType)); } else if ( isPTTextBlock(block) && block.style === "blockquote" && block.listItem === undefined ) { const quoteBlocks: PTTextBlock[] = []; while (i < blocks.length) { const cur = blocks[i]; if ( !cur || !isPTTextBlock(cur) || cur.style !== "blockquote" || cur.listItem !== undefined ) { break; } quoteBlocks.push(cur); i++; } content.push({ type: "blockquote", content: quoteBlocks.map((quoteBlock) => { const pmContent = convertPTSpans(quoteBlock.children, quoteBlock.markDefs || []); return { type: "paragraph", content: pmContent.length > 0 ? pmContent : undefined, }; }), }); } else { const c = convertPTBlock(block); if (c) content.push(c); i++; }Then add a regression test mirroring
tests/unit/converters/blockquote-grouping.test.tsbut using the inline editor's_portableTextToPM/_pmToPortableTextexports to prove the PT → PM → PT round-trip is stable for the visual editor too.
The inline editor keeps its own PT<->PM converter, so the grouping fix in the core converter didn't reach on-site visual editing — multi- paragraph quotes still split there and merges reverted on reload.
|
Good catch — fixed in 80ff94f. The inline visual editor's own |
There was a problem hiding this comment.
The approach is sound: Portable Text is flat, so treating a run of style: "blockquote" blocks as a single quote on load and on render is the right fix for #1884.
This is a re-review. The prior blocking finding — that the on-site inline visual editor kept its own portableTextToPM / pmToPortableText implementation and still split consecutive quote blocks — has been resolved:
packages/core/src/components/InlinePortableTextEditor.tsxnow groups a run ofstyle: "blockquote"/ no-listItemblocks into a single ProseMirrorblockquotenode with oneparagraphper block, matching the core converter.- A new regression test at
packages/core/tests/unit/components/inline-portable-text-blockquote.test.tsexercises the PT → PM → PT round-trip for the inline editor seam, so merges no longer revert on reload there either.
I re-checked every changed hunk:
portable-text-blockquote-group.tscorrectly produces ablockquoteGroupnode for runs of two or more quote-styled text blocks, leaves single blocks and quote-styled list items untouched, and preserves non-quote blocks as-is.BlockquoteGroup.astrorenders grouped runs as one<blockquote>with<p>per paragraph, using sharedBlock/ mark components.PortableText.astroapplies the grouping only on the non-edit render path (edit mode delegates toInlineEditorwith the raw value, and the editor itself now groups on load).packages/core/src/content/converters/portable-text-to-prosemirror.tsgroups blockquote runs the same way.- Component registration in
packages/core/src/components/index.tsand the changeset targetingemdashare in place. - No SQL, route, locale, i18n, or authorization concerns apply here — this is front-end rendering/conversion code.
No remaining blocking or correctness issues found. LGTM.
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
What does this PR do?
Fixes a multi-paragraph blockquote splitting into multiple disconnected quotes — both on the rendered site and in the editor, where merging the blocks reverted on reload.
Closes #1884
Root cause: Portable Text is flat, so a multi-paragraph
<blockquote>(which is exactly what the Gutenberg importer'score/quotetransformer emits) is stored as consecutive blocks withstyle: "blockquote". Both consumers treated each block as its own quote:portableTextToProsemirrorcreated one blockquote node per block → the editor shows a single quote as several quotes. Merging them can never stick, becauseprosemirrorToPortableText(correctly) serializes a multi-paragraph quote node back into consecutive flat blocks — the next editor load split them again. This is the "merge reverts on reload" behaviour from the issue.PortableTextAstro component rendered one<blockquote>element per block → the split HTML shown in the issue report.Fix: treat a run of consecutive blockquote-styled blocks as one quote in both places:
portableTextToProsemirror): a run merges into a single blockquote node with one paragraph per block. The PT → PM → PT round-trip is now stable, so editor merges survive reloads.PortableText.astro): a run is pre-grouped into a syntheticblockquoteGroupnode rendered by a newBlockquoteGroup.astroas one<blockquote>with a<p>per paragraph (following the nested-render pattern ofColumns.astro).Behaviour is deliberately conservative: single-block quotes are left untouched and render byte-for-byte as before, quote-styled list items keep belonging to their list, and runs separated by any other block stay separate quotes. No stored content changes — this only fixes how the existing canonical representation is loaded and rendered.
Tested with new regression tests in
tests/unit/converters/blockquote-grouping.test.ts(run merging, non-adjacent runs staying separate, PT → PM → PT round-trip stability — the "merge reverts on reload" repro — and list-item exclusion) andtests/unit/components/blockquote-group.test.ts(render-side grouping helper). Full core unit suite passes (232 files, 3108 tests).Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
New regression tests plus full core unit suite: 232 files, 3108 tests passing locally.