I was expecting Y.encodeStateAsUpdate
to return the same value for the same ydoc every single time.
Is my expectation incorrect?
My experiments show that some times it can return differnt value. See output at the bottom.
NOTE: In order to reproduce the problem, please run it from the shell script as shown below. It’s very hard to reproduce this otherwise.
yupdate.js
const Y = require("yjs");
const ydoc = new Y.Doc();
ydoc.getMap("foo").set("a", "a");
ydoc.getMap("foo").set("b", "b");
ydoc.getMap("foo").set("c", "c");
ydoc.getMap("bar").set("d", "d");
ydoc.getMap("bar").set("e", []);
ydoc.getMap("bar").set("f", []);
ydoc.getArray("0").insert(0, []);
ydoc.getArray("1").insert(0, []);
ydoc.getArray("2").insert(0, []);
ydoc.getArray("3").insert(0, []);
ydoc.getArray("4").insert(0, []);
console.log(Y.encodeStateAsUpdate(ydoc).length);
run.sh (chmod +x run.sh)
#!/bin/bash
for (( ; ; ))
do
node yupdate.js
done
Run the shell script and observe that some times it returns different value for the length of the update.
$ ./run.sh
79
79
79
79
78 ← here
79
79
79
79
79
79
79
79
79
79
78 ← here
79
79
79
79
79
78 ← here