fix(richtext-lexical): prevent invalid h0 heading nodes when all heading sizes are disabled#16090
Merged
AlessioGr merged 1 commit intoMar 30, 2026
Conversation
…ing sizes are disabled When enabledHeadingSizes is an empty array, the markdown transformer regex becomes ^()\s which matches any leading whitespace and creates invalid h0 heading nodes that corrupt stored data. Skip registering the heading markdown transformer entirely when no heading sizes are enabled.
AlessioGr
approved these changes
Mar 30, 2026
Contributor
|
🚀 This is included in version v3.81.0 |
milamer
pushed a commit
to milamer/payload
that referenced
this pull request
Apr 20, 2026
…ing sizes are disabled (payloadcms#16090) ## What Fixes `HeadingFeature({ enabledHeadingSizes: [] })` creating invalid `h0` heading nodes that corrupt stored data. Closes payloadcms#15899 ## Why When `enabledHeadingSizes` is an empty array, the heading markdown transformer builds its regex from an empty alternation group: ``` pattern = "^()\\s" // matches ANY leading whitespace ``` This regex matches any line starting with a space or tab. The empty capture group produces `match[1] = ""`, so: ```js tag = 'h' + match[1]?.length // 'h' + 0 = 'h0' ``` An invalid `h0` heading node is created and persisted to the database. If the HeadingFeature is later removed, these nodes cause a runtime error (`parseEditorState: type "heading" not found`). ## Changes Skip registering the heading markdown transformer when `enabledHeadingSizes` is empty. No heading sizes enabled means no heading markdown shortcuts should be active. ## Testing - `npx tsc --noEmit` passes - Lint passes - With this fix, `HeadingFeature({ enabledHeadingSizes: [] })` registers zero markdown transformers, so no heading conversion can occur
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
Fixes
HeadingFeature({ enabledHeadingSizes: [] })creating invalidh0heading nodes that corrupt stored data.Closes #15899
Why
When
enabledHeadingSizesis an empty array, the heading markdown transformer builds its regex from an empty alternation group:This regex matches any line starting with a space or tab. The empty capture group produces
match[1] = "", so:An invalid
h0heading node is created and persisted to the database. If the HeadingFeature is later removed, these nodes cause a runtime error (parseEditorState: type "heading" not found).Changes
Skip registering the heading markdown transformer when
enabledHeadingSizesis empty. No heading sizes enabled means no heading markdown shortcuts should be active.Testing
npx tsc --noEmitpassesHeadingFeature({ enabledHeadingSizes: [] })registers zero markdown transformers, so no heading conversion can occur