mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-04-25 11:18:22 +00:00
Fix abnormal preview of HTML files (#1986)
* Fix HTML artifact preview rendering * Add after screenshot for HTML preview fix * Add before screenshot for HTML preview fix * Update before screenshot for HTML preview fix * Update after screenshot for HTML preview fix * Update before screenshot to Tsinghua homepage repro * Update after screenshot to Tsinghua homepage preview * Address PR review on HTML artifact preview * Harden HTML artifact preview isolation
This commit is contained in:
parent
52718b0f23
commit
140907ce1d
@ -83,7 +83,7 @@ export function ArtifactFileDetail({
|
|||||||
const isSupportPreview = useMemo(() => {
|
const isSupportPreview = useMemo(() => {
|
||||||
return language === "html" || language === "markdown";
|
return language === "html" || language === "markdown";
|
||||||
}, [language]);
|
}, [language]);
|
||||||
const { content, url } = useArtifactContent({
|
const { content } = useArtifactContent({
|
||||||
threadId,
|
threadId,
|
||||||
filepath: filepathFromProps,
|
filepath: filepathFromProps,
|
||||||
enabled: isCodeFile && !isWriteFile,
|
enabled: isCodeFile && !isWriteFile,
|
||||||
@ -194,7 +194,7 @@ export function ArtifactFileDetail({
|
|||||||
tooltip={t.common.openInNewWindow}
|
tooltip={t.common.openInNewWindow}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const w = window.open(
|
const w = window.open(
|
||||||
urlOfArtifact({ filepath, threadId }),
|
urlOfArtifact({ filepath, threadId, isMock }),
|
||||||
"_blank",
|
"_blank",
|
||||||
"noopener,noreferrer",
|
"noopener,noreferrer",
|
||||||
);
|
);
|
||||||
@ -226,7 +226,12 @@ export function ArtifactFileDetail({
|
|||||||
tooltip={t.common.download}
|
tooltip={t.common.download}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const w = window.open(
|
const w = window.open(
|
||||||
urlOfArtifact({ filepath, threadId, download: true }),
|
urlOfArtifact({
|
||||||
|
filepath,
|
||||||
|
threadId,
|
||||||
|
download: true,
|
||||||
|
isMock,
|
||||||
|
}),
|
||||||
"_blank",
|
"_blank",
|
||||||
"noopener,noreferrer",
|
"noopener,noreferrer",
|
||||||
);
|
);
|
||||||
@ -249,9 +254,7 @@ export function ArtifactFileDetail({
|
|||||||
(language === "markdown" || language === "html") && (
|
(language === "markdown" || language === "html") && (
|
||||||
<ArtifactFilePreview
|
<ArtifactFilePreview
|
||||||
content={displayContent}
|
content={displayContent}
|
||||||
isWriteFile={isWriteFile}
|
|
||||||
language={language ?? "text"}
|
language={language ?? "text"}
|
||||||
url={url}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{isCodeFile && viewMode === "code" && (
|
{isCodeFile && viewMode === "code" && (
|
||||||
@ -274,15 +277,28 @@ export function ArtifactFileDetail({
|
|||||||
|
|
||||||
export function ArtifactFilePreview({
|
export function ArtifactFilePreview({
|
||||||
content,
|
content,
|
||||||
isWriteFile,
|
|
||||||
language,
|
language,
|
||||||
url,
|
|
||||||
}: {
|
}: {
|
||||||
content: string;
|
content: string;
|
||||||
isWriteFile: boolean;
|
|
||||||
language: string;
|
language: string;
|
||||||
url?: string;
|
|
||||||
}) {
|
}) {
|
||||||
|
const [htmlPreviewUrl, setHtmlPreviewUrl] = useState<string>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (language !== "html") {
|
||||||
|
setHtmlPreviewUrl(undefined);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const blob = new Blob([content ?? ""], { type: "text/html" });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
setHtmlPreviewUrl(url);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
}, [content, language]);
|
||||||
|
|
||||||
if (language === "markdown") {
|
if (language === "markdown") {
|
||||||
return (
|
return (
|
||||||
<div className="size-full px-4">
|
<div className="size-full px-4">
|
||||||
@ -302,7 +318,7 @@ export function ArtifactFilePreview({
|
|||||||
className="size-full"
|
className="size-full"
|
||||||
title="Artifact preview"
|
title="Artifact preview"
|
||||||
sandbox="allow-scripts allow-forms"
|
sandbox="allow-scripts allow-forms"
|
||||||
{...(isWriteFile ? { srcDoc: content } : url ? { src: url } : {})}
|
src={htmlPreviewUrl}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
pr-build/issue1955-after.png
Normal file
BIN
pr-build/issue1955-after.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 MiB |
BIN
pr-build/issue1955-before.png
Normal file
BIN
pr-build/issue1955-before.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 923 KiB |
Loading…
x
Reference in New Issue
Block a user