A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: sometimes editor is empty on startup
thecodrr2316baefd438
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.jsindex be8e6af55..996da8abd 100644--- a/apps/web/src/components/editor/index.js+++ b/apps/web/src/components/editor/index.js@@ -54,36 +54,46 @@ function Editor({ noteId, nonce }) {})();}, [startSession, noteId, nonce]);- useEffect(() => {- if (sessionState === SESSION_STATES.new) {- editorstore.set((state) => (state.session.state = SESSION_STATES.stale));- const {- id,- content: { data },- } = editorstore.get().session;- const editor = editorRef.current?.editor;- if (!editor) return;- clearTimeout(editor.changeTimeout);- async function setContents() {- // NOTE: workaround to not fire onEditorChange event on content load- editor.isLoading = true;- editor.setContent(data, { format: "html" });+ const setContent = useCallback(() => {+ const {+ id,+ content: { data },+ } = editorstore.get().session;+ const editor = editorRef.current?.editor;+ if (!editor) return;- editor.undoManager.reset();- editor.setDirty(false);+ clearTimeout(editor.changeTimeout);+ async function setContents() {+ if (!editor.initialized) return;- if (id) await db.attachments.downloadImages(id);- }+ // NOTE: workaround to not fire onEditorChange event on content load+ editor.isLoading = true;+ editor.setContent(data, { format: "html" });- if (!isMobile) editor.focus();+ editor.undoManager.reset();+ editor.setDirty(false);- setContents();- editor.on("init", setContents);- return () => {- editor.off("init", setContents);- };+ editorstore.set((state) => (state.session.state = SESSION_STATES.stale));+ if (id) await db.attachments.downloadImages(id);+ }++ if (!isMobile) editor.focus();++ setContents();+ }, [isMobile]);++ useEffect(() => {+ if (sessionState === SESSION_STATES.new) {+ setContent();}- }, [editorRef, isMobile, contentType, sessionState, sessionNonce]);+ }, [+ editorRef,+ isMobile,+ contentType,+ sessionState,+ sessionNonce,+ setContent,+ ]);return (<Flex@@ -163,6 +173,7 @@ function Editor({ noteId, nonce }) {onWordCountChanged={updateWordCount}onInit={async () => {await startSession(noteId);+ setContent();}}/></>diff --git a/apps/web/src/components/editor/tinymce.js b/apps/web/src/components/editor/tinymce.jsindex b0e6cc087..4dbe327bb 100644--- a/apps/web/src/components/editor/tinymce.js+++ b/apps/web/src/components/editor/tinymce.js@@ -181,11 +181,6 @@ function TinyMCE(props) {<Editorref={tinymceRef}onFocus={onFocus}- onInit={(args, editor) => {- editor.serializer.addTempAttr("data-progress");- clearTimeout(editor.changeTimeout);- onInit(args, editor);- }}initialValue={initialValue}init={{//experimental@@ -219,6 +214,11 @@ function TinyMCE(props) {link_title: false,imagetools_toolbar:"rotateleft rotateright | flipv fliph | alignleft aligncenter alignright",+ init_instance_callback: (editor) => {+ editor.serializer.addTempAttr("data-progress");+ clearTimeout(editor.changeTimeout);+ onInit(editor);+ },setup: (editor) => {editor.on("ScrollIntoView", (e) => {e.preventDefault();