Skip to content

feat(lab): add getHTML() to RichTextEditor imperative ref - #4550

Merged
cixzhang merged 1 commit into
meta:mainfrom
potatowagon:navi/feat/richtext-get-html-v2
Jul 31, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
potatowagon:navi/feat/richtext-get-html-v2

Conversation

@potatowagon

@potatowagon potatowagon commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds getHTML() to the RichTextEditor imperative ref handle (RichTextEditorRef), serializing the current editor content to an HTML string.

Why

Completes the EPS RichTextArea ref parity — its ref exposes both getMarkdown() (landed in #4509) and getHTML(). Useful for copy/paste, email bodies, or handing content to non-Lexical consumers.

How

  • Added getHTML: () => string to RichTextEditorRef.
  • EditorRefBridge implements it as editor.getEditorState().read(() => $generateHtmlFromNodes(editor, null)) — run in a read context (as the $-API requires); null selection serializes the whole document. Requires a DOM (present in the browser and in jsdom-based tests).
  • $generateHtmlFromNodes comes from @lexical/html, added as a new optional peer dependency (peerDependencies + peerDependenciesMeta optional: true + devDependencies), matching every other @lexical/* peer. It's a subpackage (built dist), so this adds no top-level lexical value import (avoiding the sandbox-build trap).
  • pnpm-lock.yaml: added the @lexical/html importer entry for packages/lab. The package + its transitives already existed in the lockfile (pulled in transitively), so only the direct-dependency declaration was needed.

Docs / stories / tests (SYNC contract)

  • RichTextEditor.doc.mjs — ref best-practice note now mentions getHTML().
  • RichTextEditor.stories.tsx — added a getHTML() button to the ImperativeRef story.
  • RichTextEditor.test.tsx — added a test asserting the HTML contains the seeded paragraph markup/text; handle-shape test updated.

Testing

CI runs the full build/typecheck/lint/test. (Authored on a devserver without a local pnpm toolchain, so relying on CI. Only @lexical/html subpackage is imported — no top-level lexical import.)

in lab https://facebook.github.io/astryx/pr/4550/?path=/docs/lab-richtexteditor--docs
Screenshot 2026-07-31 at 2 27 49 PM

Notes

Adds `getHTML()` to the RichTextEditorRef handle, serializing the current
content to an HTML string via $generateHtmlFromNodes (run in a read context;
requires a DOM — available in the browser and jsdom tests).

Adds `@lexical/html` as a new OPTIONAL peer dependency (peerDependencies +
peerDependenciesMeta.optional + devDependencies), matching the other @lexical/*
peers. `@lexical/html` is a subpackage (built dist) so this adds no top-level
`lexical` value import — the sandbox build stays safe.

- Extended RichTextEditorRef + EditorRefBridge
- Updated doc.mjs ref best-practice note
- Added getHTML() button to the ImperativeRef storybook story
- Added a unit test asserting the HTML contains the seeded paragraph text

Stacked on the getMarkdown PR (meta#4509) since both extend the same ref handle.
@vercel

vercel Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Jul 30, 2026 4:24pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 30, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang
cixzhang enabled auto-merge (squash) July 31, 2026 06:26
@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Jul 31, 2026
@cixzhang
cixzhang merged commit 95f28a1 into meta:main Jul 31, 2026
19 checks passed
cixzhang added a commit that referenced this pull request Aug 12, 2026
RichTextEditor's input wrapper spread `themeProps('rich-text-editor', ...)`
and then overwrote it with both `stylex.props(...)` and
`className={className}`. Each of those carries its own `className`, so React
kept only the last one: the stable `astryx-rich-text-editor` class never
reached the DOM, and with it went every StyleX class on the wrapper — border,
padding, disabled and status styling — plus the `xstyle` passthrough. Merged
through `mergeProps` instead, so the theme target, the StyleX classes and any
consumer `className`/`style` all survive.

The ChatSendButton half of this change landed separately on main in #4634
(`fix(Chat): add missing themeProps and fix className clobber`) with the same
`mergeProps` call, so only its regression test remains here.

The changeset goes with it: what is left changes `@astryxdesign/lab` only,
which is `private: true` / canary-only and so cannot be named in changeset
frontmatter (`check:changesets` rejects it), matching how other lab-only
fixes land (#4670, #4550, #4380, #4891).

@cixzhang
cixzhang added a commit that referenced this pull request Aug 12, 2026
RichTextEditor's input wrapper spread `themeProps('rich-text-editor', ...)`
and then overwrote it with both `stylex.props(...)` and
`className={className}`. Each of those carries its own `className`, so React
kept only the last one: the stable `astryx-rich-text-editor` class never
reached the DOM, and with it went every StyleX class on the wrapper — border,
padding, disabled and status styling — plus the `xstyle` passthrough. Merged
through `mergeProps` instead, so the theme target, the StyleX classes and any
consumer `className`/`style` all survive.

The ChatSendButton half of this change landed separately on main in #4634
(`fix(Chat): add missing themeProps and fix className clobber`) with the same
`mergeProps` call, so only its regression test remains here.

The changeset goes with it: what is left changes `@astryxdesign/lab` only,
which is `private: true` / canary-only and so cannot be named in changeset
frontmatter (`check:changesets` rejects it), matching how other lab-only
fixes land (#4670, #4550, #4380, #4891).

@cixzhang
cixzhang added a commit that referenced this pull request Aug 14, 2026
RichTextEditor's input wrapper spread `themeProps('rich-text-editor', ...)`
and then overwrote it with both `stylex.props(...)` and
`className={className}`. Each of those carries its own `className`, so React
kept only the last one: the stable `astryx-rich-text-editor` class never
reached the DOM, and with it went every StyleX class on the wrapper — border,
padding, disabled and status styling — plus the `xstyle` passthrough. Merged
through `mergeProps` instead, so the theme target, the StyleX classes and any
consumer `className`/`style` all survive.

The ChatSendButton half of this change landed separately on main in #4634
(`fix(Chat): add missing themeProps and fix className clobber`) with the same
`mergeProps` call, so only its regression test remains here.

The changeset goes with it: what is left changes `@astryxdesign/lab` only,
which is `private: true` / canary-only and so cannot be named in changeset
frontmatter (`check:changesets` rejects it), matching how other lab-only
fixes land (#4670, #4550, #4380, #4891).

@cixzhang

This branch was successfully deployed

1 active deployment
Preview — 0f5657b5 Deployed Jul 30, 2026 by vercel[bot]
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 Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants