Skip to content

fix(richtext-lexical): prevent invalid h0 heading nodes when all heading sizes are disabled#16090

Merged
AlessioGr merged 1 commit into
payloadcms:mainfrom
mahmoodhamdi:fix/lexical-heading-empty-sizes
Mar 30, 2026
Merged

fix(richtext-lexical): prevent invalid h0 heading nodes when all heading sizes are disabled#16090
AlessioGr merged 1 commit into
payloadcms:mainfrom
mahmoodhamdi:fix/lexical-heading-empty-sizes

Conversation

@mahmoodhamdi

Copy link
Copy Markdown
Contributor

What

Fixes HeadingFeature({ enabledHeadingSizes: [] }) creating invalid h0 heading nodes that corrupt stored data.

Closes #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:

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

…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.
@mahmoodhamdi mahmoodhamdi requested a review from AlessioGr as a code owner March 29, 2026 02:46
@AlessioGr AlessioGr enabled auto-merge (squash) March 30, 2026 23:11
@AlessioGr AlessioGr merged commit 185548a into payloadcms:main Mar 30, 2026
157 checks passed
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HeadingFeature({ enabledHeadingSizes: [] }) creates invalid h0 heading nodes

2 participants