Skip to content

Commit 5e72215

Browse files
committed
fix a bug where a file might appear blank the very first time it is opened
- i observed this 2 or 3 times after opening hundreds of files - but this is clearly the correct fix and the code before was wrong.
1 parent 5da6415 commit 5e72215

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/packages/sync/editor/generic/sync-doc.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,8 +1460,8 @@ export class SyncDoc extends EventEmitter {
14601460
this.assert_not_closed("initAll -- before ensuring syncstring exists");
14611461
await this.ensure_syncstring_exists_in_db();
14621462

1463-
await this.init_syncstring_table(),
1464-
this.assert_not_closed("initAll -- successful init_syncstring_table");
1463+
await this.init_syncstring_table();
1464+
this.assert_not_closed("initAll -- successful init_syncstring_table");
14651465

14661466
log("patch_list, cursors, evaluator, ipywidgets");
14671467
this.assert_not_closed(
@@ -1504,7 +1504,7 @@ export class SyncDoc extends EventEmitter {
15041504
// this will finish.
15051505
// if (!this.client.is_browser() && !this.client.is_project()) {
15061506
// // FAKE DELAY!!! Just to simulate flakiness / slow network!!!!
1507-
// await delay(10000);
1507+
// await delay(3000);
15081508
// }
15091509
await retry_until_success({
15101510
f: this.init_load_from_disk,
@@ -1563,22 +1563,28 @@ export class SyncDoc extends EventEmitter {
15631563
}
15641564
}
15651565

1566+
let init;
15661567
const is_init = (t: SyncTable) => {
15671568
this.assert_not_closed("is_init");
15681569
const tbl = t.get_one();
15691570
if (tbl == null) {
15701571
dbg("null");
15711572
return false;
15721573
}
1573-
return tbl.get("init") != null;
1574+
init = tbl.get("init")?.toJS();
1575+
return init != null;
15741576
};
15751577
dbg("waiting for init...");
1576-
const init = await this.syncstring_table.wait(is_init, 0);
1578+
await this.syncstring_table.wait(is_init, 0);
15771579
dbg("init done");
15781580
if (init.error) {
15791581
throw Error(init.error);
15801582
}
15811583
assertDefined(this.patch_list);
1584+
if (init.size == null) {
1585+
// don't crash but warn at least.
1586+
console.warn("SYNC BUG -- init.size must be defined", { init });
1587+
}
15821588
if (
15831589
!this.client.is_project() &&
15841590
this.patch_list.count() === 0 &&
@@ -2937,8 +2943,8 @@ export class SyncDoc extends EventEmitter {
29372943
size = data.length;
29382944
dbg(`got it -- length=${size}`);
29392945
this.from_str(data);
2940-
// we also know that this is the version on disk, so we update the hash
29412946
this.commit();
2947+
// we also know that this is the version on disk, so we update the hash
29422948
await this.set_save({
29432949
state: "done",
29442950
error: "",

src/packages/util/smc-version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/* autogenerated by the update_version script */
2-
exports.version=1750777285;
2+
exports.version=1751049898;

0 commit comments

Comments
 (0)