fix(frontend): enable HTML preview for generated artifacts using srcDoc (#1001)

* fix(frontend): enable HTML preview for generated artifacts using srcDoc

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Ashwek-Werghi
2026-03-09 08:34:44 +01:00
committed by GitHub
parent ac1e1915ef
commit 4f0a8da2ee

View File

@@ -81,8 +81,8 @@ export function ArtifactFileDetail({
return checkCodeFile(filepath); return checkCodeFile(filepath);
}, [filepath, isWriteFile, isSkillFile]); }, [filepath, isWriteFile, isSkillFile]);
const isSupportPreview = useMemo(() => { const isSupportPreview = useMemo(() => {
return (language === "html" && !isWriteFile) || language === "markdown"; return language === "html" || language === "markdown";
}, [isWriteFile, language]); }, [language]);
const { content } = useArtifactContent({ const { content } = useArtifactContent({
threadId, threadId,
filepath: filepathFromProps, filepath: filepathFromProps,
@@ -239,8 +239,6 @@ export function ArtifactFileDetail({
viewMode === "preview" && viewMode === "preview" &&
(language === "markdown" || language === "html") && ( (language === "markdown" || language === "html") && (
<ArtifactFilePreview <ArtifactFilePreview
filepath={filepath}
threadId={threadId}
content={displayContent} content={displayContent}
language={language ?? "text"} language={language ?? "text"}
/> />
@@ -264,17 +262,12 @@ export function ArtifactFileDetail({
} }
export function ArtifactFilePreview({ export function ArtifactFilePreview({
filepath,
threadId,
content, content,
language, language,
}: { }: {
filepath: string;
threadId: string;
content: string; content: string;
language: string; language: string;
}) { }) {
const { isMock } = useThread();
if (language === "markdown") { if (language === "markdown") {
return ( return (
<div className="size-full px-4"> <div className="size-full px-4">
@@ -292,7 +285,9 @@ export function ArtifactFilePreview({
return ( return (
<iframe <iframe
className="size-full" className="size-full"
src={urlOfArtifact({ filepath, threadId, isMock })} title="Artifact preview"
srcDoc={content}
sandbox="allow-scripts allow-forms"
/> />
); );
} }