fix note parser

This commit is contained in:
Ren Amamiya
2023-05-06 08:02:53 +07:00
parent 65aebcc3a3
commit 30c39d27f5
5 changed files with 26 additions and 7 deletions

View File

@@ -10,9 +10,18 @@ import { memo, useContext } from 'react';
import useSWRSubscription from 'swr/subscription';
import { navigate } from 'vite-plugin-ssr/client/router';
function isJSON(str: string) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
export const RootNote = memo(function RootNote({ id, fallback }: { id: string; fallback?: any }) {
const pool: any = useContext(RelayContext);
const parseFallback = fallback.length > 1 ? JSON.parse(fallback) : null;
const parseFallback = isJSON(fallback) ? JSON.parse(fallback) : null;
const { data, error } = useSWRSubscription(parseFallback ? null : id, (key, { next }) => {
const unsubscribe = pool.subscribe(