Repository navigation
fix(lab): make RichTextView react to value prop changes - #4671
Merged
potatowagon merged 2 commits intoAug 4, 2026
Merged
Conversation
LexicalComposer's initialConfig.editorState is only read once on mount, so
<RichTextView value={changingValue} /> froze at its first value and never
updated when value changed. This surfaced in the RichTextEditor 'Markdown
Serializers' story: editing the Markdown input updated the live editor (which
remounts via key={json}) and the round-tripped Markdown, but the read-only
RichTextView stayed stale.
Add an internal SyncValuePlugin that re-applies value via
editor.setEditorState(editor.parseEditorState(value)) whenever it changes
(skipping the initial mount, already handled by initialConfig.editorState).
Mirrors the imperative setEditorState pattern already used in RichTextEditor.tsx
and avoids a top-level lexical value import. Schema-invalid updates still route
through the existing onParseError/errorFallback path.
Add regression tests: RichTextView updates on value change, and recovers from a
malformed value once a valid one is supplied.
potatowagon
requested review from
cixzhang,
ejhammond and
imdreamrunner
as code owners
August 3, 2026 05:38
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reference the canonical pattern SyncValuePlugin mirrors: the Playgrounds ActionsPlugin uses editor.setEditorState(editor.parseEditorState(...)) from inside a plugin, and LexicalComposer reads initialConfig.editorState once in a useMemo(..., []). Comment-only; no behavior change.
cixzhang
approved these changes
Aug 3, 2026
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsRichTextEditor (@astryxdesign/lab) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In the RichTextEditor Markdown Serializers story, section "3. Same JSON rendered read-only via RichTextView" does not update when the Markdown input changes. Editing the Markdown updates the live
<RichTextEditor>(section 2) and the round-tripped Markdown (section 4), but the read-only<RichTextView>stays frozen at its initial content.Root cause
RichTextViewpassesvaluetoLexicalComposer'sinitialConfig.editorState, which Lexical reads once on mount. Whenvaluechanges afterward, the composer is not re-initialized, so the rendered content never updates. (Section 2's editor sidesteps this withkey={json}, which forces a full remount — butRichTextViewhas no such workaround, and consumers of the component hit the same frozen-content bug.)Fix
Add a small internal
SyncValuePlugininside the composer that re-appliesvaluewhenever it changes, viaeditor.setEditorState(editor.parseEditorState(value))— skipping the initial mount (already handled byinitialConfig.editorState). This:setEditorState/parseEditorStatepattern already used inRichTextEditor.tsx(and its documented reason for avoiding a top-levellexicalvalue import that breaks the sandbox Next build).onParseError→errorFallbackpath (Lexical'sonError).Tests
Added two regression tests to the
RichTextViewsuite:updates the rendered content when the value prop changes— rerenders with a new value and asserts the content swaps (fails onmainwithout this fix; verified).recovers from a malformed value once a valid value is supplied again— malformed value renders the fallback, then a valid value re-mounts and renders.All 52 tests in
RichTextEditor.test.tsxpass. Lint +check:repopre-commit checks pass.