Repository navigation
feat: render images in RichText via a custom Lexical image node - #3448
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review. WalkthroughRichText now processes Lexical image nodes. The node validates and serializes image metadata, transforms supported VTEX URLs, and exports responsive HTML with alignment metadata. The change also updates rich-text styles, public exports, newsletter privacy-policy widget settings, and browser tests. ChangesRich-text image support
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant RichText
participant HeadlessLexicalEditor
participant RichTextImageNode
participant BrowserDOM
RichText->>HeadlessLexicalEditor: register RichTextImageNode
HeadlessLexicalEditor->>RichTextImageNode: process serialized image data
RichTextImageNode->>RichTextImageNode: validate metadata and transform supported VTEX URL
RichTextImageNode-->>RichText: export responsive image HTML
RichText->>BrowserDOM: render HTML with alignment wrapper
Merge Risk: ⚪ Minimal · up to The previously reported test-loading issue has been corrected, and no actionable merge-blocking risk remains after normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The image implementation uses DOM properties rather than interpolated markup, and the existing HTML-rendering behavior is preserved. No introduced exploitable path is established. However, content-author permissions, validation by external callers, and editor-to-renderer compatibility are not fully confirmed. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 3 files. (2 skipped: 2 unsupported.) ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/src/components/ui/RichText/RichTextImageNode.ts`:
- Around line 37-40: Update resolveWidthPercent so it accepts only finite,
positive numeric width values; reject Infinity, -Infinity, and NaN before
returning the value, while preserving DEFAULT_WIDTH_PERCENT for invalid inputs.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 1db129b2-2d82-4b71-a422-0b302abe1cb1
📒 Files selected for processing (3)
packages/core/src/components/ui/RichText/RichText.tsxpackages/core/src/components/ui/RichText/RichTextImageNode.tspackages/ui/src/components/atoms/RichText/styles.scss
…g in RichTextImageNode
@faststore/api
@faststore/cli
@faststore/components
@faststore/core
@faststore/diagnostics
@faststore/lighthouse
@faststore/sdk
@faststore/ui
commit: |
…line image attribute handling
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/test/components/ui/RichText/RichText.test.tsx`:
- Around line 8-12: Hoist isContentPlatformSourceMock with vi.hoisted before the
vi.mock factory uses it, preserving the existing mock behavior. Rename the test
file from RichText.test.tsx to RichText.browser.test.tsx so it is collected by
the browser project instead of the node project.
Apply the same fix in
`@packages/core/test/components/ui/RichText/RichText.test.tsx` around lines 1 - 3.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: acf386cc-3ea9-4d43-86b5-e06088ccdc2f
📒 Files selected for processing (2)
packages/core/src/components/ui/RichText/RichTextImageNode.tspackages/core/test/components/ui/RichText/RichText.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/core/src/components/ui/RichText/RichTextImageNode.ts
…ing and image handling
| const VALID_ALIGNMENTS = new Set<ImageAlignment>(['left', 'center', 'right']) | ||
| const DEFAULT_ALIGNMENT: ImageAlignment = 'left' | ||
| const DEFAULT_WIDTH_PERCENT = 100 | ||
| const RICH_TEXT_CONTENT_MAX_WIDTH = 720 |
There was a problem hiding this comment.
deu pra testar no Newsletter em desktop? queria saber de onde vem esse 720 e se a imagem ficou nítida
There was a problem hiding this comment.
o RICH_TEXT_CONTENT_MAX_WIDTH serve para melhorar a performance do componente, é um valor base que garante que arquivos pesados nao sejam baixados por inteiro
a imagem ficou nitida sim, mas podemos excluir essa constante se fizer mais sentido
There was a problem hiding this comment.
não precisamos remover, o teto faz sentido, eu só queria entender esse valor base, não dá para saber se o teto está baixo demais para tela retina ou alto demais para o Newsletter
There was a problem hiding this comment.
eu concordo! o que tu acha que deveria ser feito nesse caso?
There was a problem hiding this comment.
eu tentei validar o RichText no componente de Newsletter na conta brandless pra ver como ficava a imagem, mas não consegui por causa do problema que comentei no slack, o schema desse componente nativo não usa o draftjs-rich-text-v2. O teste iria validar se o 720 estava ok como base.
…export RichText Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
| const DEFAULT_WIDTH_PERCENT = 100 | ||
| const RICH_TEXT_CONTENT_MAX_WIDTH = 720 | ||
| const DEFAULT_IMAGE_QUALITY = 8 | ||
|
|
There was a problem hiding this comment.
[Functional.Logic] 🟡 RESTRICT
DEFAULT_IMAGE_QUALITY is set to 8, which on a 0-100 quality scale produces heavily compressed, visibly degraded images for every rich-text image rendered through the VTEX resize pipeline. The included test merely asserts this value rather than a sane one, so it would not be caught by CI.
Action: Verify the intended quality value with design/content stakeholders — likely should be 80 — and update DEFAULT_IMAGE_QUALITY plus the corresponding test assertion.
To dismiss: reply /dk-review dismiss [reason] under this comment
|
|
||
| function withVtexResizeParams(src: string, widthPercent: number): string { | ||
| if (!src.includes('vtexassets') || !src.includes('/assets')) { | ||
| return src |
There was a problem hiding this comment.
[Functional.Check] 🟡 RESTRICT
withVtexResizeParams decides whether to treat a URL as a VTEX asset by checking if the full URL string contains the substrings 'vtexassets' and '/assets' anywhere, instead of validating the actual hostname. A URL such as https://evil.example.com/path?ref=vtexassets/assets/x.png would pass both checks even though the host isn't a VTEX asset CDN.
Action: Parse the URL and validate url.hostname (e.g. ends with .vtexassets.com) rather than doing substring checks on the raw string.
To dismiss: reply /dk-review dismiss [reason] under this comment
DK Review — Audit SummaryVerdict:
Only BLOCK and RESTRICT findings anchored to a changed line are commented inline on the diff. The other 2 findings below open no review thread. Scenarios evaluated: feature-flags, general-review
📋 Findings (4)RESTRICT
SUGGEST
DK Review v1.0.0 | To dismiss a finding: reply |

0 New Issues
0 Fixed Issues
0 Accepted Issues
What's the purpose of this pull request?
This pull request introduces support for custom image nodes in the rich text editor, allowing images with alignment and width options to be rendered and styled consistently. The main changes include the implementation of a new
RichTextImageNodefor image handling, its integration into the editor pipeline, and corresponding styling updates.Rich Text Image Node Implementation and Integration:
RichTextImageNodeclass toRichTextImageNode.ts, supporting image source, alt text, alignment (left,center,right), and width percentage, with logic for exporting to and importing from JSON and DOM, and automatic image resizing for VTEX assets.RichTextImageNodein thelexicalToHtmlfunction, enabling the rich text editor to recognize and handle image nodes.RichTextImageNodeintoRichText.tsxto ensure it is available for use in the editor.Styling Enhancements:
styles.scssto add styles for[data-fs-rich-text-image-wrapper], ensuring images are displayed with correct alignment and responsive sizing according to their alignment and width settings.How it works?
An image inserted via Content Platform's RichTextWidget gets serialized as a Lexical image node (src, altText, alignment, widthPercent) inside the rich text field's content. RichText's headless Lexical editor didn't recognize that node type, so images were dropped or broke parsing.
Added RichTextImageNode, registered in lexicalToHtml(), to close that gap: it parses the node (sanitizing alignment/widthPercent, capping width at 100%) and renders it to
<div data-fs-rich-text-image-wrapper>+<img data-fs-rich-text-image loading="lazy">. VTEX file-manager URLs get resized via query params (same convention as faststoreLoader). A missing/invalid src makes the node skip itself instead of breaking the block. Styling was added to @faststore/ui's RichText/styles.scss.(Check this PR to get more context)
How to test it?
This should be tested using Content Platform as content source. It can be tested using the Newsletter component. Simply set up a store that uses the code from this PR on CP and create a new entry with the Newsletter component. The preview feature can then be used to test the rendering of the Newsletter rich text.
Checklist
PR Title and Commit Messages
feat,fix,chore,docs,style,refactor,ciandtestPR Description
breaking change,bug,contributing,performance,documentation..Dependencies
pnpm-lock.yamlfile when there were changes to the packagesDocumentation
@Mariana-Caetanoto review and update (Or submit a doc request)Summary by CodeRabbit