Skip to content
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

[PE-210] feat: editor performance #6269

Open
wants to merge 10 commits into
base: preview
Choose a base branch
from

Conversation

Palanikannan1437
Copy link
Collaborator

@Palanikannan1437 Palanikannan1437 commented Dec 23, 2024

Description

  1. Make editor much faster and upgrading all the packages.
  2. Remove editorRef in use-editor and use-read-only-editor
  3. Remove selection ref and use editor's state itself as it's persistent now post focus-refocus

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

References

Copy link
Contributor

coderabbitai bot commented Dec 23, 2024

Walkthrough

This pull request focuses on updating dependencies and refactoring the editor-related code in the Plane project. The changes primarily involve upgrading package versions across multiple files, including live/package.json and packages/editor/package.json. Additionally, significant modifications were made to the editor hooks and types, removing references to saved selections and simplifying the editor interaction model. The updates aim to streamline the editor's functionality and bring dependencies to their latest versions.

Changes

File Change Summary
live/package.json Updated versions of Hocuspocus extensions, server, y-prosemirror, and yjs
packages/editor/package.json Removed "module" export fields, updated dependency versions for Hocuspocus, tiptap-markdown, y-prosemirror, and yjs
packages/editor/src/core/components/menus/menu-items.ts Simplified ImageItem command by removing savedSelection parameter
packages/editor/src/core/helpers/insert-content-at-cursor-position.ts Refactored insertContentAtSavedSelection to directly use Editor instance
packages/editor/src/core/hooks/use-editor.ts Removed savedSelection state and editorRef, simplified editor interaction
packages/editor/src/core/hooks/use-read-only-editor.ts Replaced useCustomEditor with useTiptapEditor, removed editorRef
packages/editor/src/core/types/editor.ts Removed methods related to heading changes and real-time updates from EditorReadOnlyRefApi

Possibly related PRs

Suggested labels

🌟improvement, 🌐frontend, ✍️editor

Suggested reviewers

  • aaryan610
  • SatishGandham
  • rahulramesha

Poem

🐰 Hop, hop, through the code we go,
Dependencies dancing, versions in tow,
Editors refactored with magical might,
Simplifying logic, making everything light!
A rabbit's delight in clean, crisp design! 🚀

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Palanikannan1437 Palanikannan1437 force-pushed the fix/upgrade-editor branch 2 times, most recently from 6985452 to bbe378e Compare January 10, 2025 10:43
@Palanikannan1437 Palanikannan1437 self-assigned this Jan 10, 2025
@Palanikannan1437 Palanikannan1437 marked this pull request as ready for review January 10, 2025 11:21
@Palanikannan1437 Palanikannan1437 changed the title chore: upgrade editor packages feat: editor performance Jan 10, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/editor/src/core/helpers/insert-content-at-cursor-position.ts (1)

14-15: Consider using early return pattern for better readability.

The position calculation could be simplified using early returns.

-  const docSize = editor.state.doc.content.size;
-  const safePosition = Math.max(0, Math.min(editor.state.selection.anchor, docSize));
+  if (!editor.state.selection.anchor) return;
+  const safePosition = Math.min(editor.state.selection.anchor, editor.state.doc.content.size);
packages/editor/src/core/hooks/use-editor.ts (2)

117-121: Improve error boundary for selection handling.

Consider wrapping the selection handling in a separate try-catch block to prevent the entire content sync from failing.

  try {
    editor.commands.setContent(value, false, { preserveWhitespace: "full" });
+  } catch (error) {
+    console.error("Error syncing editor content:", error);
+  }
+  try {
    if (editor.state.selection) {
      const docLength = editor.state.doc.content.size;
      const relativePosition = Math.min(editor.state.selection.from, docLength - 1);
      editor.commands.setTextSelection(relativePosition);
    }
  } catch (error) {
-    console.error("Error syncing editor content with external value:", error);
+    console.error("Error restoring selection:", error);
  }

Line range hint 236-254: Optimize text selection performance.

The getSelectedText implementation could be optimized by reducing DOM operations.

  if (empty) return null;

  const nodesArray: string[] = [];
+ const tempDiv = document.createElement("div");
  state.doc.nodesBetween(from, to, (node, _pos, parent) => {
    if (parent === state.doc && editor) {
      const serializer = DOMSerializer.fromSchema(editor.schema);
      const dom = serializer.serializeNode(node);
-     const tempDiv = document.createElement("div");
      tempDiv.appendChild(dom);
      nodesArray.push(tempDiv.innerHTML);
+     tempDiv.innerHTML = '';
    }
  });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 58ac1dc and f78e367.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (7)
  • live/package.json (2 hunks)
  • packages/editor/package.json (3 hunks)
  • packages/editor/src/core/components/menus/menu-items.ts (1 hunks)
  • packages/editor/src/core/helpers/insert-content-at-cursor-position.ts (1 hunks)
  • packages/editor/src/core/hooks/use-editor.ts (10 hunks)
  • packages/editor/src/core/hooks/use-read-only-editor.ts (5 hunks)
  • packages/editor/src/core/types/editor.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/editor/src/core/types/editor.ts
🔇 Additional comments (9)
packages/editor/src/core/helpers/insert-content-at-cursor-position.ts (1)

3-4: LGTM! Improved function signature.

The change from MutableRefObject<Editor | null> to direct Editor instance reduces indirection and simplifies the code.

packages/editor/src/core/hooks/use-read-only-editor.ts (2)

43-46: Performance optimization through render control.

Good addition of immediatelyRender and shouldRerenderOnTransaction flags to optimize rendering performance.


78-81: Verify the impact of skipImageDeletion meta flag.

The skipImageDeletion meta flag is used in clearEditor. Ensure this doesn't affect image cleanup.

