-
Notifications
You must be signed in to change notification settings - Fork 10.4k
fix: Rich text editor duplicates content on update #22759
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
Conversation
@SinghaAnirban005 is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes focus on the Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes detected. All code modifications relate directly to the objectives of fixing content duplication on template updates and improving related test coverage. Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Graphite Automations"Add community label" took an action on this PR • (07/27/25)1 label was added to this PR based on Keith Williams's automation. |
There was a problem hiding this 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 (1)
packages/ui/components/editor/plugins/ToolbarPlugin.tsx (1)
376-392
: Simplify the update listener registration logic.The condition
if (!unregisterUpdateListener)
at line 376 is always true since the variable is initialized tonull
at line 345. This conditional check appears redundant.Consider simplifying by removing the conditional:
- if (!unregisterUpdateListener) { - unregisterUpdateListener = editor.registerUpdateListener(({ editorState, prevEditorState }) => { + unregisterUpdateListener = editor.registerUpdateListener(({ editorState, prevEditorState }) => { editorState.read(() => { const textInHtml = $generateHtmlFromNodes(editor).replace(/</g, "<").replace(/>/g, ">"); const cleanedHtml = textInHtml.replace( /<p\s+class="editor-paragraph"[^>]*>\s*<br>\s*<\/p>/g, "<p class='editor-paragraph'></p>" ); props.setText(cleanedHtml); }); if (!prevEditorState._selection) { editor.blur(); } }); - }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/ui/components/editor/plugins/ToolbarPlugin.test.tsx
(3 hunks)packages/ui/components/editor/plugins/ToolbarPlugin.tsx
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code. Functions like .add, .diff, .isBefore, and .isAfter are slow, especially in timezone mode. Prefer .utc() for better performance. Where possible, replace with native Date and direct .valueOf() comparisons for faster execution. Recommend using native methods or Day.js .utc() consistently in hot paths like loops.
Files:
packages/ui/components/editor/plugins/ToolbarPlugin.test.tsx
packages/ui/components/editor/plugins/ToolbarPlugin.tsx
🔇 Additional comments (5)
packages/ui/components/editor/plugins/ToolbarPlugin.test.tsx (3)
194-224
: Good test improvements for clarity and isolation.The added comments and mock clearing improve test readability and ensure proper isolation of the update behavior being tested.
253-291
: Well-structured test for editor reinitialization.This test effectively validates that the editor reinitializes when
updateTemplate
changes totrue
, which is crucial for the duplication fix.
293-339
: Excellent test coverage for the duplication bug fix.This test directly validates the core issue by ensuring content is replaced rather than duplicated. The regex pattern check effectively catches any duplication scenarios.
packages/ui/components/editor/plugins/ToolbarPlugin.tsx (2)
347-372
: Correct implementation of the duplication fix.The
root.clear()
call at line 354 is the key fix that prevents content duplication by ensuring old content is removed before inserting new content. The fallback handling for empty content and insertion failures is also well-implemented.
344-403
: Well-structured effect with proper cleanup and dependencies.The refactored
useEffect
correctly consolidates initialization and update logic, properly cleans up listeners, and has the right dependency to trigger reinitialization whenupdateTemplate
changes.
ef9eabe
to
0c3a683
Compare
0c3a683
to
28241fb
Compare
@anikdhabal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It only happens in the development environment due to React’s double rendering. So the current approach isn't correct
Closing due to inactivity |
What does this PR do?
This PR resolves the issue in the Editor component where users upon updating text inside the editor, the text get duplicated and appended to the very same text.
For eg -> user typing "i am a dev" after updation woukld become --> "i am a devi am a dev"
Visual Demo (For contributors especially)
Screencast.from.2025-07-27.14-30-41.webm
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?