Skip to content

Commit 73ff17f

Browse files
committed
fix OOB change after IB move, thanks @3coins
1 parent 7456b2c commit 73ff17f

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

jupyter_server_documents/rooms/yroom_file_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ def load_ydoc_content(self) -> None:
155155
if self._ydoc_content_loaded.is_set() or self._ydoc_content_loading:
156156
return
157157

158-
self.log.info(f"Loading content for room ID '{self.room_id}'.")
159158
self._ydoc_content_loading = True
160159
self._loop.create_task(self._load_ydoc_content())
161160

@@ -168,6 +167,7 @@ async def _load_ydoc_content(self) -> None:
168167
self._last_path = path
169168

170169
# Load the content of the file from the path
170+
self.log.info(f"Loading content for room ID '{self.room_id}', found at path: '{path}'.")
171171
file_data = await ensure_async(self._contents_manager.get(
172172
path,
173173
type=self.file_type,

src/docprovider/yprovider.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,49 @@ export class WebSocketProvider implements IDocumentProvider {
140140
this._connect();
141141
}
142142

143+
/**
144+
* Gets the file ID for this path. This should only be called once when the
145+
* provider connects for the first time, because any future in-band moves may
146+
* cause `this._path` to not refer to the correct file.
147+
*/
148+
private async _getFileId(): Promise<string | null> {
149+
let fileId: string | null = null;
150+
try {
151+
const resp = await requestAPI(`api/fileid/index?path=${this._path}`, {
152+
method: 'POST'
153+
});
154+
if (resp && 'id' in resp && typeof resp['id'] === 'string') {
155+
fileId = resp['id'];
156+
}
157+
} catch (e) {
158+
console.error(`Could not get file ID for path '${this._path}'.`);
159+
return null;
160+
}
161+
return fileId;
162+
}
163+
143164
private async _connect(): Promise<void> {
144-
// Fetch file ID from the file ID service.
145-
const resp = await requestAPI(`api/fileid/index?path=${this._path}`, {
146-
method: 'POST'
147-
});
148-
const fileId: string = resp['id'];
165+
// Fetch file ID from the file ID service, if not cached
166+
if (!this._fileId) {
167+
this._fileId = await this._getFileId();
168+
}
169+
170+
// If file ID could not be retrieved, show an error dialog asking for a bug
171+
// report, as this error is irrecoverable.
172+
if (!this._fileId) {
173+
showErrorMessage(
174+
this._trans.__('File ID error'),
175+
`The file '${this._path}' cannot be opened because its file ID could not be retrieved. Please report this issue on GitHub.`,
176+
[Dialog.okButton()]
177+
);
178+
return;
179+
}
149180

181+
// Otherwise, initialize the `YWebsocketProvider` to connect
182+
console.log({ fileId: this._fileId });
150183
this._yWebsocketProvider = new YWebsocketProvider(
151184
this._serverUrl,
152-
`${this._format}:${this._contentType}:${fileId}`,
185+
`${this._format}:${this._contentType}:${this._fileId}`,
153186
this._sharedModel.ydoc,
154187
{
155188
disableBc: true,
@@ -305,6 +338,7 @@ export class WebSocketProvider implements IDocumentProvider {
305338
private _sharedModel: YDocument<DocumentChange>;
306339
private _yWebsocketProvider: YWebsocketProvider | null;
307340
private _trans: TranslationBundle;
341+
private _fileId: string | null = null;
308342
}
309343

310344
/**

0 commit comments

Comments
 (0)