Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
fix(richtext-lexical): prevent invalid h0 heading nodes when all heading sizes are disabled (#16090)
## 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:
```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 M
Mahmoud Hamdy committed
185548a3d4f67dce83e4f4b2f4400c4335cb5240
Parent: 974870a
Committed by GitHub <noreply@github.com>
on 3/30/2026, 11:34:56 PM