-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Load/auto-save document from the back-end using y-py #12360
Conversation
Thanks for making a pull request to jupyterlab! |
@hbcarlos with your changes, I get in this error in the browser while opening a notebook:
|
I also get this error in the back-end, so it might be related. |
978b0ee
to
17ae24f
Compare
Now that we watch file changes and update the Y document with the saved content, I don't think it makes sense for the user to be able to e.g. press Ctrl-S to save. We basically guarantee that what the user sees in the front-end is in sync with every other client, including the back-end. |
76f8c15
to
fd1357b
Compare
8e9aebe
to
e606517
Compare
You are right, we are storing I think we should move the |
That sound good, the notebook's metadata is actually stored in |
I'll make the changes in the frontend. |
Thanks, the problem is that we would need |
Actually, it's only to have tests pass in jupyter-server/jupyter_ydoc#21, so maybe we don't need a release. |
It might make sense to only modify the shared A potential problem is that a client modifies a document (setting |
I was thinking about that too, but @afshin mentioned that we still want the dirty flag to work when the front-end looses connection, and this is a good point. |
Hmm.. that makes sense. There could be a local class SharedModel {
constructor () {
..
this._localDirty = false
this._ymeta = ydoc.getMap('meta')
this._ymeta.observe(event => {
if (event.changed.has('dirty')) {
this._localDirty = this._ymeta.get('dirty')
// potentially fire dirty-changed observer here
}
})
..
}
get dirty () {
return this._localDirty
}
set dirty () {
this._localDirty = true
}
} |
Yep, I agree we should only modify it on the backend and keep a local variable in the frontend. |
#2) * Moves nbformat and nbformat_minor to ymeta, changes the YNotebook event to support the new nbformat, and adds a local dirty property * Pin jupyter_ydoc>=0.1.8
@hbcarlos I thought that when the front-end changes the document, it would only set a local dirty flag, and let the back-end set the shared dirty flag when the document changes, but with your changes I see that the dirty flag is seen by all front-ends, and I've not changed the back-end yet to set the dirty flag. |
Yep, my bad. I added the local dirty attribute in the NotebookModel but I forgot the DocumentModel... I'm on it |
Mmmm I'm seeing the same thing after this new commit @hbcarlos. |
Yes, it is. the sharedModel is still initializing the dirty property.
I'm on it 🤣 |
* Removes the initialization of the dirty property from the frontend * Remove setting dirty in the SharedDocument
This is ready to be merged! |
Let's move on with this. |
@davidbrochart, just to confirm, you need to have collaborative mode enabled to make this work as described in the top message, right? |
@damianavila yes, this only works in collaborative mode. |
* Load document from the back-end using y-py * Load only documents metadata when collaborative * Delay closing the room in the backend * Update Yjs * Fix notebook ycell initialization * Watch file change in the back-end and overwrite Y document * Automatically save from the back-end * Small fixes * Use ypy-websocket's WebsocketServer * Poll for file changes for now, until watchfiles is fixed * Use ypy-websocket v0.1.2 * Remove watchfiles * Rename save_document to maybe_save_document, add collab_file_poll_interval config * Workaround ypy bug * Fix for new notebook * Use jupyter_ydoc * Rename yjs_echo_ws.py->ydoc_handler.py, YjsEchoWebSocket->YDocWebSocketHandler * Update ypy-websocket and jupyter_ydoc minimum versions * Use ypy-websocket>=0.1.6 * Update jupyter_ydoc>=0.1.4 * Move WEBSOCKET_SERVER global variable to YDocWebSocketHandler class attribute * Fix tests * Update jupyterlab/staging/package.json * Rename collab_file_poll_interval to collaborative_file_poll_interval, update extension migration documentation * Set room name as file_type:file_name * Don't save file if already on disk * Pin jupyter_ydoc>=0.1.5 * Set room name as format:type:path * Disable save button * Show caption only in collaborative mode * Sync file attributes with room name * Clear dirty flag when opening document * Pin jupyter_ydoc>=0.1.7 which observes the dirty flag * Don't save when dirty flag cleared * Moves nbformat and nbformat_minor to ymeta, changes the YNotebook eve… (#2) * Moves nbformat and nbformat_minor to ymeta, changes the YNotebook event to support the new nbformat, and adds a local dirty property * Pin jupyter_ydoc>=0.1.8 * Adds a local dirty property in the DocumentModel (#3) * Removes the initialization of the dirty property from the frontend (#4) * Removes the initialization of the dirty property from the frontend * Remove setting dirty in the SharedDocument Co-authored-by: hbcarlos <[email protected]> Co-authored-by: Frédéric Collonval <[email protected]>
References
Follow-up of #11599.
Code changes
We don't fetch a file content through HTTP anymore, the file is loaded when the Yjs websocket is opened.
The front-end doesn't request or put an initial content through the Yjs websocket anymore, it just syncs the Y document directly.
Pressing Ctrl-S in collaborative mode doesn't send an HTTP request, as every change to the document is auto-saved in the back-end.
User-facing changes
When a user changes a document, it is marked as dirty for one second then automatically saved.
A change made to a file in the back-end is automatically propagated to every user.
Backwards-incompatible changes
requestInitialContent
andputInitializedState
have been removed from theIDocumentProvider
interface in the@jupyterlab/docprovider
package.