Skip to content

fix(table): guard TableObserver lookup against detached root (Lexical #232 crash) - #229

Open
arvinxx wants to merge 1 commit into
masterfrom
fix/table-observer-232-detach
Open

arvinxx wants to merge 1 commit into
masterfrom
fix/table-observer-232-detach

Conversation

@arvinxx

@arvinxx arvinxx commented Oct 11, 2026

Copy link
Copy Markdown
Member

Problem

Opening an Agent Document that contains a markdown table could crash the whole editor tree with:

Minified Lexical error #232; visit https://lexical.dev/docs/error?code=232... 

Error #232 = TableObserver: Expected to find TableElement in DOM for key %s (@lexical/table 0.42.0). Tracked in LobeHub as T-632 (vent msg_9qSd082x38qIboPM7Q, desktop).

Root cause

The editor kernel supports reversible root detach — route switches and React Activity hide the subtree through setRootElement(null). Lexical's TableObserver survives the detach:

  • its DOM MutationObserver and the editor-level SELECTION_CHANGE_COMMAND listener stay registered;
  • any async table bookkeeping flushed after the detach (a queued table-subtree DOM mutation racing the route switch, or selection cleanup) resolves the table element through $lookup();
  • with no root attached, getElementByKey() returns null and Lexical throws the uncaught 🐛 fix: clamp rendered image max width to the container #232, taking down the whole editor tree.

Upstream lexical (main, 0.52.0) still throws in this situation, so the guard belongs in lobe-editor.

Reproduction (jsdom, before this fix)

  1. attach editor → hydrate a markdown table (registerTableSelectionObserver mounts the observer + trackTable);
  2. setRootElement(null) (route switch / Activity hide);
  3. mutate a detached table row (childList record on TBODY) and flush microtasks;
  4. the trackTable MutationObserver callback runs post-detach → $lookup() → uncaught 🐛 fix: clamp rendered image max width to the container #232.

Fix

Wrap TableObserver.prototype.$lookup in the existing patchTableNode():

  • while the root is detached — or when the upstream lookup throws on a missing element — degrade to the observer's last-known table element so read-only bookkeeping keeps working instead of crashing;
  • cache the element on every successful lookup;
  • never swallow errors when no fallback exists (same throw surfaces as upstream, minus the detach race).

Tests

New src/plugins/table/node/table-observer-detach.test.ts:

Full suites stay green: table 24/24, editor-kernel 74/74, common 78/78 (+1 skipped); tsc --noEmit clean; lint-staged (prettier/eslint/stylelint), circular-deps and commitlint pass.

Opening a document that contains a markdown table could crash the whole
editor tree with "Minified Lexical error #232" TableObserver: Expected to find TableElement in DOM for key %s.

Root cause: the kernel supports reversible root detach - route switches and
React Activity hide the subtree through setRootElement(null). Lexical's
TableObserver survives the detach: its DOM MutationObserver and the
editor-level SELECTION_CHANGE_COMMAND listener stay registered. Any async
table bookkeeping flushed after the detach (a queued table-subtree DOM
mutation racing the route switch, or selection cleanup) resolves the table
element through $lookup(), where getElementByKey() returns null and Lexical
0.42 throws the uncaught #232.

Fix: wrap TableObserver.prototype.$lookup in patchTableNode(). While the
root is detached - or when the upstream lookup throws on a missing element -
degrade to the observer's last-known table element so read-only bookkeeping
keeps working instead of taking the editor down. The wrapper caches the
element on every successful lookup and never swallows errors when no
fallback exists.

Reproduced in jsdom: detach root, mutate a detached table row, flush the
MutationObserver callback -> uncaught #232 before the fix, clean after.
Upstream (lexical main, 0.52) still throws in this situation, so the guard
stays in lobe-editor.

Tests: new src/plugins/table/node/table-observer-detach.test.ts covers the
post-detach mutation flush, selection bookkeeping across detach/reattach,
and the attached baseline. Full table (24), kernel (74) and common (78)
suites plus tsc --noEmit stay green.
@lobe-tsukumo

lobe-tsukumo Bot commented Oct 11, 2026

Copy link
Copy Markdown

👍 @arvinxx

Thank you for raising your pull request and contributing to our Community.
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.

非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

@vercel

vercel Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
lobe-editor Ready Ready Preview Oct 11, 2026 7:52am UTC

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Oct 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@lobehub/editor@229

commit: a1c13f8

@arvinxx

arvinxx commented Oct 11, 2026

Copy link
Copy Markdown
Member Author

Acceptance evidence (T-379 fix round, 2026-10-11)

Reproduced before the fix (jsdom, @lexical/table 0.42.0):

  • attach → hydrate a markdown table → setRootElement(null) (route switch / Activity hide) → mutate a detached table row → flush microtasks → uncaught TableObserver: Expected to find TableElement in DOM for key 1 (🐛 fix: clamp rendered image max width to the container #232) from the observer's trackTable MutationObserver callback.
  • After wrapping $lookup with the detach-aware guard in patchTableNode(): same sequence produces no error (verified via the kernel error event channel and vitest unhandled-error monitor).

Verification performed:

Item Result
Regression tests (new) ✅ 3/3 src/plugins/table/node/table-observer-detach.test.ts
Full table suite ✅ 24/24
editor-kernel suite ✅ 74/74
common suite ✅ 78/78 (+1 skipped)
tsc --noEmit (full repo) ✅ clean
lint-staged (prettier/eslint/stylelint) + circular-deps + commitlint ✅ pass (enforced at commit)
CI test workflow ⏳ queued (GitHub runner availability) — tracked by T-379 follow-up tick

Upstream note: lexical main (0.52.0) still throws #232 in this situation, so the guard stays in lobe-editor.

@arvinxx

arvinxx commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T08:12:00.257585Z a1c13f8 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: a1c13f8dbf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@arvinxx

arvinxx commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

merge-ready ✅(2026-10-22T~10:45Z 判定):① CI 关键检查无 fail;② Codex 收敛——👍 reaction + receipt 评论(Reviewed commit a1c13f8dbf,与 PR HEAD 一致);③ 行内 P1/P2 未处理数为 0。交人工合并(agent 无合并权限)。

@arvinxx arvinxx added the keep-open Prevent stale-bot from auto-closing label Nov 22, 2026

This branch was successfully deployed

1 active deployment
Preview — a1c13f8d Deployed Oct 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

keep-open Prevent stale-bot from auto-closing vent fix Agent Vent issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants