fix: Loading flicker in collab editor when no local cache

This commit is contained in:
Tom Moor
2021-09-27 10:27:02 -07:00
parent 20a72481dc
commit 252459f1cf

View File

@@ -6,7 +6,6 @@ import { useHistory } from "react-router";
import { IndexeddbPersistence } from "y-indexeddb";
import * as Y from "yjs";
import Editor, { type Props as EditorProps } from "components/Editor";
import PlaceholderDocument from "components/PlaceholderDocument";
import env from "env";
import useCurrentToken from "hooks/useCurrentToken";
import useCurrentUser from "hooks/useCurrentUser";
@@ -74,7 +73,10 @@ function MultiplayerEditor({ ...props }: Props, ref: any) {
});
});
localProvider.on("synced", () => setLocalSynced(true));
localProvider.on("synced", () =>
// only set local storage to "synced" if it's loaded a non-empty doc
setLocalSynced(!!ydoc.get("default")._start)
);
provider.on("synced", () => setRemoteSynced(true));
if (debug) {
@@ -124,10 +126,6 @@ function MultiplayerEditor({ ...props }: Props, ref: any) {
return null;
}
if (isLocalSynced && !isRemoteSynced && !ydoc.get("default")._start) {
return <PlaceholderDocument includeTitle={false} delay={500} />;
}
// while the collaborative document is loading, we render a version of the
// document from the last text cache in read-only mode if we have it.
const showCache = !isLocalSynced && !isRemoteSynced;