fix(editor): persist and render text alignment on blocks#761
Open
drudge wants to merge 4 commits intoemdash-cms:mainfrom
Open
fix(editor): persist and render text alignment on blocks#761drudge wants to merge 4 commits intoemdash-cms:mainfrom
drudge wants to merge 4 commits intoemdash-cms:mainfrom
Conversation
Text alignment applied in the admin editor (center, right, justify) was silently dropped because the ProseMirror → Portable Text converter ignored node.attrs.textAlign, the type had no field for it, and the PortableText renderer emitted plain tags with no style. Alignment now round-trips through the converters and renders as inline text-align on paragraph, heading, and blockquote blocks.
🦋 Changeset detectedLatest commit: 26b3b61 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 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/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@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-forms
@emdash-cms/plugin-webhook-notifier
commit: |
drudge
added a commit
to drudge/emdash
that referenced
this pull request
Apr 24, 2026
The admin editor inlines its own copy of the ProseMirror ↔ Portable Text converter pair (PortableTextEditor.tsx), separate from the shared core converters. The prior commit patched core but missed the admin duplicate, so the editor was still dropping textAlign on save — alignment applied in the toolbar vanished on reload. Mirror the fix into the admin converters. A follow-up should delete the admin's inlined converters and import from core to eliminate this drift class.
drudge
added a commit
to drudge/emdash
that referenced
this pull request
Apr 24, 2026
…editor's PM ↔ PT round-trip
Contributor
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. |
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.
What does this PR do?
Fixes a bug where text alignment applied in the admin editor (center, right, justify) did not show up on the rendered site — and, on a closer review, also did not survive a reload in the editor itself. Reported case: select an
h1, click "Center" in the editor toolbar, save — the heading still renders left-aligned on the public page.The bug spanned two separate converter pairs plus the renderer:
Core (
packages/core)prosemirrorToPortableTextdroppednode.attrs.textAlignfor paragraphs and headings, so alignment never reached the database.PortableTextTextBlockhad notextAlignfield.portableTextToProsemirrornever restoredtextAlignonto the rehydrated node.emdashComponentshad noblockstyle renderer, soastro-portabletext's default emitted plain<p>/<h1>with no alignment applied.Admin (
packages/admin/src/components/PortableTextEditor.tsx)The admin editor inlines its own copy of the PM↔PT converter pair and a local
PortableTextTextBlocktype. Patching core alone was not enough — the admin still wrote blocks withouttextAlign, which is why alignment applied in the toolbar also vanished on reload. Mirrored the same fix in the admin's duplicates.Modeled as a top-level block property (consistent with how
style,listItem,level, and image dimensions are modeled; inline marks would be semantically wrong since alignment is block-level). The default"left"is normalized away on save so existing payloads stay byte-identical.Follow-up
The admin's inlined converter pair (~500 LOC) duplicates
packages/core/src/content/converters/*and caused the split-brain that motivated the second commit in this PR. A follow-up should delete the admin copies and import from core. That's a refactor, so it needs a prior Discussion per CONTRIBUTING.md and is out of scope for this bug fix.Closes #
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runpnpm locale:extracthas been run (if applicable)Translation checkbox N/A — no new admin UI strings. New-feature checkbox N/A — bug fix.
AI-generated code disclosure
Changesets
Two patch changesets since the fix spans two published packages:
.changeset/editor-text-alignment-render.md—emdash(core converter + renderer).changeset/admin-text-alignment-persist.md—@emdash-cms/admin(inlined-converter fix)Screenshots / test output
Rendered HTML from end-to-end verification (POST via API with
textAlignon anh1+p, thenGETthe public post page):The
h1is centered, thepis right-aligned, and the un-alignedphas no inline style — confirming the default is normalized away on save.Tests:
packages/core/tests/unit/converters/text-alignment.test.ts— 4 round-trip tests against the core converters.packages/admin/tests/editor/text-alignment.test.ts— 4 matching tests against the admin's exported_prosemirrorToPortableText/_portableTextToProsemirror.Core suite: 2,591/2,591 pass. Admin suite: 790/790 pass.