🐛(frontend) fix versioning conflict
We switching from one version to the other, depending on the blocks inside, the version editor could crash due to conflicts between the different versions. We now reset the previous content when switching version to avoid these conflicts.
This commit is contained in:
@@ -77,7 +77,6 @@ export function useDocVersionsInfiniteQuery(
|
||||
getNextPageParam(lastPage) {
|
||||
return lastPage.next_version_id_marker || undefined;
|
||||
},
|
||||
|
||||
...queryConfig,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,13 +32,18 @@ export const DocVersionEditor = ({
|
||||
const { replace } = useRouter();
|
||||
const [initialContent, setInitialContent] = useState<Y.XmlFragment>();
|
||||
|
||||
// Reset initialContent when versionId changes to avoid conflicts between versions
|
||||
useEffect(() => {
|
||||
if (!version?.content) {
|
||||
setInitialContent(undefined);
|
||||
}, [versionId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!version?.content || isLoading || initialContent) {
|
||||
return;
|
||||
}
|
||||
|
||||
setInitialContent(base64ToBlocknoteXmlFragment(version.content));
|
||||
}, [version?.content]);
|
||||
}, [versionId, version?.content, isLoading, initialContent]);
|
||||
|
||||
if (isError && error) {
|
||||
if (error.status === 404) {
|
||||
|
||||
Reference in New Issue
Block a user