Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: defer update propagation by 100ms

Abdullah Attaf69afd2d9abb
diff --git a/packages/editor/src/hooks/use-editor.ts b/packages/editor/src/hooks/use-editor.ts
index 89e9d3214..3235a7fe4 100644
--- a/packages/editor/src/hooks/use-editor.ts
+++ b/packages/editor/src/hooks/use-editor.ts
@@ -34,6 +34,7 @@ export const useEditor = (
const [editor, setEditor] = useState<Editor | null>(null);
const forceUpdate = useForceUpdate();
const editorRef = useRef<Editor | null>(editor);
+ const updateTimeout = useRef<number>();
useEffect(
() => {
@@ -44,13 +45,16 @@ export const useEditor = (
setEditor(instance);
instance.on("transaction", () => {
- requestAnimationFrame(() => {
+ clearTimeout(updateTimeout.current);
+ updateTimeout.current = setTimeout(() => {
requestAnimationFrame(() => {
- if (isMounted) {
- forceUpdate();
- }
+ requestAnimationFrame(() => {
+ if (isMounted) {
+ forceUpdate();
+ }
+ });
});
- });
+ }, 100) as unknown as number;
});
return () => {