-
Notifications
You must be signed in to change notification settings - Fork 6
Handle document resets / out-of-band changes on text files #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle document resets / out-of-band changes on text files #83
Conversation
|
Added reviewer instructions & opened new issues for follow-up items. This PR is now ready for review! 🎉 |
ee6c495 to
54c993d
Compare
|
Rebased the PR onto #84, addressed merge conflicts, and renamed the plugin to reflect the new package name. |
|
@3coins Thank you for catching that issue. I found a way to reproduce #89 and added those details in a new comment. I've just pushed a few commits that fix #89. These changes now:
Here's a demo video showing that it works well now: Screen.Recording.2025-05-29.at.10.42.49.AM.mov |
3coins
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dlqqq
Added some minor comments, looks good otherwise.
One side-effect I observed now is that the dirty flag of text file is not reset, this seems to be new which wasn't present with your previous commit. This could be a front-end issue, so can be tackled in a separate PR. Ok to merge and iterate.
|
@3coins Thank you for the feedback & for catching these bugs! Really appreciate your help in testing this branch. I've incorporated your suggestions & fixed the main issue you just reported; the "unsaved changes" icon is now hidden after an out-of-band change. Screen.Recording.2025-05-29.at.2.25.34.PM.mov |
3coins
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to merge after recent updates. 🚀
|
Thanks for this work, going to merge so @dlqqq can work on the out of band changes for notebooks. |
Description
Fixes #9.
Fixes #89.
This PR adds out-of-band change handling for text files. Supporting notebooks is still a WIP and will be done in a future PR, as this PR is already quite long.
Demo video
Screen.Recording.2025-05-23.at.4.52.39.PM.mov
Backend changes
Adds a new
YRoom.reload_ydoc()method. This method:4000(discussed later).YRoomFileAPIto block any new saves.self._ydoc,self._awareness, andself._jupyter_ydocto reset the shared docs to an empty state.YRoomFileAPI, reloading the YDoc content from theContentsManager.Updates
YRoomFileAPIto watch the file on a loop & detect out-of-band changes based on thelast_modifiedtimestamp. When this happens,YRoomFileAPIcallsYRoom.reload_ydoc().When an out-of-band change is detected, the server closes each WS with close code
4000. This is a special value that the frontend also uses to become informed of out-of-band changes.Frontend changes
The changes are pretty complicated. In summary, this PR overrides the
'@jupyterlab/codemirror-extension:binding'plugin & re-implements it.When this plugin is activated, it adds an extension to the Codemirror editor that syncs it with the underlying
YTextobject within aYFileor aYCellwithin aYNotebook.I've modified the
YFileobject to add the following to its interface:The
reset()method re-initializes the YDoc & awareness (similar toYRoom.reload_ydoc(), but doesn't load content). It then callsresetSignal.emit()to tell the Codemirror editor to clear itself. Whenever the client receives close code 4000, thereset()method is called, since the YDoc needs to be reset when an out-of-band change occurs.I then modified the Codemirror Yjs plugin's interface. Instead of taking
ytext: YText, it now takes:When the reset signal fires, it just calls
getYText()again to get the newYTextinstance, then resets the editor to an empty state. The editor then gets populated with the new content following the SS1 + SS2 handshake.Reviewer instructions
This PR also adds a
dev/reset-untitled-txt.shscript. To test this PR:jlpm builduntitled.txtand make some editsNext steps
'@jupyterlab/codemirror'.References
The close code range
4000-4999is reserved for private use (by applications) according to RFC 6455.