Skip to content

fix: editor performance improvements - #1648

Merged
Philipinho merged 2 commits into
mainfrom
fix/editor-transaction
Sep 30, 2025
Merged

Philipinho merged 2 commits into
mainfrom
fix/editor-transaction

Conversation

@Philipinho

@Philipinho Philipinho commented Sep 30, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Fixed multiple active-state detections so formatting, alignment, colors, node types, and link preview reflect the true editor state.
    • Corrected menu/plugin keys to ensure bubble menus display reliably.
    • Media/embed width controls now read and show current values consistently.
  • Performance and UX Improvements

    • Menus and icons respond more reliably and only appear when the editor is editable.
    • Safer null/guard handling prevents stale UI when no editor is present.
  • Refactor

    • Unified derived editor state used across bubble menus and media controls for more stable UI logic.

- change shouldRerenderOnTransaction to false
@coderabbitai

coderabbitai Bot commented Sep 30, 2025 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

Walkthrough

Introduces useEditorState selectors across many editor UI components to derive active flags and attributes, replaces direct editor.isActive/attribute reads, adds null guards and Editor | null prop types in several components, fixes pluginKey typos, adds a default export for DrawioMenu, and sets shouldRerenderOnTransaction to false in PageEditor.

Changes

Cohort / File(s) Summary
Bubble menu core
apps/client/src/features/editor/components/bubble-menu/bubble-menu.tsx, apps/client/src/features/editor/components/bubble-menu/color-selector.tsx, apps/client/src/features/editor/components/bubble-menu/node-selector.tsx, apps/client/src/features/editor/components/bubble-menu/text-alignment-selector.tsx
Add useEditorState selectors to derive mark/node/alignment flags and color state; replace direct editor.isActive/attribute reads with editorState lookups; add null guards; change some prop types to `Editor
Media node menus
apps/client/src/features/editor/components/drawio/drawio-menu.tsx, apps/client/src/features/editor/components/excalidraw/excalidraw-menu.tsx, apps/client/src/features/editor/components/image/image-menu.tsx, apps/client/src/features/editor/components/video/video-menu.tsx
Derive node active state and width via useEditorState; replace direct attribute access with derived values; gate NodeWidthResize on derived width; normalize string quotes; fix pluginKey values; add default export for DrawioMenu.
Table tools
apps/client/src/features/editor/components/table/table-background-color.tsx, apps/client/src/features/editor/components/table/table-text-alignment.tsx
Compute current cell/header color and alignment via useEditorState; change editor prop types to `Editor
Link
apps/client/src/features/editor/components/link/link-menu.tsx
Derive link href via useEditorState and use editorState?.href in panels; preserve existing edit/unset flows.
Callout
apps/client/src/features/editor/components/callout/callout-menu.tsx
Add useEditorState-derived callout-type flags; replace isActive checks with editorState flags; fix pluginKey and cleanup imports.
Node selectors / Misc bubble items
apps/client/src/features/editor/components/bubble-menu/*
General pattern change: compute active-item flags via useEditorState and use them for UI active states while preserving command wiring to editor.
Page editor
apps/client/src/features/editor/page-editor.tsx
Add useEditorState-derived editorIsEditable and use it for conditional menu rendering; set shouldRerenderOnTransaction: false; minor formatting/cleanup.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as Menu/Selector Component
  participant S as useEditorState
  participant E as Editor
  participant Doc as Document

  User->>UI: open menu / change selection
  UI->>S: read derived state (e.g., isBold, width, href)
  S->>E: query active marks/nodes/attributes
  E-->>S: snapshot flags/attrs
  S-->>UI: editorState (flags/attrs)
  UI-->>User: render active states

  User->>UI: trigger action (e.g., Bold, Align, Update href)
  UI->>E: editor.commands.<action>(...)
  E->>Doc: apply transaction
  Doc-->>E: updated document state
  E-->>S: new state available
  S-->>UI: updated editorState
  UI-->>User: UI reflects updated state
Loading
sequenceDiagram
  autonumber
  participant PageEditor
  participant S as useEditorState
  participant E as Editor

  PageEditor->>S: derive editorIsEditable
  S->>E: read isEditable
  E-->>S: true/false
  S-->>PageEditor: editorIsEditable
  alt editorIsEditable == true
    PageEditor->>PageEditor: render toolbars/menus
  else
    PageEditor->>PageEditor: hide toolbars/menus
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • fix: editor performance improvements #1648 — Applies the same pattern across editor UI components: adding useEditorState selectors and replacing direct editor.isActive/attribute reads with derived editorState usage.

Poem

I hop and nibble on editor state,
Derived flags tidy every gate.
pluginKeys mended, widths in view,
Menus sing true, commands still do.
A rabbit cheers: code fresh and neat 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title “fix: improvements to editor performance” concisely conveys that the primary goal of this changeset is to enhance the editor’s performance, which aligns with the broad integration of useEditorState and related refactors to limit re-renders and optimize transaction handling across multiple components.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2d6827 and ebdd947.

📒 Files selected for processing (6)
  • apps/client/src/features/editor/components/bubble-menu/bubble-menu.tsx (2 hunks)
  • apps/client/src/features/editor/components/bubble-menu/node-selector.tsx (3 hunks)
  • apps/client/src/features/editor/components/bubble-menu/text-alignment-selector.tsx (3 hunks)
  • apps/client/src/features/editor/components/link/link-menu.tsx (3 hunks)
  • apps/client/src/features/editor/components/table/table-text-alignment.tsx (5 hunks)
  • apps/client/src/features/editor/components/video/video-menu.tsx (6 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
apps/client/src/features/editor/components/excalidraw/excalidraw-menu.tsx (1)

68-68: Fix pluginKey typo - closing brace instead of opening brace.

The pluginKey has a typo: excalidraw-menu} contains a closing brace } instead of an opening brace {. This should be {excalidraw-menu} for a template literal or simply "excalidraw-menu" for a plain string.

Apply this diff to fix:

-      pluginKey={`excalidraw-menu}`}
+      pluginKey={`excalidraw-menu`}
apps/client/src/features/editor/components/link/link-menu.tsx (1)

62-62: Fix the pluginKey typo.

The pluginKey has a typo with an extra closing brace: link-menu} should be link-menu.

Apply this diff:

-      pluginKey={`link-menu}`}
+      pluginKey="link-menu"
🧹 Nitpick comments (8)
apps/client/src/features/editor/components/table/table-background-color.tsx (1)

42-64: Consider removing unused properties from selector.

The isTableCell and isTableHeader properties (lines 60-61) are computed but never used in the component. Since the selector runs on every editor transaction, removing unused computations would be a minor optimization.

Apply this diff to simplify the selector:

   const editorState = useEditorState({
     editor,
     selector: (ctx) => {
       if (!ctx.editor) {
         return null;
       }
 
       let currentColor = "";
       if (ctx.editor.isActive("tableCell")) {
         const attrs = ctx.editor.getAttributes("tableCell");
         currentColor = attrs.backgroundColor || "";
       } else if (ctx.editor.isActive("tableHeader")) {
         const attrs = ctx.editor.getAttributes("tableHeader");
         currentColor = attrs.backgroundColor || "";
       }
 
       return {
         currentColor,
-        isTableCell: ctx.editor.isActive("tableCell"),
-        isTableHeader: ctx.editor.isActive("tableHeader"),
       };
     },
   });
apps/client/src/features/editor/components/excalidraw/excalidraw-menu.tsx (1)

16-28: Consider using editorState in shouldShow for consistency.

The shouldShow callback still uses editor.isActive("excalidraw") directly, while editorState.isExcalidraw (computed on line 39) is derived but never used. If the goal is to optimize re-renders via useEditorState, consider leveraging the computed state here as well, or remove the unused isExcalidraw property from the selector.

apps/client/src/features/editor/components/callout/callout-menu.tsx (1)

39-54: Well-structured derived state pattern for performance optimization.

The useEditorState selector computes all active states in a single reactive computation, reducing re-renders compared to multiple direct editor.isActive checks during render.

Minor observation: isCallout is computed but never consumed. Consider removing it if unused, though the performance impact is negligible.

apps/client/src/features/editor/components/drawio/drawio-menu.tsx (1)

17-26: Consider using editorState.isDrawio for consistency.

The shouldShow callback still directly calls editor.isActive("drawio"), while editorState.isDrawio is computed but unused. For consistency and to maximize the performance benefits of useEditorState, consider using the derived state instead:

  const shouldShow = useCallback(
    ({ state }: ShouldShowProps) => {
      if (!state) {
        return false;
      }

-      return editor.isActive("drawio") && editor.getAttributes("drawio")?.src;
+      return editorState?.isDrawio && editor.getAttributes("drawio")?.src;
    },
-    [editor],
+    [editorState, editor],
  );

This would reduce redundant isActive checks and better align with the performance optimization approach.

apps/client/src/features/editor/components/link/link-menu.tsx (1)

11-13: Consider deriving shouldShow from editorState for consistency.

The shouldShow callback uses editor.isActive("link") directly, which may trigger re-renders on every transaction. For consistency with the performance improvements in this PR, consider deriving the active state from useEditorState.

You could extend the selector to include the active state:

  const editorState = useEditorState({
    editor,
    selector: (ctx) => {
      if (!ctx.editor) {
        return { href: '', isActive: false };
      }
      const link = ctx.editor.getAttributes("link");
      return {
        href: link.href,
+       isActive: ctx.editor.isActive("link"),
      };
    },
  });

  const shouldShow = useCallback(() => {
-   return editor.isActive("link");
+   return editorState.isActive;
- }, [editor]);
+ }, [editorState.isActive]);
apps/client/src/features/editor/components/bubble-menu/color-selector.tsx (1)

113-130: Consider memoization to prevent unnecessary re-renders.

While useEditorState is the correct approach for deriving reactive state, the current selector creates a new object on every transaction, which may trigger re-renders even when active colors haven't changed. Additionally, checking all 18 color combinations (9 text + 9 highlight) on every transaction could impact performance in large documents.

Consider these optimizations:

  1. Return a stable reference when colors haven't changed (use a comparison):
  const editorState = useEditorState({
    editor,
    selector: ctx => {
      if (!ctx.editor) {
        return null;
      }

      const activeColors: Record<string, boolean> = {};
      TEXT_COLORS.forEach(({ color }) => {
        activeColors[`text_${color}`] = ctx.editor.isActive("textStyle", { color });
      });
      HIGHLIGHT_COLORS.forEach(({ color }) => {
        activeColors[`highlight_${color}`] = ctx.editor.isActive("highlight", { color });
      });

      return activeColors;
    },
+   equalityFn: (prev, next) => {
+     if (!prev || !next) return prev === next;
+     return Object.keys(prev).every(key => prev[key] === next[key]);
+   },
  });
  1. Alternatively, if you're experiencing performance issues, consider only checking the currently active colors rather than all 18 combinations, or use a more targeted selector that only subscribes to the specific attributes being modified.
apps/client/src/features/editor/components/image/image-menu.tsx (1)

36-53: Excellent performance optimization with reactive state selector.

The useEditorState hook with a selector function prevents unnecessary re-renders by deriving only the required UI state. The null guard for ctx.editor is appropriate, and the alignment/width derivations are correct.

Optional: Consider using explicit radix for parseInt:

-        width: imageAttrs?.width ? parseInt(imageAttrs.width) : null,
+        width: imageAttrs?.width ? parseInt(imageAttrs.width, 10) : null,

This makes the base-10 parsing explicit and avoids potential edge cases with leading zeros (though unlikely with Tiptap attributes).

apps/client/src/features/editor/components/video/video-menu.tsx (1)

36-53: Use explicit radix when parsing video width

Change parseInt(videoAttrs.width) to parseInt(videoAttrs.width, 10) on line 50. The width attribute is always formatted as a percent string (e.g. "50%"), so this is a no-op but makes the radix explicit:

-        width: videoAttrs?.width ? parseInt(videoAttrs.width) : null,
+        width: videoAttrs?.width ? parseInt(videoAttrs.width, 10) : null,
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b50e256 and a2d6827.

📒 Files selected for processing (13)
  • apps/client/src/features/editor/components/bubble-menu/bubble-menu.tsx (2 hunks)
  • apps/client/src/features/editor/components/bubble-menu/color-selector.tsx (4 hunks)
  • apps/client/src/features/editor/components/bubble-menu/node-selector.tsx (3 hunks)
  • apps/client/src/features/editor/components/bubble-menu/text-alignment-selector.tsx (3 hunks)
  • apps/client/src/features/editor/components/callout/callout-menu.tsx (7 hunks)
  • apps/client/src/features/editor/components/drawio/drawio-menu.tsx (3 hunks)
  • apps/client/src/features/editor/components/excalidraw/excalidraw-menu.tsx (4 hunks)
  • apps/client/src/features/editor/components/image/image-menu.tsx (6 hunks)
  • apps/client/src/features/editor/components/link/link-menu.tsx (3 hunks)
  • apps/client/src/features/editor/components/table/table-background-color.tsx (4 hunks)
  • apps/client/src/features/editor/components/table/table-text-alignment.tsx (5 hunks)
  • apps/client/src/features/editor/components/video/video-menu.tsx (6 hunks)
  • apps/client/src/features/editor/page-editor.tsx (7 hunks)
🧰 Additional context used
🧬 Code graph analysis (9)
apps/client/src/features/editor/components/link/link-menu.tsx (2)
apps/client/src/features/editor/components/link/link-editor-panel.tsx (1)
  • LinkEditorPanel (8-36)
apps/client/src/features/editor/components/link/link-preview.tsx (1)
  • LinkPreviewPanel (19-60)
apps/client/src/features/editor/components/bubble-menu/text-alignment-selector.tsx (2)
apps/client/src/features/editor/components/bubble-menu/bubble-menu.tsx (1)
  • BubbleMenuItem (33-38)
apps/client/src/features/editor/components/bubble-menu/node-selector.tsx (1)
  • BubbleMenuItem (26-31)
apps/client/src/features/editor/components/drawio/drawio-menu.tsx (1)
apps/client/src/features/editor/components/common/node-width-resize.tsx (1)
  • NodeWidthResize (10-35)
apps/client/src/features/editor/components/video/video-menu.tsx (1)
apps/client/src/features/editor/components/common/node-width-resize.tsx (1)
  • NodeWidthResize (10-35)
apps/client/src/features/editor/components/image/image-menu.tsx (1)
apps/client/src/features/editor/components/common/node-width-resize.tsx (1)
  • NodeWidthResize (10-35)
apps/client/src/features/editor/components/excalidraw/excalidraw-menu.tsx (1)
apps/client/src/features/editor/components/common/node-width-resize.tsx (1)
  • NodeWidthResize (10-35)
apps/client/src/features/editor/components/bubble-menu/bubble-menu.tsx (2)
apps/client/src/features/editor/components/bubble-menu/node-selector.tsx (1)
  • BubbleMenuItem (26-31)
apps/client/src/features/editor/components/bubble-menu/text-alignment-selector.tsx (1)
  • BubbleMenuItem (21-26)
apps/client/src/features/editor/components/bubble-menu/node-selector.tsx (2)
apps/client/src/features/editor/components/bubble-menu/bubble-menu.tsx (1)
  • BubbleMenuItem (33-38)
apps/client/src/features/editor/components/bubble-menu/text-alignment-selector.tsx (1)
  • BubbleMenuItem (21-26)
apps/client/src/features/editor/page-editor.tsx (1)
apps/client/src/features/editor/atoms/editor-atoms.ts (1)
  • yjsConnectionStatusAtom (10-10)
🔇 Additional comments (46)
apps/client/src/features/editor/components/table/table-background-color.tsx (5)

12-13: LGTM: Type-only import and useEditorState hook addition.

The type-only import of Editor is good practice for TypeScript optimization, and useEditorState is correctly imported to enable reactive editor state derivation.


22-22: LGTM: More explicit editor type.

Changing to Editor | null is clearer and more explicit than ReturnType<typeof useEditor>, and properly represents the nullable state of the editor prop.


66-68: LGTM: Proper null guards.

The null guards for both editor and editorState prevent rendering when the editor is unavailable, which is the correct defensive pattern.


70-84: LGTM: Color setter logic is correct.

The function properly updates both tableCell and tableHeader attributes with the selected color and name, and correctly uses null to clear attributes when color is empty.


140-140: LGTM: Reactive color state usage.

Using editorState.currentColor enables automatic re-rendering when the selection changes, which is the key improvement of this refactor.

apps/client/src/features/editor/components/table/table-text-alignment.tsx (6)

15-16: LGTM! Correct imports for the performance optimization.

The Editor type and useEditorState hook imports are appropriate for deriving reactive alignment states.


20-20: LGTM! Cleaner type definition.

Using Editor | null directly is clearer than ReturnType<typeof useEditor> and properly expresses the nullable editor prop.


35-48: Excellent performance optimization using useEditorState.

The selector pattern properly memoizes alignment state and will only trigger re-renders when alignment actually changes, avoiding unnecessary updates on every editor transaction.


50-52: LGTM! Proper null safety guard.

The early return correctly handles both null editor and null editorState cases before accessing them below.


58-58: LGTM! Correctly uses derived state.

The isActive methods now reference the memoized editorState flags instead of calling editor.isActive() repeatedly, which improves performance.

Also applies to: 65-65, 72-72


109-109: LGTM! Correct conditional rendering.

The rightSection properly uses item.isActive() to conditionally render the check icon, leveraging the new state-derived active flags.

apps/client/src/features/editor/components/bubble-menu/node-selector.tsx (1)

16-17: Good use of useEditorState for performance optimization.

The introduction of useEditorState to derive reactive editor state is a solid performance improvement that aligns with the PR's goal of reducing re-renders. This approach ensures the component only re-renders when the specific editor state properties change, rather than on every transaction.

Also applies to: 40-59

apps/client/src/features/editor/components/excalidraw/excalidraw-menu.tsx (5)

1-14: LGTM - Imports updated correctly.

The addition of useEditorState aligns with the performance improvement objective of this PR.


30-43: Good use of useEditorState for performance optimization.

The selector correctly derives the width attribute needed for rendering. The null-check for the editor is appropriate.


45-63: LGTM - Quote normalization only.

No functional changes; just style consistency improvements.


82-92: LGTM - Rendering logic correctly uses derived state.

The null-safe access to editorState?.width and conditional rendering appropriately leverage the optimized state from useEditorState.


97-97: LGTM - Default export added.

The default export addition is appropriate and follows common patterns.

apps/client/src/features/editor/components/callout/callout-menu.tsx (4)

5-5: LGTM: Import changes support the new derived state pattern.

The addition of useEditorState enables reactive state computation, and the removal of the unused Divider import cleans up dependencies.

Also applies to: 13-13


113-113: Critical fix: Corrected malformed pluginKey.

The pluginKey typo (callout-menu}} → callout-menu) could have caused plugin registration or lifecycle issues. Good catch.


132-132: LGTM: Variant bindings properly use derived state.

The optional chaining correctly handles the null case, falling back to "default" variant when editor state is unavailable.

Also applies to: 143-143, 154-154, 165-165


25-185: Performance optimization aligns with PR objectives.

The refactoring successfully reduces render-time computations by replacing four inline editor.isActive checks with a single memoized useEditorState selector. This pattern prevents unnecessary re-renders when unrelated editor state changes, directly addressing the PR's performance improvement goal.

The shouldShow callback correctly continues to use direct editor.isActive as it's invoked by Tiptap's plugin system lifecycle rather than component render.

apps/client/src/features/editor/components/drawio/drawio-menu.tsx (4)

1-14: LGTM! Imports are well-organized.

The addition of useEditorState aligns with the PR objective of improving editor performance by enabling selective reactivity. The other imports (useCallback, sticky, PMNode) are appropriately added to support the refactored implementation.


28-41: Excellent use of useEditorState selector pattern.

The selector properly isolates drawio-specific state (active status and width), which will prevent unnecessary rerenders when other editor state changes. The null check for ctx.editor and the width parsing logic are both correctly implemented. This is a key performance improvement aligned with the PR objective.


87-89: Improved conditional rendering with derived state.

The conditional rendering now uses editorState?.width instead of directly accessing editor.getAttributes("drawio")?.width, which is more efficient and consistent with the performance optimization approach. The value is also correctly parsed to an integer in the selector.


95-95: LGTM! Default export added for convenience.

Adding a default export while preserving the named export is a non-breaking change that provides flexibility for consumers of this component.

apps/client/src/features/editor/components/bubble-menu/bubble-menu.tsx (1)

72-103: Items array refactor looks good, pending null guard.

The migration from editor.isActive() to editorState predicates in the isActive callbacks is correct and will reduce unnecessary re-renders by relying on derived state. Commands appropriately continue using props.editor for execution.

This implementation is sound once the null guard (flagged in lines 54-70) is in place.

apps/client/src/features/editor/components/bubble-menu/text-alignment-selector.tsx (4)

11-12: Good type refinement with explicit nullability.

Changing the editor prop type from ReturnType<typeof useEditor> to Editor | null makes the nullability explicit and improves type clarity. The addition of useEditorState import aligns with the performance optimization pattern.

Also applies to: 16-16


35-53: Excellent null-safe implementation of editorState.

The implementation properly guards against null editor at two levels:

  1. Inside the selector (lines 38-40)
  2. At the component level with an early return (lines 51-53)

This ensures type safety and prevents runtime errors when the editor is unavailable. The derived alignment state will optimize re-renders by only updating when actual alignment state changes.


82-82: Improved activeItem logic with sensible fallback.

The new computation items.filter((item) => item.isActive()).pop() ?? items[0] correctly identifies the active alignment and falls back to the first item (left align) when none are active. This is more intuitive than a fixed fallback and properly handles the edge case where no alignment is explicitly set.


95-95: Dynamic icon rendering improves UX.

Rendering activeItem.icon dynamically instead of a static icon provides better visual feedback by showing the currently active alignment in the button. This makes the UI more intuitive and informative.

apps/client/src/features/editor/components/bubble-menu/color-selector.tsx (5)

12-13: LGTM: Proper type import and new hook.

The switch to a type-only import for Editor and the addition of useEditorState align with the PR's goal to improve editor performance by deriving reactive state.


22-22: LGTM: More explicit prop type.

The change from ReturnType<typeof useEditor> to Editor | null is clearer and properly typed for the null check added below.


132-134: LGTM: Proper null guards.

The early return with null checks for both editor and editorState is appropriate defensive programming and aligns with the Editor | null prop type.


136-142: LGTM: Efficient state lookup.

Using the derived editorState map instead of calling editor.isActive during render is the correct pattern and avoids redundant queries.


179-179: LGTM: Correct usage of editorState for UI.

The checkmark visibility correctly uses the derived editorState map, avoiding direct editor.isActive calls during render.

apps/client/src/features/editor/components/image/image-menu.tsx (4)

5-5: LGTM: Performance optimization import.

The useEditorState hook import is appropriate for the performance improvements outlined in the PR objectives.


106-106: Good catch: Fixed pluginKey typo.

The removal of the trailing }} characters corrects a malformed plugin key string.


126-126: LGTM: UI now consumes derived state.

The alignment button variants now use editorState?.isAlignLeft/Center/Right instead of direct editor.isActive calls, which reduces re-renders. Optional chaining correctly handles the null case.

Also applies to: 137-137, 148-148


155-157: NodeWidthResize’s width prop is optional – no change needed.
The ImageWidthProps interface declares width?: string, so omitting it falls back to the default (w={100}) as intended.

Likely an incorrect or invalid review comment.

apps/client/src/features/editor/components/video/video-menu.tsx (3)

5-5: LGTM!

The useEditorState import is correct and aligns with the PR's objective to introduce reactive state management for editor UI components.


126-126: LGTM: Improved reactive alignment state management.

The alignment button variants now correctly use derived editorState flags with proper null-safe optional chaining. This eliminates direct editor.isActive calls and ensures the UI reactively updates only when alignment state changes.

Also applies to: 137-137, 148-148


155-160: Keep the existing truthy width guard. The Slider in NodeWidthResize enforces min={10}, so editorState.width will never be 0—it’s either null (hides the control) or ≥10 (renders it) and the current editorState?.width check is sufficient.

apps/client/src/features/editor/page-editor.tsx (4)

10-15: LGTM: useEditorState import added for reactive state derivation.

The addition of useEditorState enables deriving reactive state from the editor without triggering full component re-renders on every transaction, which aligns with the performance improvement objective.


221-221: Excellent performance optimization!

Setting shouldRerenderOnTransaction: false prevents unnecessary React re-renders on every ProseMirror transaction, significantly improving editor responsiveness. Combined with useEditorState for selective reactivity, this follows tiptap's recommended performance pattern.


279-284: Well-implemented reactive state derivation.

The useEditorState hook with a focused selector extracts only the isEditable state, ensuring re-renders occur only when editability changes rather than on every transaction. The optional chaining and fallback value provide safe null handling.


404-417: Correct usage of derived editable state.

Replacing editor.isEditable with editorIsEditable ensures the menu components only re-render when editability changes, not on every transaction. This maintains correctness while improving performance.

@Philipinho Philipinho changed the title fix: improvements to editor performance fix: editor performance improvements Sep 30, 2025
@Philipinho
Philipinho merged commit 3fae41a into main Sep 30, 2025
github-actions Bot added a commit to antiagingrecord/docmost that referenced this pull request Oct 9, 2025
4231ba9 Merge commit '042836cb6d7cc1f71af3ce44c7957f8abbbf8f25' into feat/aar_edition
042836c sync
4f1f0ba fix
3164b69 feat: api keys management (EE) (docmost#1665)
16c1e86 fix comment space
c9b1cad sync
bf8cf62 feat: Typesense search driver (EE) (docmost#1664)
5a2e16a Merge commit '31350303760163384113bf49d07127e886f94907' into feat/aar_edition
3bc710d Adds CLAUDE.md documentation
16914f1 Block search for non-indexed shares
ca75e29 Set default page mode to Read
3135030 fix editor converter (docmost#1647)
3fae41a fix: editor performance improvements (docmost#1648)
b50e256 sync
1f3b0c7 cloud fix
3c4cab0 v0.23.2
4de25a8 invalidate queries on space deletion
cf5bbb1 fix import html processing
ac17521 sync
9ac180f fix: enhance page import (docmost#1570)
46669fe (cloud) disable page sharing in trial mode
fe6ecdf fix: update combobox props in SpaceSelect component (docmost#1564)
04ae1d7 Allow lastColumnResizable in table
1280f96 feat: implement space and workspace icons (docmost#1558)
61d1cf8 fix: reset file inputs after import
f413720 - sync - reinstantiate S3 client to fix file upload errors during import - delete import zip file after use
8e16ad9 v0.23.1
7ada3cb fix: page import task (docmost#1551)
47c5417 sync
dc06502 sync
091e790 fix attachment search in cloud
ae24ea2 v0.23.0
9df6061 lock file
31053e2 update mermaid
eb8e850 use debug
c99bfb8 make print better
26ea04e sync
6cc58c5 sync
7d2ff34 UI fixes
b08d37f fix
d43ee77 remove debug log
5d91eb4 feat: queue imported attachments for indexing
3e9f6b1 Remove version from docker-compose.yml [deprecated] (docmost#1011)
db55de9 feat: progressive web app (docmost#614)
1919eba New Crowdin updates (docmost#1522)
7951b2e New Crowdin updates (docmost#1509)
73b78f6 more translations
cf7534d fix version display
adec36d fix: adjust margins - use default browser highlight background
f9e1080 sync
00e499b Fixing extra page bug on print (docmost#1478)
5ee6e46 checkbox aligned to text (docmost#1486)
1f797c3 fix: confluence drawio import (docmost#1518)
f12866c feat(EE): full-text search in attachments (docmost#1502)
dcbb65d feat(EE): LDAP integration (docmost#1515)
5968764 feat: emoji callout icon (docmost#1323)
242fb6b fix: set mermaid theme based on computed color scheme (docmost#1438)
74cd890 feat(EE): implement SSO group sync for SAML and OIDC (docmost#1452)
509622a ignore type error
937386e fix: hide table handles in readonly mode
60a373f fix: readonly editor table responsiveness
73ee6ee feat: subpages (child pages) list node (docmost#1462)
7d1e5bc feat: table row/column drag and drop (docmost#1467)
aa58e27 fix: exclude deleted pages (docmost#1494)
08135a2 sync
d92a942 sync
5012a68 sync
5a33777 feat: debug mode env variable (docmost#1450)
3b85f4b fix: enforce C collation for page position ordering to ensure consistent behavior in Postgres 17+ (docmost#1446)
cb2a039 fix: invalidate trashed page from tree state
95b7be6 fix: hide trash from can view permission (docmost#1445)
b0c5572 fix nested taskList in markdown export (docmost#1443)
dddfd48 feat: add attachments support for single page exports (docmost#1440)
aa6eec7 fix: exclude trashed pages from position generation
97a7701 fix local storage copy function (docmost#1442)
b97eb85 sync

git-subtree-dir: vendor/app
git-subtree-split: 4231ba9
@coderabbitai coderabbitai Bot mentioned this pull request Dec 13, 2025
@Philipinho
Philipinho deleted the fix/editor-transaction branch December 14, 2025 19:06
nulluserid pushed a commit to N2con-Inc/docmost that referenced this pull request Dec 17, 2025
* Switch to useEditorState
* change shouldRerenderOnTransaction to false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant