Skip to content

[lexical-code][lexical-markdown] Use lightweight code-node import in …#8196

Closed
gurkerl83 wants to merge 1 commit intofacebook:mainfrom
gurkerl83:markdown-code-node-subpath
Closed

[lexical-code][lexical-markdown] Use lightweight code-node import in …#8196
gurkerl83 wants to merge 1 commit intofacebook:mainfrom
gurkerl83:markdown-code-node-subpath

Conversation

@gurkerl83
Copy link
Copy Markdown

@gurkerl83 gurkerl83 commented Mar 7, 2026

Summary

Decouple @lexical/markdown code-block internals from the Prism-heavy @lexical/code root export by introducing and consuming a lightweight @lexical/code/node subpath.

Problem

@lexical/markdown imported code-node APIs from @lexical/code root, which pulls Prism-related modules into markdown-only dependency graphs.

Changes

  • Added new public subpath export: @lexical/code/node
    • Exposes only node-focused APIs:
      • $createCodeNode
      • $isCodeNode
      • CodeNode
      • DEFAULT_CODE_LANGUAGE
      • getDefaultCodeLanguage
      • SerializedCodeNode (type)
  • Switched markdown internals to import from @lexical/code/node:
    • MarkdownTransformers.ts
    • MarkdownShortcuts.ts
    • utils.ts
  • Added TS path mappings for @lexical/code/node.
  • Added regression guardrail test to ensure markdown source does not import @lexical/code root.

Compatibility

No markdown API behavior changes (TRANSFORMERS, CODE, import/export/shortcuts behavior remain unchanged).
Apps that need syntax highlighting should continue to set it up explicitly via @lexical/code (highlight node/plugin); this PR only removes implicit Prism inclusion from markdown-only paths.

Validation

  • pnpm exec vitest run packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts packages/lexical-markdown/src/__tests__/unit/MarkdownTransformers.test.ts
  • pnpm exec vitest run packages/lexical-code/src/__tests__/unit/LexicalCodeNode.test.ts
  • pnpm exec vitest run scripts/__tests__/unit/build.test.ts scripts/__tests__/unit/markdown-deps.test.ts

Bundle proof (markdown-only entry via esbuild metafile):

  • packages/lexical-code/src/FacadePrism.ts: not present
  • prismjs/components/prism-*: not present

Fixes #5381
Related to #4550 #5424 #6575

…markdown

## Summary

Decouple `@lexical/markdown` code-block internals from the Prism-heavy `@lexical/code` root export by introducing and consuming a lightweight `@lexical/code/node` subpath.

## Problem

`@lexical/markdown` imported code-node APIs from `@lexical/code` root, which pulls Prism-related modules into markdown-only dependency graphs.

## Changes

- Added new public subpath export: `@lexical/code/node`
  - Exposes only node-focused APIs:
    - `$createCodeNode`
    - `$isCodeNode`
    - `CodeNode`
    - `DEFAULT_CODE_LANGUAGE`
    - `getDefaultCodeLanguage`
    - `SerializedCodeNode` (type)
- Switched markdown internals to import from `@lexical/code/node`:
  - `MarkdownTransformers.ts`
  - `MarkdownShortcuts.ts`
  - `utils.ts`
- Added TS path mappings for `@lexical/code/node`.
- Added regression guardrail test to ensure markdown source does not import `@lexical/code` root.

## Compatibility

No markdown API behavior changes (`TRANSFORMERS`, `CODE`, import/export/shortcuts behavior remain unchanged).

## Validation

- `pnpm exec vitest run packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts packages/lexical-markdown/src/__tests__/unit/MarkdownTransformers.test.ts`
- `pnpm exec vitest run packages/lexical-code/src/__tests__/unit/LexicalCodeNode.test.ts`
- `pnpm exec vitest run scripts/__tests__/unit/build.test.ts scripts/__tests__/unit/markdown-deps.test.ts`

Bundle proof (markdown-only entry via esbuild metafile):
- `packages/lexical-code/src/FacadePrism.ts`: **not present**
- `prismjs/components/prism-*`: **not present**

Fixes facebook#5381
Related to facebook#4550 facebook#5424 facebook#6575
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 7, 2026

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Mar 7, 2026 11:47am
lexical-playground Ready Ready Preview, Comment Mar 7, 2026 11:47am

Request Review

@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Mar 7, 2026

Hi @gurkerl83!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Mar 7, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 Mar 7, 2026
@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Mar 7, 2026

I’m not sure that this is the best approach. At some point the prism stuff needs to be moved out. I don’t know if it’s worth making this awkward extra module to support that doesn’t follow other lexical conventions and also doesn’t make any progress into extracting prism highlighting into its own package.

@gurkerl83
Copy link
Copy Markdown
Author

gurkerl83 commented Mar 7, 2026

Fair point, I can work on this strategy as well 🙂 Another point is that lexical/code is adding also a tone of stuff on lexical/markdown…

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Mar 7, 2026

The approach here is also not complete for what it is doing, because a lot of tsconfig.json and package.json are maintained by scripts (but due to the nature of json they can't have comments warning about that) so this change would cause problems as soon as those scripts are run.

@gurkerl83
Copy link
Copy Markdown
Author

@etrepum Made a second attempt here #8197

@gurkerl83 gurkerl83 closed this Mar 7, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: prismjs is included as a dependency of @lexical/markdown

2 participants