Skip to content

Commit c557ee3

Browse files
committed
fix loop of OOB events when opening NB in 2 editors
1 parent 7846e7e commit c557ee3

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

jupyter_server_documents/rooms/yroom.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -642,19 +642,23 @@ def should_ignore_state_update(event: pycrdt.MapEvent) -> bool:
642642
more info.
643643
"""
644644
# Iterate through the keys added/updated/deleted by this event. Return
645-
# `False` if:
646-
# - any key was not updated (i.e. a key was added/deleted), or
647-
# - the key was updated to a value different from the previous value
645+
# `False` immediately if:
646+
# - a key was updated to a value different from the previous value
647+
# - a key was added with a value different from the previous value
648648
for key in event.keys.keys():
649-
key_update = event.keys[key]
650-
action = key_update.get('action', None)
651-
if action != 'update':
652-
return False
649+
update_info = event.keys[key]
650+
action = update_info.get('action', None)
651+
if action == 'update':
652+
old_value = update_info.get('oldValue', None)
653+
new_value = update_info.get('newValue', None)
654+
if old_value != new_value:
655+
return False
656+
elif action == "add":
657+
old_value = event.target.get(key, None)
658+
new_value = update_info.get('newValue', None)
659+
if old_value != new_value:
660+
return False
653661

654-
old_value = key_update.get('oldValue', None)
655-
new_value = key_update.get('newValue', None)
656-
if old_value != new_value:
657-
return False
658-
662+
# Otherwise, return `True`.
659663
return True
660664

src/docprovider/yprovider.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ export class WebSocketProvider implements IDocumentProvider {
190190
if (isSynced) {
191191
if (this._yWebsocketProvider) {
192192
this._yWebsocketProvider.off('sync', this._onSync);
193-
194-
const state = this._sharedModel.ydoc.getMap('state');
195-
state.set('document_id', this._yWebsocketProvider.roomname);
196193
}
197194
this._ready.resolve();
198195
}

0 commit comments

Comments
 (0)