File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import Image from "@tiptap/extension-image";
1212import { nodePasteRule , type PasteRuleFinder } from "@tiptap/core" ;
1313import EditorMenu from "./EditorMenu" ;
1414import { useEffect } from "react" ;
15+ import { toast } from "sonner" ;
1516
1617const getExtensions = ( ) => {
1718 const ImageFinder : PasteRuleFinder = / d a t a : i m a g e \/ / g;
@@ -60,9 +61,18 @@ const getExtensions = () => {
6061const Editor = ( ) => {
6162 const [ content , setContent ] = useAtom ( contentAtom ) ;
6263
64+ const safeParse = ( value : string | null ) => {
65+ try {
66+ return value ? JSON . parse ( value ) : "" ;
67+ } catch ( e ) {
68+ toast . error ( `Failed to parse content due to ${ e } ` ) ;
69+ return "" ;
70+ }
71+ } ;
72+
6373 const editor = useEditor ( {
6474 extensions : getExtensions ( ) ,
65- content : content ? JSON . parse ( content ) : "" ,
75+ content : safeParse ( content ) ,
6676 onUpdate : ( { editor } ) => {
6777 setContent ( JSON . stringify ( editor . getJSON ( ) ) ) ;
6878 } ,
You can’t perform that action at this time.
0 commit comments