Skip to content

fix(text-editor): keep the pending empty change when clear finds an empty editor - #4174

Open
john-traas wants to merge 2 commits into
mainfrom
fix-text-editor-clear-pending-change
Open

fix(text-editor): keep the pending empty change when clear finds an empty editor#4174
john-traas wants to merge 2 commits into
mainfrom
fix-text-editor-clear-pending-change

Conversation

@john-traas

Copy link
Copy Markdown
Contributor

What

Reorders clear() in limel-prosemirror-adapter so the already-empty check runs before the pending debounced change is cancelled. When the editor is already empty, any pending change emission reflects that same empty content and is now allowed to fire; the cancel only happens when clear() is actually about to replace non-empty content.

Why

A user emptying the editor queues a debounced change(''). If the consumer calls clear() 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

  • New e2e test covering the exact scenario (user-clear followed by clear() inside the debounce window)
  • text-editor e2e: 19/19 passing

🤖 Generated with Claude Code

@john-traas
john-traas requested a review from Copilot July 8, 2026 11:02
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@john-traas, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e2912d7e-9072-473b-98fa-dd02bd553909

📥 Commits

Reviewing files that changed from the base of the PR and between 8610768 and 1abfc61.

📒 Files selected for processing (2)
  • src/components/text-editor/prosemirror-adapter/prosemirror-adapter.tsx
  • src/components/text-editor/text-editor.e2e.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-text-editor-clear-pending-change

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +356 to +359
document.execCommand('selectAll');
document.execCommand('delete');

await root.clear();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-4174/

@john-traas
john-traas marked this pull request as ready for review August 10, 2026 09:41
@john-traas
john-traas requested a lite review from Copilot August 10, 2026 09:41
@john-traas john-traas self-assigned this Aug 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 with changeWaiting === 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 before root.clear() is called, which would no longer verify the intended regression (calling clear() while the empty change is still pending). Add an assertion that no change has been emitted yet before invoking clear().
            editor.focus();
            document.execCommand('selectAll');
            document.execCommand('delete');
            await vi.waitFor(() => {
                expect(editor.textContent).toBe('');
            });

            await root.clear();
            await sleep(DEBOUNCE_WAIT);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants