Skip to content

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

fix: opening empty note doesn't clear out editor contents

thecodrr88a93fbf05ab
diff --git a/apps/web/__e2e__/notes.test.js b/apps/web/__e2e__/notes.test.js
index e4a6f1615..5b54572c2 100644
--- a/apps/web/__e2e__/notes.test.js
+++ b/apps/web/__e2e__/notes.test.js
@@ -519,7 +519,7 @@ test.describe("run tests independently", () => {
await createNoteAndCheckPresence({ title: "Hello World" });
});
- test.only("format changes should get saved", async () => {
+ test("format changes should get saved", async () => {
const selector = await createNoteAndCheckPresence();
await page.click(getTestId("notes-action-button"));
@@ -538,6 +538,32 @@ test.describe("run tests independently", () => {
expect(content).toMatchSnapshot(`format-changes-should-get-saved.txt`);
});
+
+ test("opening an empty titled note should empty out editor contents", async () => {
+ await createNoteAndCheckPresence();
+
+ const onlyTitle = await createNoteAndCheckPresence({
+ title: "Only a title",
+ });
+
+ await page.click(getTestId("notes-action-button"));
+
+ await page.reload();
+
+ const fullNote = await checkNotePresence("home", 1, NOTE);
+
+ await page.click(fullNote);
+
+ await expect(getEditorContent()).resolves.toBe(NOTE.content);
+
+ await expect(getEditorTitle()).resolves.toBe(NOTE.title);
+
+ await page.click(onlyTitle);
+
+ await expect(getEditorTitle()).resolves.toBe("Only a title");
+
+ await expect(getEditorContent()).resolves.toBe("");
+ });
});
test.describe("stress tests", () => {
diff --git a/apps/web/__e2e__/notes.test.js-snapshots/export-html-Firefox-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/export-html-Firefox-linux.txt
index 28038ffa7..f72a0474c 100644
--- a/apps/web/__e2e__/notes.test.js-snapshots/export-html-Firefox-linux.txt
+++ b/apps/web/__e2e__/notes.test.js-snapshots/export-html-Firefox-linux.txt
@@ -11,7 +11,7 @@
</head>
<body>
<h1>Test 1</h1>
- <p>This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1<br></p>
+ <p>This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1<br></p><p><br></p>
<br/>
Created on: <b>xxx</b><br/>
Edited on: <b>xxx</b>
diff --git a/apps/web/__e2e__/notes.test.js-snapshots/export-md-Firefox-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/export-md-Firefox-linux.txt
index e479a1902..289911edf 100644
--- a/apps/web/__e2e__/notes.test.js-snapshots/export-md-Firefox-linux.txt
+++ b/apps/web/__e2e__/notes.test.js-snapshots/export-md-Firefox-linux.txt
@@ -3,6 +3,8 @@
This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1
+
+
---
_Created on: xxx_
diff --git a/apps/web/__e2e__/notes.test.js-snapshots/format-changes-should-get-saved-Firefox-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/format-changes-should-get-saved-Firefox-linux.txt
new file mode 100644
index 000000000..1d98fbbf1
--- /dev/null
+++ b/apps/web/__e2e__/notes.test.js-snapshots/format-changes-should-get-saved-Firefox-linux.txt
@@ -0,0 +1 @@
+<p><br></p>
\ No newline at end of file
diff --git a/apps/web/__e2e__/notes.test.js-snapshots/format-changes-should-get-saved-WebKit-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/format-changes-should-get-saved-WebKit-linux.txt
new file mode 100644
index 000000000..711bdf038
--- /dev/null
+++ b/apps/web/__e2e__/notes.test.js-snapshots/format-changes-should-get-saved-WebKit-linux.txt
@@ -0,0 +1 @@
+<p><strong>This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1</strong></p>
\ No newline at end of file
diff --git a/apps/web/playwright.config.js b/apps/web/playwright.config.js
index d471cca05..c5dbe4cae 100644
--- a/apps/web/playwright.config.js
+++ b/apps/web/playwright.config.js
@@ -18,14 +18,14 @@ const projects = IS_CI
browserName: "chromium",
},
},
- // {
- // name: "Firefox",
- // use: { browserName: "firefox" },
- // },
- // {
- // name: "WebKit",
- // use: { browserName: "webkit" },
- // },
+ {
+ name: "Firefox",
+ use: { browserName: "firefox" },
+ },
+ {
+ name: "WebKit",
+ use: { browserName: "webkit" },
+ },
];
module.exports = {
@@ -44,7 +44,7 @@ module.exports = {
reporter: "list",
retries: IS_CI ? 3 : 1,
use: {
- headless: false,
+ headless: true,
acceptDownloads: true,
// Artifacts
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index 4bb174bd6..1903c1d07 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -23,7 +23,7 @@ import debounce from "just-debounce-it";
import { FlexScrollContainer } from "../scroll-container";
const ReactMCE = React.lazy(() => import("./tinymce"));
-
+const EMPTY_CONTENT = "<p><br></p>";
function editorSetContent(editor, content) {
const editorScroll = document.querySelector(".editorScroll");
if (editorScroll) editorScroll.scrollTop = 0;
@@ -71,6 +71,13 @@ function Editor({ noteId, nonce }) {
[newSession, openSession, nonce]
);
+ const clearContent = useCallback(() => {
+ const editor = editorRef.current?.editor;
+ if (!editor || !editor.initialized) return;
+ editor.clearContent();
+ updateWordCount(editor);
+ }, []);
+
const setContent = useCallback(() => {
const {
id,
@@ -80,20 +87,14 @@ function Editor({ noteId, nonce }) {
if (!editor || !editor.initialized) return;
async function setContents() {
- editorSetContent(editor, data);
+ if (data) editorSetContent(editor, data);
+ else clearContent(editor);
editorstore.set((state) => (state.session.state = SESSION_STATES.stale));
if (id) await db.attachments.downloadImages(id);
}
setContents();
- }, []);
-
- const clearContent = useCallback(() => {
- const editor = editorRef.current?.editor;
- if (!editor || !editor.initialized) return;
- editor.clearContent();
- updateWordCount(editor);
- }, []);
+ }, [clearContent]);
useEffect(
function clearSession() {
@@ -105,7 +106,9 @@ function Editor({ noteId, nonce }) {
useEffect(
function openSesion() {
- if (!contentId) return;
+ // there can be notes that only have a title so we need to
+ // handle that.
+ if (!contentId && !editorstore.get().session.title) return;
setContent();
},
[sessionId, contentId, setContent, clearContent]
@@ -193,7 +196,7 @@ function Editor({ noteId, nonce }) {
onSave={saveSession}
sessionId={sessionId}
onChange={(content, editor) => {
- if (!content || content === "<p><br></p>") return;
+ if (!content || content === EMPTY_CONTENT) return;
editorstore.get().setSessionContent({
type: "tiny",