mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-21 22:19:41 +01:00
editor: defer update propagation by 100ms
by default our editor sends an update "signal" on every single transaction. This is oftentimes unnecessary. We can improve the responsiveness by deferring this so multiple transactions cause 1 rerender.
This commit is contained in:
committed by
Abdullah Atta
parent
02459d759f
commit
f69afd2d9a
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user