Skip to content

fix: render and edit consecutive blockquote blocks as one quote - #1905

Merged
ascorbic merged 2 commits into
emdash-cms:mainfrom
swissky:fix/blockquote-grouping
Jul 10, 2026
Merged

ascorbic merged 2 commits into
emdash-cms:mainfrom
swissky:fix/blockquote-grouping

Conversation

@swissky

@swissky swissky commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

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's core/quote transformer emits) is stored as consecutive blocks with style: "blockquote". Both consumers treated each block as its own quote:

  • portableTextToProsemirror created one blockquote node per block → the editor shows a single quote as several quotes. Merging them can never stick, because prosemirrorToPortableText (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.
  • The PortableText Astro 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:

  • Editor load (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.
  • Rendering (PortableText.astro): a run is pre-grouped into a synthetic blockquoteGroup node rendered by a new BlockquoteGroup.astro as one <blockquote> with a <p> per paragraph (following the nested-render pattern of Columns.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) and tests/unit/components/blockquote-group.test.ts (render-side grouping helper). Full core unit suite passes (232 files, 3108 tests).

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Cursor + Fable 5, reviewed and tested by me

Screenshots / test output

New regression tests plus full core unit suite: 232 files, 3108 tests passing locally.

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-bot

changeset-bot Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 80ff94f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

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

@github-actions github-actions Bot added area/core size/L review/needs-review No maintainer or bot review yet labels Jul 10, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1905

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1905

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@1905

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1905

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1905

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@1905

emdash

npm i https://pkg.pr.new/emdash@1905

create-emdash

npm i https://pkg.pr.new/create-emdash@1905

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1905

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@1905

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@1905

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@1905

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@1905

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@1905

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1905

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1905

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1905

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1905

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1905

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1905

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@1905

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1905

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1905

commit: 80ff94f

@swissky swissky added the bot:review Trigger an emdashbot code review on this PR label Jul 10, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-368

    This else branch dispatches every non-list block to convertPTBlock, which still creates one blockquote node per style: "blockquote" block. Because InlinePortableTextEditor.tsx defines its own portableTextToPM instead of using the updated core portableTextToProsemirror, 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.ts here, before falling through to convertPTBlock:

    		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.ts but using the inline editor's _portableTextToPM / _pmToPortableText exports 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.
@swissky

swissky commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

Good catch — fixed in 80ff94f. The inline visual editor's own portableTextToPM now applies the same run-grouping (consecutive style: "blockquote" blocks, excluding list items, become one blockquote node with a paragraph per block), and pmToPortableText already flattened multi-paragraph quotes back to consecutive PT blocks, so the round-trip is stable. Added inline-portable-text-blockquote.test.ts mirroring the core converter tests against the _portableTextToPM/_pmToPortableText seams — grouping, separation by other blocks, double round-trip stability, and the single-block case.

@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/needs-review No maintainer or bot review yet labels Jul 10, 2026
@ascorbic ascorbic added bot:review Trigger an emdashbot code review on this PR and removed bot:review Trigger an emdashbot code review on this PR labels Jul 10, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.tsx now groups a run of style: "blockquote" / no-listItem blocks into a single ProseMirror blockquote node with one paragraph per block, matching the core converter.
  • A new regression test at packages/core/tests/unit/components/inline-portable-text-blockquote.test.ts exercises 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.ts correctly produces a blockquoteGroup node 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.astro renders grouped runs as one <blockquote> with <p> per paragraph, using shared Block / mark components.
  • PortableText.astro applies the grouping only on the non-edit render path (edit mode delegates to InlineEditor with the raw value, and the editor itself now groups on load).
  • packages/core/src/content/converters/portable-text-to-prosemirror.ts groups blockquote runs the same way.
  • Component registration in packages/core/src/components/index.ts and the changeset targeting emdash are 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.

@github-actions

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-rereview New commits since the last review labels Jul 10, 2026
@ascorbic
ascorbic merged commit e12f393 into emdash-cms:main Jul 10, 2026
45 checks passed
@emdashbot emdashbot Bot mentioned this pull request Jul 10, 2026
@swissky
swissky deleted the fix/blockquote-grouping branch September 10, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core bot:review Trigger an emdashbot code review on this PR review/approved Approved; no new commits since size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blockquote splits into multiple blocks on import/reload

2 participants