Skip to content

[lexical-website] Documentation Update: Add editor context gotcha documentation for editorState.read()#7731

Closed
mrdivyansh wants to merge 1 commit intofacebook:mainfrom
mrdivyansh:getEditor_gotcha_doc_update
Closed

[lexical-website] Documentation Update: Add editor context gotcha documentation for editorState.read()#7731
mrdivyansh wants to merge 1 commit intofacebook:mainfrom
mrdivyansh:getEditor_gotcha_doc_update

Conversation

@mrdivyansh
Copy link
Copy Markdown
Contributor

@mrdivyansh mrdivyansh commented Jul 29, 2025

Description

Current behavior:
The documentation does not explain that editor.getEditorState().read() lacks editor context by default, causing functions like $getEditor() to throw "Unable to find an active editor" errors. This is a common gotcha that developers discover through trial and error.

Changes being added:

  • Enhanced the existing tip sections in intro.md and README.md with clear warnings about editor context differences
  • Added a dedicated FAQ entry explaining why $getEditor() fails in editorState.read() and how to fix it
  • Added warning callout in concepts/editor-state.md right after the editorState.read() example
  • Provided multiple solutions with clear ❌ / ✅ examples showing what works and what doesn't
  • Added guidance on when to use editor.read() vs editor.getEditorState().read()

Test plan

Before

Developers encountering this issue would:

  • Try editor.getEditorState().read(() => $getEditor())
  • Get cryptic "Unable to find an active editor" error
  • Have to dig through tests or source code to understand the { editor } option
  • No clear guidance on when to use which read method

After

With the updated documentation:

  • Clear warnings in multiple locations where developers will see them
  • Prominent ⚠️ gotcha sections with visual ❌ / ✅ indicators
  • Dedicated FAQ entry for this specific error
  • Multiple solution examples showing both the explicit editor option and using editor.read() instead
  • Guidance on when to use each approach
Introduction._.Lexical.-.29.July.2025.mp4.mp4

@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2025 6:44am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2025 6:44am

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Jul 29, 2025

Why not improve the error message and API docs? People will almost certainly find those a lot more easily.

@etrepum etrepum added the stale-pr PRs that are closed due to staleness. Please reopen the PR if there are new updates label Feb 13, 2026
@etrepum etrepum closed this Feb 13, 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. stale-pr PRs that are closed due to staleness. Please reopen the PR if there are new updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants