Skip to content

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

Draft
john-traas wants to merge 1 commit into
mainfrom
fix-text-editor-clear-pending-change
Draft

fix(text-editor): keep the pending empty change when clear finds an empty editor#4174
john-traas wants to merge 1 commit 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

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 97bbe2b3-588d-4d1f-8c1f-9ce286c281e7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ 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();
@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/

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