Skip to content

fix(editor): prevent yjs rebinding on keystrokes#460

Open
Rishabhworkspace wants to merge 3 commits into
piyushdotcomm:mainfrom
Rishabhworkspace:main
Open

fix(editor): prevent yjs rebinding on keystrokes#460
Rishabhworkspace wants to merge 3 commits into
piyushdotcomm:mainfrom
Rishabhworkspace:main

Conversation

@Rishabhworkspace

@Rishabhworkspace Rishabhworkspace commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Closes #458
Closes #459

What is broken?
The Yjs/Monaco collaboration binding is torn down and rebuilt on every keystroke because content (the live file text) is incorrectly listed as a useEffect dependency. This causes excessive network calls to /api/collab-token and causes remote cursors to flicker and disappear.

Fix:

  • Added a contentRef to track the latest content value without triggering re-renders.
  • Used contentRef.current inside the Yjs useEffect for initial seeding instead of the reactive content prop.
  • Removed content from the useEffect dependency array.

Verification:

  • The Yjs binding is now established only once when the file or playground changes.
  • Typing in the editor no longer tears down the binding or triggers repeated token requests.
  • Cursors from collaborators are now stable.

Summary by CodeRabbit

  • Bug Fixes

    • Improved collaborative editor initialization so shared documents reliably populate with the latest content.
    • Removed noisy debug logging from the AI chat flow to reduce console clutter.
  • Chores

    • Updated ignore rules to exclude a documentation file from source control.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@github-actions github-actions Bot added the bug Something isn't working label Jun 3, 2026
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

👋 Thanks for opening a PR, @Rishabhworkspace!

Your PR has entered the 🚦 PR Review Pipeline.

Standard PR detected — your PR will follow the standard review pipeline.


What happens next

Stage Reviewer Checks
Stage 1 — Automated Validation 🤖 Bot DCO · Format · AI/Slop · Duplicate
Stage 2 — Human Review 👥 Maintainer Code + Quality Review
Stage 3 — PA / Maintainer Review 🔑 Project Admin Final Merge Decision

A pipeline status comment will appear below and update automatically as your PR progresses.


While you wait

  • Sign all commits (git commit -s)
  • Link your issue (Closes #123)
  • Use a feature branch (not main)
  • Avoid unrelated changes

This comment is posted only once.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Decouples editor content tracking from Yjs binding using a ref and adjusts binding dependencies to avoid rebinding on keystrokes; removes debug console logs from the AI chat panel; adds docs/github-issues.md to .gitignore.

Changes

Bug Fix: Yjs Binding Stability, Logging Cleanup, and Git Configuration

Layer / File(s) Summary
Yjs binding lifecycle and content ref synchronization
modules/playground/components/playground-editor.tsx
Adds contentRef with an effect to track the latest content prop; uses contentRef.current when initially populating Yjs text; updates the Yjs/Monaco binding effect deps to isMounted and session, removing content.
AI chat panel debug log removals
modules/playground/components/ai-chat-panel.tsx
Removes two debug-only console.log statements used during tool-call processing and after tool execution; core logic unchanged.
Git ignore update for generated docs
.gitignore
Adds docs/github-issues.md to ignore patterns.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #459 — Matches removals of identical debug console.log statements in ai-chat-panel.tsx.
  • #278 — Also reports removal of verbose debug logging in ai-chat-panel.tsx.

Suggested labels

mentor:piyushdotcomm, level:intermediate

Suggested reviewers

  • piyushdotcomm
  • Maxd646

Poem

🐰 I held the content in a tiny ref so neat,
No rebinding dances with each tapping beat.
Quieted the logs, the console sleeps sound,
Docs tucked away, ignored and safe and round.
Hooray — collaborative fields stay calm and sweet!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The changes in .gitignore (ignoring docs/github-issues.md) and removal of debug logs in ai-chat-panel.tsx are unrelated to issue #458's objectives. Remove the .gitignore change and ai-chat-panel.tsx debug log removal, or create separate PRs for these unrelated modifications. This PR should focus solely on fixing the Yjs rebinding issue.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: preventing Yjs rebinding on keystrokes, which directly addresses the core issue resolved by the PR.
Linked Issues check ✅ Passed The PR fully addresses all coding objectives from issue #458: preventing Yjs rebinding on keystrokes, eliminating repeated token requests, and stabilizing collaborator cursors through useEffect dependency management.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description comprehensively covers the problem, fix, and verification with clear examples matching the PR template structure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

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

Labels

bug Something isn't working

Projects

None yet

1 participant