-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[WIKI-740] refactor: editor table performance #8411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ type TableColumnDragHandlePluginState = { | |
| // track table structure to detect changes | ||
| tableWidth?: number; | ||
| tableNodePos?: number; | ||
| // track renderers for cleanup | ||
| renderers?: ReactRenderer[]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renderers not destroyed when navigating away from tableWhen a user navigates away from a table (so Additional Locations (1) |
||
| }; | ||
|
|
||
| const TABLE_COLUMN_DRAG_HANDLE_PLUGIN_KEY = new PluginKey("tableColumnHandlerDecorationPlugin"); | ||
|
|
@@ -58,11 +60,22 @@ export const TableColumnDragHandlePlugin = (editor: Editor): Plugin<TableColumnD | |
| decorations: mapped, | ||
| tableWidth: tableMap.width, | ||
| tableNodePos: table.pos, | ||
| renderers: prev.renderers, | ||
| }; | ||
| } | ||
|
|
||
| // Clean up old renderers before creating new ones | ||
| prev.renderers?.forEach((renderer) => { | ||
| try { | ||
| renderer.destroy(); | ||
| } catch (error) { | ||
| console.error("Error destroying renderer:", error); | ||
| } | ||
| }); | ||
|
|
||
| // recreate all decorations | ||
| const decorations: Decoration[] = []; | ||
| const renderers: ReactRenderer[] = []; | ||
|
|
||
| for (let col = 0; col < tableMap.width; col++) { | ||
| const pos = getTableCellWidgetDecorationPos(table, tableMap, col); | ||
|
|
@@ -75,19 +88,35 @@ export const TableColumnDragHandlePlugin = (editor: Editor): Plugin<TableColumnD | |
| editor, | ||
| }); | ||
|
|
||
| renderers.push(dragHandleComponent); | ||
| decorations.push(Decoration.widget(pos, () => dragHandleComponent.element)); | ||
| } | ||
|
|
||
| return { | ||
| decorations: DecorationSet.create(newState.doc, decorations), | ||
| tableWidth: tableMap.width, | ||
| tableNodePos: table.pos, | ||
| renderers, | ||
| }; | ||
| }, | ||
| }, | ||
| props: { | ||
| decorations(state) { | ||
| return TABLE_COLUMN_DRAG_HANDLE_PLUGIN_KEY.getState(state).decorations; | ||
| return (TABLE_COLUMN_DRAG_HANDLE_PLUGIN_KEY.getState(state) as TableColumnDragHandlePluginState | undefined) | ||
| ?.decorations; | ||
| }, | ||
| }, | ||
| destroy() { | ||
| // Clean up all renderers when plugin is destroyed | ||
| const state = | ||
| editor.state && | ||
| (TABLE_COLUMN_DRAG_HANDLE_PLUGIN_KEY.getState(editor.state) as TableColumnDragHandlePluginState | undefined); | ||
| state?.renderers?.forEach((renderer: ReactRenderer) => { | ||
| try { | ||
| renderer.destroy(); | ||
| } catch (error) { | ||
| console.error("Error destroying renderer:", error); | ||
| } | ||
| }); | ||
| }, | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.