Also applies to: 84-85

✅ Verification successful

The skipImageDeletion meta flag implementation is correct

The flag is properly used in the TrackImageDeletionPlugin to skip cleanup only during programmatic content clearing, while maintaining normal image deletion functionality for user actions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for skipImageDeletion usage and related image cleanup logic
rg -A 5 "skipImageDeletion|imageCleanup"

Length of output: 1937


Script:

#!/bin/bash
# Search for image-related tests and handlers
rg -g "*.test.*" -A 5 "image|Image"

# Search for additional image-related logic in plugins
ast-grep --pattern 'class $_ extends Node {
  $$$
  get name() {
    return "image"
  }
  $$$
}'

Length of output: 285


Script:

#!/bin/bash
# Search for test files
fd -e test.ts -e test.tsx -x rg -l "image|Image" {}

# Search for image node and deletion logic
rg -g "*.ts" -A 10 "class.*Image|deleteImage|onDelete.*image"

# Search for image-related extensions or plugins
rg -g "*.ts" "addImage|createImage|uploadImage"

Length of output: 4970

packages/editor/src/core/components/menus/menu-items.ts (1)

205-205: LGTM! Simplified selection handling.

Good change to use editor's selection state directly instead of maintaining a separate saved selection.

packages/editor/src/core/hooks/use-editor.ts (1)

77-78: Performance optimization through render control.

Good addition of render control flags. However, verify if setting both flags to false doesn't affect editor responsiveness.

live/package.json (2)

43-43: Verify y-prosemirror and yjs compatibility

The updates to y-prosemirror (1.2.9 → 1.2.15) and yjs (13.6.14 → 13.6.20) appear to be patch versions, but we should verify compatibility between these interdependent packages.

Also applies to: 45-45

✅ Verification successful

✓ Compatibility verified between y-prosemirror 1.2.15 and yjs 13.6.20

Both updates contain only bug fixes and improvements with no breaking changes or compatibility issues reported in their release notes. The changes enhance stability and fix various edge cases while maintaining backward compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for breaking changes in release notes
echo "Checking y-prosemirror changelog..."
gh api repos/yjs/y-prosemirror/releases | jq -r ".[].body"

echo "Checking yjs changelog..."
gh api repos/yjs/yjs/releases | jq -r ".[].body"

Length of output: 20227


19-22: Verify @hocuspocus packages compatibility

The @hocuspocus packages have been updated to v2.15.0. While this appears to be a minor version bump, we should verify there are no breaking changes.

✅ Verification successful

@hocuspocus package updates appear safe

The minor version bump (2.15.0) with consistent versioning across all @hocuspocus packages, combined with standard API usage patterns in the codebase, suggests this update is safe. The codebase uses well-established APIs that are unlikely to change in minor versions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for breaking changes in release notes
for pkg in extension-database extension-logger extension-redis server; do
  echo "Checking @hocuspocus/$pkg changelog..."
  gh api repos/ueberdosis/hocuspocus/releases | jq -r ".[] | select(.tag_name | contains(\"$pkg\")) | .body"
done

Length of output: 1180


Script:

#!/bin/bash
# Check peer dependencies and usage patterns
echo "Checking package dependencies..."
fd package.json --exec cat {} \; | jq -r '.peerDependencies | select(. != null)'

echo -e "\nChecking @hocuspocus usage patterns..."
rg "@hocuspocus" --type ts --type js -A 2 -B 2

Length of output: 2690

packages/editor/package.json (2)

15-15: Verify impact of removing module exports

The removal of the "module" field from exports could affect bundlers' module resolution. Please ensure this change doesn't impact build optimization.

Consider testing the build process to verify:

  1. Bundle size hasn't increased
  2. Tree-shaking still works effectively
  3. No resolution errors in dependent packages

Also applies to: 20-20


37-37: Package versions aligned with live package

Good job aligning the versions across packages:

  • @hocuspocus/provider: ^2.15.0
  • tiptap-markdown: ^0.8.10
  • y-prosemirror: ^1.2.15
  • yjs: ^13.6.20

Let's verify the tiptap-markdown update:

Also applies to: 68-68, 71-71, 73-73

✅ Verification successful

Package updates verified as safe

All package version updates are safe to use:

  • @hocuspocus/provider ^2.15.0: Adds thread features and bug fixes
  • y-prosemirror ^1.2.15: Contains cursor selection bug fixes
  • yjs ^13.6.20: Adds isDestroyed property and bug fixes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check tiptap-markdown changelog for breaking changes
echo "Checking tiptap-markdown changelog..."
gh api repos/aguingand/tiptap-markdown/releases | jq -r ".[].body"

Length of output: 2422


Script:

#!/bin/bash
# Check @hocuspocus/provider changelog
echo "Checking @hocuspocus/provider changelog..."
gh api repos/ueberdosis/hocuspocus/releases | jq -r ".[].body"

# Check y-prosemirror changelog
echo "Checking y-prosemirror changelog..."
gh api repos/yjs/y-prosemirror/releases | jq -r ".[].body"

# Check yjs changelog
echo "Checking yjs changelog..."
gh api repos/yjs/yjs/releases | jq -r ".[].body"

Length of output: 41975

@Palanikannan1437 Palanikannan1437 changed the title feat: editor performance [PE-210] feat: editor performance Jan 10, 2025
@Palanikannan1437 Palanikannan1437 added the 🛫plane Sync issues onto Plane label Jan 10, 2025
@Palanikannan1437 Palanikannan1437 changed the title [PE-210] feat: editor performance [WEB-593] feat: editor performance Jan 10, 2025
@Palanikannan1437 Palanikannan1437 changed the title [WEB-593] feat: editor performance [PE-210] feat: editor performance Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛫plane Sync issues onto Plane
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants