fix: prevent table column insertion from freezing - #985
Conversation
|
🎉 This PR is included in version 4.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Since the editor renders decorators through Lexical's extension composer (useSyncExternalStore), React state set inside parentEditor.update() is rendered before the new table contents. After a column insert, that render focused the cell that was about to shift right, and its late focus event fought the new cell for the active position until React aborted with "Maximum update depth exceeded" (mdx-editor#982). Set the active cell from the update's onUpdate callback instead, which runs after the commit, and replace the setTimeout workaround from mdx-editor#985. The row and add-row/add-column actions get the same treatment, since they relied on the same ordering. Also read the table size from the committed editor state rather than the lexicalTable prop, which still describes the table from before the change. Inserting right of the last column or below the last row previously moved focus to the wrong cell or out of the table.
|
Thanks for the reproduction and the browser test, @Bashar-Omar. This shipped in v4.3.0, but with a different fix on top of yours, so here is why the While looking into this further, it turned out to be a regression from two earlier changes combined:
With both in place, React rendered the new active cell ( The fix in 5408665 sets the active cell from the update's Your |
|
Thanks for the detailed breakdown. Moving the active-cell update to onUpdate after the Lexical commit makes the ordering issue much clearer than my initial popover hypothesis. Glad the browser regression test was useful, and nice catch on the last-row/last-column focus cases as well. |
Fixes #982.
Column insertion was updating the table while the column popover was still in the same interaction. Since inserting a column changes the header geometry, the popover trigger moves while Radix is positioning it and React falls into repeated updates.
This closes the column popover first and defers the Lexical table mutation to the next task. The existing node-by-key guard and focus behavior stay unchanged.
Added browser coverage for inserting columns on both sides. Before the fix, both cases timed out with
Maximum update depth exceededin Chromium, Firefox, and WebKit. After the fix, the full CI suite passes.