Repository navigation
Add defaultTextBlockStyles option to createTipTapRichTextBlock - #6366
Closed
VPS-Andreas wants to merge 3 commits into
Closed
VPS-Andreas wants to merge 3 commits into
VPS-Andreas wants to merge 3 commits into
Conversation
The text block style dropdown always offered an unstyled "Default" entry next to the configured textBlockStyles, even for a tag where every instance should always carry one of them, unlike the Draft.js RTE's standardBlockType, which had no such state for the block types it covered. defaultTextBlockStyles assigns a default style per tag instead: no "Default" entry is offered for it, a newly created or converted heading/paragraph of that tag gets the style automatically, and the API rejects stored content of that tag missing a style. migrateFromDraftJs falls back to the configured default when a mapped Draft.js block doesn't specify a textBlockStyle. A tag without an entry keeps today's behavior. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
A block migration running after migrateFromDraftJs's DraftJS->TipTap conversion (e.g. one remapping heading levels, like the demo's Heading1ToHeading2Migration) could leave a node missing its default style, since only the DraftJS conversion step resolved defaultTextBlockStyles, against the tag/level a node had at that point. Found by migrating old DraftJS demo data through the pipeline. Always append a migration that fills in any default still missing once every other migration has applied, so the guarantee holds regardless of what happens in between. Wire defaultTextBlockStyles into the demo's TipTapRichTextBlock to dogfood the option. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
VPS-Andreas
force-pushed
the
tiptap-default-text-block-style
branch
from
September 15, 2026 08:18
49bb724 to
ad3f166
Compare
2 of 3 tasks
Contributor
|
What do you think about this alternative API? createTipTapRichTextBlock({
textBlockStyles: [
{ name: "copy100", appliesTo: ["paragraph"], defaultFor: ["paragraph"] },
{ name: "copy200", appliesTo: ["paragraph"] },
{ name: "headline300", appliesTo: ["heading-2"], defaultFor: ["heading-2"] },
],
}); |
Contributor
Author
|
One case worth checking this against: a style that should be the default for several tags, e.g. With { name: "copy100", appliesTo: ["paragraph", "heading-2"], defaultFor: ["paragraph", "heading-2"] }And nothing stops two different style entries from both claiming With defaultTextBlockStyles: {
paragraph: "copy100",
"heading-2": "copy100",
},Since it's a |
VPS-Andreas
marked this pull request as ready for review
September 15, 2026 12:51
The defaultTextBlockStyles safety-net migration only filled in a missing textBlockStyle. A node whose tag changed after the style was already set (e.g. a heading level bump by a later migration) kept its old style even when that style's appliesTo no longer covers the new tag, breaking the guarantee that a valid default is always applied. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
VPS-Obi
marked this pull request as draft
September 16, 2026 07:53
VPS-Obi
removed their request for review
September 16, 2026 07:53
Contributor
Author
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.
Summary
The text block style dropdown always offered an unstyled
Defaultentry next to the configuredtextBlockStyles, even for a tag where every instance should always carry one of them, unlike the Draft.js RTE'sstandardBlockType, which had no such state for the block types it covered.defaultTextBlockStylesassigns a default style per tag instead: noDefaultentry is offered for it, a newly created or converted heading/paragraph of that tag gets the style automatically, and the API rejects stored content of that tag missing a style.migrateFromDraftJsfalls back to the configured default when a mapped Draft.js block doesn't specify atextBlockStyle. A tag without an entry keeps today's behavior.A migration that runs after
migrateFromDraftJs(for instance one that changes a node's heading level) can leave a node missing its default style, or carrying a style that no longer applies to its new tag, since earlier steps only resolvedefaultTextBlockStylesagainst the tag a node has at that point. A migration is now always appended last to fill in any default still missing, or swap in the default for a style that no longer applies, once every other migration — including a block's own — has applied, so the guarantee holds regardless of what happens in between.This replaces #6225 (
requireTextBlockStyle, a single boolean forcing every applicable tag to require a style, with an implicit "first-in-array-wins" default) and #6004 (defaultTextBlockStyleLabel, a cosmetic rename of the "Default" entry) with one explicit, per-tag mapping — both had grown unclear in scope. Built on top of #6240 (heading-only blocks), now merged.Example
Test plan
tscandeslintpass for both packagesblocks/TipTapRichTextBlock→ "Default Text Block Styles") verified interactively via Playwright — initial default applied, noDefaultentry for tags with a default, auto-assign on type switch,Defaultstill offered for a tag without a configured default: https://69df3371c46abe69b5199825-nuucasmmou.chromatic.com/?path=/story/blocks-tiptaprichtextblock--default-text-block-stylesmigrateBlocksagainst the demo's Draft.js fixture data, and covered by 4 new tests inbuildApplyDefaultTextBlockStylesMigration.test.ts, including a node whose tag change (via a later migration) makes its already-set style inapplicablemainnow that cms-admin: Fix invalid DOM nesting in textBlockStyles node views #6363 and cms-admin: Don't insert a trailing paragraph after a heading #6364 (the two independent TipTap bugfixes found while testing this) are merged🤖 Generated with Claude Code