Skip to content

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

web: fix note content loading in editor

Abdullah Atta4700843517fd
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index 8d48ca772..88c9b15f2 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -23,7 +23,8 @@ import React, {
useRef,
PropsWithChildren,
Suspense,
- useLayoutEffect
+ useLayoutEffect,
+ useCallback
} from "react";
import ReactDOM from "react-dom";
import { Box, Button, Flex, Progress, Text } from "@theme-ui/components";
@@ -298,11 +299,11 @@ function EditorView({
};
}, [editor]);
- useEffect(() => {
- if (!session.needsHydration && session.content) {
- editor?.updateContent(session.content.data);
- }
- }, [editor, session]);
+ const getContent = useCallback(() => {
+ return session.content?.data;
+ }, [session.content?.data]);
+
+ if (session.needsHydration) return null;
return (
<Flex
@@ -321,7 +322,7 @@ function EditorView({
<Editor
id={session.id}
nonce={1}
- content={() => session.content?.data}
+ content={getContent}
session={session}
onPreviewDocument={(preview) =>
useEditorStore.setState({ documentPreview: preview })
@@ -665,10 +666,12 @@ function EditorChrome(props: PropsWithChildren<EditorProps>) {
parent.left - child.left - CONTAINER_MARGIN
);
- editor.style.marginLeft = `-${negativeSpace}px`;
- editor.style.marginRight = `-${negativeSpace}px`;
- editor.style.paddingLeft = `${negativeSpace}px`;
- editor.style.paddingRight = `${negativeSpace}px`;
+ requestAnimationFrame(() => {
+ editor.style.marginLeft = `-${negativeSpace}px`;
+ editor.style.marginRight = `-${negativeSpace}px`;
+ editor.style.paddingLeft = `${negativeSpace}px`;
+ editor.style.paddingRight = `${negativeSpace}px`;
+ });
}
const observer = new ResizeObserver(debounce(onResize, 500));
observer.observe(editorScrollRef.current);
diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsx
index e8b45433e..1c86b144d 100644
--- a/apps/web/src/components/editor/tiptap.tsx
+++ b/apps/web/src/components/editor/tiptap.tsx
@@ -307,8 +307,8 @@ function TipTap(props: TipTapProps) {
}
};
}, [
+ content,
readonly,
- nonce,
doubleSpacedLines,
dateFormat,
timeFormat,