-
Notifications
You must be signed in to change notification settings - Fork 0
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
[lexical-history][lexical-selection][lexical-react] Fix: #6409 TextNode change detection #42
base: main
Are you sure you want to change the base?
Conversation
Add delay option to HistoryPlugin Add test for #6409 Fix lint issues Fix $cloneWithProperties and test expectations Targeted fix for TextNode leaf change
Clone of the PR facebook/lexical#6420 |
My review is in progress 📖 - I will have feedback for you in a few minutes! |
WalkthroughRecent changes enhance the functionality and maintainability of the Lexical framework. Key updates include the introduction of new node types for improved text manipulation, refinements in type handling for cloning functions, and enhancements to history management with optional delay settings. Additionally, adjustments promote stricter type safety and a more responsive filtering mechanism in the website's UI. Overall, these modifications aim to optimize developer experience and expand the capabilities of the editor. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Editor
participant HistoryManager
participant NodeManager
User->>Editor: Edit Text
Editor->>NodeManager: Update TextNode
NodeManager-->>Editor: Node Updated
Editor->>HistoryManager: Record Change
HistoryManager-->>Editor: History Recorded
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
I have reviewed your code and did not find any issues!
Please note that I can make mistakes, and you should still encourage your team to review your code as well.
/review |
PR Reviewer Guide 🔍(Review updated until commit 58c0311)
|
Persistent review updated to latest commit 58c0311 |
@coderabbitai review |
Actions performedReview triggered.
|
@coderabbitai full review |
Actions performedFull review triggered. |
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
Outside diff range, codebase verification and nitpick comments (1)
packages/lexical-clipboard/src/clipboard.ts (1)
270-274
: Improved comment clarity.The comments have been updated for grammatical consistency, improving the clarity and professionalism of the code documentation.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (8)
- packages/lexical-clipboard/src/clipboard.ts (2 hunks)
- packages/lexical-history/src/tests/unit/LexicalHistory.test.tsx (4 hunks)
- packages/lexical-history/src/index.ts (1 hunks)
- packages/lexical-html/src/index.ts (1 hunks)
- packages/lexical-react/src/LexicalContentEditable.tsx (2 hunks)
- packages/lexical-react/src/LexicalHistoryPlugin.ts (1 hunks)
- packages/lexical-selection/src/lexical-node.ts (2 hunks)
- packages/lexical-website/src/components/Gallery/utils.tsx (1 hunks)
Additional comments not posted (12)
packages/lexical-react/src/LexicalHistoryPlugin.ts (1)
20-28
: LGTM! The addition of thedelay
parameter enhances flexibility.The changes to the
HistoryPlugin
function by adding an optionaldelay
parameter are well-implemented and align with the PR objectives.packages/lexical-website/src/components/Gallery/utils.tsx (1)
54-54
: LGTM! The dependency array update improves responsiveness.Including
tags
in the dependency array ofuseFilteredExamples
ensures that the component reacts to changes intags
, enhancing its responsiveness and accuracy.packages/lexical-react/src/LexicalContentEditable.tsx (1)
18-18
: LGTM! Stricter type safety and deprecation strategy are well-handled.The removal of ESLint comments promotes cleaner code, and the adjustments to the
Props
type indicate a thoughtful approach to deprecating theeditor
property.packages/lexical-html/src/index.ts (1)
106-106
: LGTM! Simplified type inference in$cloneWithProperties
.The removal of the generic type parameter
<LexicalNode>
from the$cloneWithProperties
function call allows TypeScript to automatically infer the type, enhancing flexibility without affecting the function's external interface.packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx (4)
46-49
: Approved: Addition ofSerializedCustomTextNode
type.The
SerializedCustomTextNode
type effectively extendsSerializedTextNode
to include custom classes, enhancing serialization capabilities.
51-93
: Approved: Implementation ofCustomTextNode
class.The
CustomTextNode
class provides methods for managing custom classes, which enhances the flexibility and styling capabilities of text nodes.
94-104
: Approved: Utility functions forCustomTextNode
.The
$createCustomTextNode
and$isCustomTextNode
functions streamline the creation and identification of custom text nodes, improving usability.
382-439
: Approved: Tests forCustomTextNode
behavior.The tests ensure that changes to text content and class attributes of
CustomTextNode
instances are correctly tracked in the undo history, confirming accurate state management.packages/lexical-history/src/index.ts (1)
196-215
: Approved: Refactoring ofisTextNodeUnchanged
function.The refactoring simplifies the logic for detecting line deletions and ensures accurate node comparison by considering parent nodes and serialized representations.
packages/lexical-clipboard/src/clipboard.ts (1)
259-259
: Type parameter removal in$cloneWithProperties
.The removal of the type parameter from the
$cloneWithProperties
function call suggests a shift towards inferred type handling. This change is appropriate and aligns with TypeScript's type inference capabilities.packages/lexical-selection/src/lexical-node.ts (2)
39-39
: In-place modification for node properties.The return types of
$updateElementNodeProperties
,$updateTextNodeProperties
, and$updateParagraphNodeProperties
have been changed tovoid
, indicating in-place modifications. This change enhances clarity and reduces the cognitive load on developers.Also applies to: 51-51, 61-61
80-85
: Adjustment in$cloneWithProperties
for in-place updates.The
$cloneWithProperties
function has been updated to reflect the in-place modification changes. The function now directly calls the update functions without expecting a return value, streamlining the cloning process.
Description
TextNode
change detection when only one text leaf is dirty but unchanged$cloneWithProperties
- the previous implementation did not correctly handle__textFormat
fromParagraphNode
. Also updated the very incorrect doc string.$cloneWithProperties
to the lexical package because the correct implementation was already inlined inLexicalNode.getWritable()
A more general fix may be possible, it's unclear whether this hack is really necessary for MaxLengthPlugin but other text node transforms may have similar issues so removing the hack could be backwards incompatible.
Closes #6409
Test plan
Before
History's TextNode change detection did not work correctly for subclasses where only properties that did not exist on TextNode changed.
After
The tests show that the behavior is consistent with expectations
Description by Korbit AI
What change is being made?
Fix text node change detection by updating the
isTextNodeUnchanged
function, adding a newCustomTextNode
class, and modifying related test cases and utility functions.Why are these changes being made?
These changes address issue #6409, where text node changes were not being detected properly. The new
CustomTextNode
class and updated logic ensure that changes to text content and properties are accurately tracked, improving the reliability of the editor's undo/redo functionality.Summary by CodeRabbit
New Features
CustomTextNode
class for enhanced text styling and manipulation within theLexicalHistory
component.delay
parameter to theHistoryPlugin
, allowing for more control over history management timing.useFilteredExamples
to react to changes intags
, improving example filtering capabilities.Bug Fixes
Documentation
Refactor