Skip to content

[lexical-markdown] Bug Fix: replace lookbehind assertions for Safari < 16.4 compatibility#8332

Merged
etrepum merged 1 commit intofacebook:mainfrom
Yahid-Basha:fix/markdown-safari-lookbehind-compat
Apr 11, 2026
Merged

[lexical-markdown] Bug Fix: replace lookbehind assertions for Safari < 16.4 compatibility#8332
etrepum merged 1 commit intofacebook:mainfrom
Yahid-Basha:fix/markdown-safari-lookbehind-compat

Conversation

@Yahid-Basha
Copy link
Copy Markdown
Contributor

Description

Current behavior: Negative lookbehind assertions ((?<!...)) inside
createTextFormatTransformersIndex throw a SyntaxError at new RegExp(...)
construction time in Safari < 16.4 (ES2018 not supported), crashing markdown
import entirely for those users.

Changes: Replace all lookbehind-based patterns with a preceding-character
capture group (^|[^\\...]) that matches start-of-string or a non-escape
character before the delimiter. Call sites offset match.index by
match[1].length to find the real start of the span. The escape guard on
openTagsRegExp is removed since isEscaped() in scanDelimiters() already
handles this.

Closes #8012

Test plan

Before

Safari < 16.4 throws SyntaxError: Invalid regular expression: invalid group specifier name when any markdown string is imported — no markdown rendering
works at all.

After

7 new unit tests added to LexicalMarkdown.test.ts:

  • No throw on regex construction
  • Code span at start of string
  • Code span mid-text
  • Multiple spans on one line
  • Escaped backtick not parsed as span
  • Content capture correctness
  • No emphasis formatting inside code span

All 2,754 existing tests continue to pass.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Apr 11, 2026 5:49am
lexical-playground Ready Ready Preview, Comment Apr 11, 2026 5:49am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 11, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Apr 11, 2026
@etrepum etrepum added this pull request to the merge queue Apr 11, 2026
Merged via the queue into facebook:main with commit be0b091 Apr 11, 2026
38 checks passed
@etrepum etrepum mentioned this pull request Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Invalid group specifier on @lexical/markdown

2 participants