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 2 commits into
Conversation
|
Warning Review limit reached
Next review available in: 43 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ 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(); |
There was a problem hiding this comment.
Good catch — ProseMirror processes contenteditable mutations through a MutationObserver, so the state update after execCommand('delete') isn't guaranteed to be synchronous. The test now waits for the editor to be empty before calling clear(), matching the pattern used elsewhere in this file. The vi.waitFor polls well inside the 300 ms debounce window, so the pending-change precondition the test depends on is preserved.
⚡ 1abfc61
|
Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-4174/ |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/components/text-editor/prosemirror-adapter/prosemirror-adapter.tsx:254
- The inline comment implies a pending debounced change always exists when the editor is already empty, but
clear()can be called withchangeWaiting === false. Wording it conditionally avoids misleading future readers about the invariant.
if (currentContent === '') {
// A pending change already reflects this empty content; let it
// emit so consumers still learn the document became empty.
return;
src/components/text-editor/text-editor.e2e.tsx:363
- This test can pass even if the debounced empty
change('')already fired beforeroot.clear()is called, which would no longer verify the intended regression (callingclear()while the empty change is still pending). Add an assertion that no change has been emitted yet before invokingclear().
editor.focus();
document.execCommand('selectAll');
document.execCommand('delete');
await vi.waitFor(() => {
expect(editor.textContent).toBe('');
});
await root.clear();
await sleep(DEBOUNCE_WAIT);
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