Skip to content

Prevent Yjs unobserve warnings when destroy() runs after observers re…#29

Open
rahulCoder9417 wants to merge 1 commit intoyjs:masterfrom
rahulCoder9417:fix-destroy-unobserve-warning
Open

Prevent Yjs unobserve warnings when destroy() runs after observers re…#29
rahulCoder9417 wants to merge 1 commit intoyjs:masterfrom
rahulCoder9417:fix-destroy-unobserve-warning

Conversation

@rahulCoder9417
Copy link

Checklist

Are you reporting a bug?

Try to report your issue in the correct repository.

Describe the bug

Calling destroy() on a MonacoBinding instance causes Yjs to print warnings like:

[yjs] Tried to remove event handler that doesn't exist.

This happens when ytext.unobserve(this._ytextObserver) is executed after the observer has already been removed somewhere else.
The warning is harmless but noisy, and it appears frequently in projects where cleanup is triggered multiple times (e.g. hot reload, component unmounts, or integration with reactive frameworks).

To Reproduce

Create a MonacoBinding instance with a Y.Text.

Call destroy() more than once or manually call ytext.unobserve somewhere before the binding’s destroy logic runs.

Open the console.

Observe the Yjs warning:

[yjs] Tried to remove event handler that doesn't exist.

Expected behavior

destroy() should clean up safely without throwing Yjs warnings, even if the Y.Text observer was removed earlier or if destroy is called multiple times.
The method should either check before unobserving or handle the error silently.

Screenshots

N/A — console output only.

Environment Information

Browser / Node.js: (e.g. Chrome 129 / Node.js 18)

Yjs version: output of npm ls yjs

y-monaco / y-protocols / y-websocket versions

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.

1 participant