Skip to content

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

web: fix potential crash when saving note

Abdullah Attad5cf65e568a4
diff --git a/apps/web/src/components/diff-viewer/index.tsx b/apps/web/src/components/diff-viewer/index.tsx
index 1c40d10f3..219e12163 100644
--- a/apps/web/src/components/diff-viewer/index.tsx
+++ b/apps/web/src/components/diff-viewer/index.tsx
@@ -42,17 +42,17 @@ function DiffViewer(props: DiffViewerProps) {
const [content, setContent] = useState(session.content);
const [conflictedContent, setConflictedContent] = useState(
- content.conflicted
+ content?.conflicted
);
useLayoutEffect(() => {
setConflictedContent((c) => {
- if (c?.dateEdited === session.content.conflicted?.dateEdited) return c;
- return session.content.conflicted;
+ if (c?.dateEdited === session.content?.conflicted?.dateEdited) return c;
+ return session.content?.conflicted;
});
}, [session]);
- if (!conflictedContent) return null;
+ if (!conflictedContent || !content) return null;
return (
<Flex
diff --git a/apps/web/src/components/properties/index.tsx b/apps/web/src/components/properties/index.tsx
index 28f0e1a66..7273a1de5 100644
--- a/apps/web/src/components/properties/index.tsx
+++ b/apps/web/src/components/properties/index.tsx
@@ -317,7 +317,7 @@ function InternalLinkItem({
const { items, tabIndex, noteId, isExpanded, toggleExpand } = context;
const item = useResolvedItem({ items, index });
- if (!item || item.item.type !== "note") return null;
+ if (!item || item.item?.type !== "note") return null;
if (tabIndex === InternalLinksTabs.LINKED_NOTES)
return (
@@ -325,7 +325,7 @@ function InternalLinkItem({
item={item.item}
noteId={noteId}
isExpanded={isExpanded(item.item.id)}
- toggleExpand={() => toggleExpand(item.item.id)}
+ toggleExpand={() => toggleExpand(item.item!.id)}
/>
);
return (
@@ -333,7 +333,7 @@ function InternalLinkItem({
item={item.item}
noteId={noteId}
isExpanded={isExpanded(item.item.id)}
- toggleExpand={() => toggleExpand(item.item.id)}
+ toggleExpand={() => toggleExpand(item.item!.id)}
/>
);
}
diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts
index f92dd1bb3..b14f1bc8b 100644
--- a/apps/web/src/stores/editor-store.ts
+++ b/apps/web/src/stores/editor-store.ts
@@ -119,7 +119,7 @@ export type NewEditorSession = BaseEditorSession & {
export type ConflictedEditorSession = BaseEditorSession & {
type: "conflicted" | "diff";
note: Note;
- content: ContentItem;
+ content?: ContentItem;
};
export type EditorSession =
@@ -771,12 +771,12 @@ class EditorStore extends BaseStore<EditorStore> {
const session = state.sessions.find(
(s): s is ConflictedEditorSession =>
(s.type === "diff" || s.type === "conflicted") &&
- !!s.content.conflicted &&
+ !!s.content?.conflicted &&
s.content.conflicted.id === currentSession.note.contentId &&
s.content.conflicted.dateEdited ===
currentSession.note.dateEdited
);
- if (!session || !session.content.conflicted) return;
+ if (!session || !session.content?.conflicted) return;
session.content.conflicted.data = partial.content!.data;
session.content.conflicted.dateEdited = note.dateEdited;
});