refactor: sanitize HTML function (#8307)

* refactor: replace isomorphic-dompurify with sanitize-html

* dompurify fixes

* more fixes with fallback and title

* build

---------

Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com>
This commit is contained in:
M. Palanikannan 2025-12-11 13:30:31 +05:30 committed by GitHub
parent 76ebf395e6
commit e0c97c5471
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 235 additions and 260 deletions

View file

@ -2,22 +2,22 @@ import { useCallback, useEffect, useRef, useState } from "react";
import type { EditorRefApi, CollaborationState } from "@plane/editor";
// plane editor
import { convertBinaryDataToBase64String, getBinaryDataFromDocumentEditorHTMLString } from "@plane/editor";
// plane propel
import { setToast, TOAST_TYPE } from "@plane/propel/toast";
// plane types
import type { TDocumentPayload } from "@plane/types";
// hooks
import useAutoSave from "@/hooks/use-auto-save";
import type { TPageInstance } from "@/store/pages/base-page";
type TArgs = {
editorRef: React.RefObject<EditorRefApi>;
fetchPageDescription: () => Promise<ArrayBuffer>;
collaborationState: CollaborationState | null;
updatePageDescription: (data: TDocumentPayload) => Promise<void>;
page: TPageInstance;
};
export const usePageFallback = (args: TArgs) => {
const { editorRef, fetchPageDescription, collaborationState, updatePageDescription } = args;
const { editorRef, fetchPageDescription, collaborationState, updatePageDescription, page } = args;
const hasShownFallbackToast = useRef(false);
const [isFetchingFallbackBinary, setIsFetchingFallbackBinary] = useState(false);
@ -32,12 +32,7 @@ export const usePageFallback = (args: TArgs) => {
// Show toast notification when fallback mechanism kicks in (only once)
if (!hasShownFallbackToast.current) {
// setToast({
// type: TOAST_TYPE.WARNING,
// title: "Connection lost",
// message: "Your changes are being saved using backup mechanism. ",
// });
console.log("Connection lost");
console.warn("Websocket Connection lost, your changes are being saved using backup mechanism.");
hasShownFallbackToast.current = true;
}
@ -49,7 +44,11 @@ export const usePageFallback = (args: TArgs) => {
if (latestEncodedDescription && latestEncodedDescription.byteLength > 0) {
latestDecodedDescription = new Uint8Array(latestEncodedDescription);
} else {
latestDecodedDescription = getBinaryDataFromDocumentEditorHTMLString("<p></p>");
const pageDescriptionHtml = page.description_html;
latestDecodedDescription = getBinaryDataFromDocumentEditorHTMLString(
pageDescriptionHtml ?? "<p></p>",
page.name
);
}
editor.setProviderDocument(latestDecodedDescription);
@ -64,15 +63,10 @@ export const usePageFallback = (args: TArgs) => {
});
} catch (error: any) {
console.error(error);
// setToast({
// type: TOAST_TYPE.ERROR,
// title: "Error",
// message: `Failed to update description using backup mechanism, ${error?.message}`,
// });
} finally {
setIsFetchingFallbackBinary(false);
}
}, [editorRef, fetchPageDescription, hasConnectionFailed, updatePageDescription]);
}, [editorRef, fetchPageDescription, hasConnectionFailed, updatePageDescription, page.description_html, page.name]);
useEffect(() => {
if (hasConnectionFailed) {