fix(text-editor): keep the pending empty change when clear finds an empty editor#4174
fix(text-editor): keep the pending empty change when clear finds an empty editor#4174john-traas wants to merge 1 commit into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes an edge case in the text editor’s ProseMirror adapter where calling clear() on an already-empty editor could previously cancel a pending debounced change('') emission, leaving consumers with a stale non-empty bound value.
Changes:
- Reorders
clear()logic so the “already empty” check happens before canceling any pending debounced change. - Adds an e2e test covering the “user clears content, then consumer calls
clear()within the debounce window” scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/components/text-editor/prosemirror-adapter/prosemirror-adapter.tsx | Reorders clear() to preserve pending empty debounced change when editor content is already empty. |
| src/components/text-editor/text-editor.e2e.tsx | Adds e2e coverage for the pending-empty-change behavior when clear() is called on an already-empty editor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| document.execCommand('selectAll'); | ||
| document.execCommand('delete'); | ||
|
|
||
| await root.clear(); |
|
Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-4174/ |
What
Reorders
clear()inlimel-prosemirror-adapterso the already-empty check runs before the pending debounced change is cancelled. When the editor is already empty, any pendingchangeemission reflects that same empty content and is now allowed to fire; the cancel only happens whenclear()is actually about to replace non-empty content.Why
A user emptying the editor queues a debounced
change(''). If the consumer callsclear()within the 300 ms debounce window, the previous order cancelled that emission and then returned early — the consumer never learned the document became empty and its bound value stayed stale.The existing contracts are unchanged: clearing non-empty content still discards the pending change (no stale emit), and
clear()itself still emits nothing.Verification
clear()inside the debounce window)🤖 Generated with Claude Code