@lexical/html
This package contains HTML helpers and functionality for Lexical.
This package has a good security score with no known vulnerabilities.
Community Reviews
Essential for Lexical but rough edges in serialization edge cases
The documentation assumes familiarity with Lexical's internal node system, which creates a steep learning curve. Type definitions are present but generic, offering limited IDE guidance on what node types are supported or how custom transformers should be structured. Error messages during serialization failures are often cryptic, giving little context about which node caused the issue or why.
The package works reliably for basic rich text scenarios, but expect to write custom serialization logic for anything beyond paragraphs, headings, and lists. Version updates sometimes introduce breaking changes in HTML output format without clear migration guides, making it challenging to maintain consistent serialization across versions.
Best for: Projects already using Lexical that need basic HTML import/export for standard rich text content.
Avoid if: You need predictable, stable HTML output across versions or extensive custom node serialization without deep Lexical internals knowledge.
Functional HTML serialization with XSS concerns requiring careful handling
From a security perspective, this package requires careful attention. The HTML generation itself doesn't sanitize output by default - it trusts your editor state is already safe. More critically, when parsing external HTML via $generateNodesFromDOM(), you're responsible for sanitizing input first. The package doesn't include DOMPurify or similar protections, meaning XSS vulnerabilities are possible if you parse untrusted HTML without pre-sanitization. Error handling is minimal; malformed HTML may produce unexpected node structures rather than clear validation errors.
The library follows Lexical's patterns but lacks security guardrails. You'll need to implement your own sanitization layer, validate HTML sources, and carefully test edge cases. Documentation mentions sanitization responsibility but doesn't provide robust examples of secure integration patterns.
Best for: Projects already using Lexical editor that need HTML serialization with a dedicated security layer in place.
Avoid if: You need out-of-the-box secure HTML parsing or are handling untrusted content without security expertise.
Functional but requires careful XSS handling and sanitization awareness
Error handling is minimal. Invalid HTML parsing often fails silently or produces unexpected node trees rather than throwing actionable exceptions. Debugging malformed conversions requires deep knowledge of Lexical's internal node structure. The TypeScript types help catch obvious mistakes, but there's limited guidance on edge cases like nested structures or custom nodes.
Dependency-wise, it's tightly coupled to the core Lexical package, which means you inherit Meta's update cadence and breaking changes. The MIT license is permissive, but you're essentially locked into the Lexical ecosystem. TLS/crypto isn't relevant here, but input validation patterns are notably absent—you must implement DOMPurify or similar yourself.
Best for: Teams with strong security practices building Lexical-based editors who can implement proper HTML sanitization layers.
Avoid if: You need a secure-by-default HTML conversion solution or are working with untrusted user content without dedicated security expertise.
Sign in to write a review
Sign In