mdx-editor / editor

A rich text editor React component for markdown
https://mdxeditor.dev
MIT License
1.63k stars 131 forks source link

Table inside a NestedLexicalEditor doesn't update properly [BUG] #451

Closed oliver-crowe-bp closed 2 months ago

oliver-crowe-bp commented 2 months ago

Describe the bug When a table is added inside a NestedLexicalEditor, the table cell contents does not update in the source mode until a space outside of the table is clicked within the NestedLexicalEditor. This means saved content can be lost when updating a table which is inside a NestedLexicalEditor.

To Reproduce

  1. Add a component which uses a NestedLexicalEditor to the MDXEditor (e.g. anything which uses the GenericJsxEditor with children)
  2. Click within the NestedLexicalEditor and insert a table
  3. Add some text to a cell of the table
  4. Click on the 'source mode' option to view the MDX source
  5. Observe no text appears in the table source (even if you click outside the NestedLexicalEditor)
  6. Click within the NestedLexicalEditor but outside of the table
  7. The table text has now updated in the MDX source

Expected behavior The table should update when it's changed, and not require an extra click inside the NestedLexicalEditor to trigger an update.

Screenshots Video demonstration using the GenericJsxEditor and table plugin:

https://github.com/mdx-editor/editor/assets/144693997/28f5b4d6-550f-4fdf-a434-038a42345fc1

Desktop (please complete the following information):

Additional context I think this could be because the table editor doesn't dispatch the NESTED_EDITOR_UPDATED_COMMAND when it saves an update, so the NestedLexicalEditor doesn't update itself.

petyosi commented 2 months ago

That's a nasty limitation of Lexical's nested editors, a bit of a chicken-and-egg problem, I'm afraid.