Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions frontend/src/components/WorkspaceOperationPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const DEFAULT_TREE_WIDTH = 240;
const DEFAULT_HISTORY_WIDTH = 320;
const MIN_SIDE_WIDTH = 220;
const MAX_SIDE_WIDTH = 520;
const HTML_DRAFT_PREVIEW_LIMIT = 20000;

function extOf(path: string): string {
const idx = path.lastIndexOf('.');
Expand Down Expand Up @@ -257,6 +258,18 @@ function buildRevisionDiff(revision: any): string {
return chunks.join('\n');
}

function HtmlDraftPreview({ content }: { content: string }) {
const shownContent = content.length > HTML_DRAFT_PREVIEW_LIMIT
? `${content.slice(0, HTML_DRAFT_PREVIEW_LIMIT)}\n\n... truncated while drafting ...`
: content;

return (
<div className="workspace-op-html-draft">
<pre>{shownContent}</pre>
</div>
);
}

function HtmlPreviewFrame({
content,
title,
Expand All @@ -276,7 +289,12 @@ function HtmlPreviewFrame({

const fitFixedWidthContent = () => {
const frame = frameRef.current;
const doc = frame?.contentDocument;
let doc: Document | null | undefined;
try {
doc = frame?.contentDocument;
} catch {
return;
}
const root = doc?.documentElement;
const body = doc?.body;
if (!frame || !doc || !root || !body) return;
Expand Down Expand Up @@ -304,7 +322,12 @@ function HtmlPreviewFrame({

const bindFrameFitObservers = () => {
const frame = frameRef.current;
const doc = frame?.contentDocument;
let doc: Document | null | undefined;
try {
doc = frame?.contentDocument;
} catch {
return;
}
if (!frame || !doc?.documentElement || !doc.body) return;

observersRef.current?.frame?.disconnect();
Expand Down Expand Up @@ -371,7 +394,7 @@ function HtmlPreviewFrame({
<div className="workspace-op-html-fit" ref={containerRef}>
<iframe
ref={frameRef}
sandbox="allow-same-origin allow-scripts allow-forms allow-modals allow-popups allow-downloads allow-pointer-lock allow-top-navigation-by-user-activation"
sandbox="allow-forms allow-modals allow-popups allow-downloads allow-pointer-lock"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore script execution for saved HTML previews

The new iframe sandbox removes allow-scripts, which means JavaScript is always blocked in non-draft HTML previews. Any saved HTML file that relies on client-side scripts (e.g., chart libraries, interactive docs, JS-rendered content) will now appear blank or partially rendered, so this is a functional regression of the existing preview path rather than just a security hardening change.

Useful? React with 👍 / 👎.

src={src}
srcDoc={src ? undefined : renderContent}
title={title}
Expand Down Expand Up @@ -927,7 +950,7 @@ export default function WorkspaceOperationPanel({
<div className="workspace-op-live">
<div className="workspace-op-live-banner">{liveDraft.status === 'drafting' ? 'Drafting HTML...' : 'Writing HTML...'}</div>
{draftContent ? (
<HtmlPreviewFrame content={draftContent} title={fileName(liveDraft.path || 'draft.html')} suspendAutoFit={isSideResizing} />
<HtmlDraftPreview content={draftContent} />
) : (
<div className="workspace-op-empty">Preparing file content...</div>
)}
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -6151,6 +6151,26 @@ select:focus {
border-radius: 8px;
}

.workspace-op-html-draft {
flex: 1;
min-height: 0;
overflow: auto;
border: 1px solid var(--border-subtle);
border-radius: 8px;
background: var(--bg-secondary);
}

.workspace-op-html-draft pre {
margin: 0;
padding: 12px;
color: var(--text-secondary);
font-family: var(--font-mono);
font-size: 12px;
line-height: 1.55;
white-space: pre-wrap;
word-break: break-word;
}

.workspace-op-image-preview {
display: flex;
align-items: center;
Expand Down
28 changes: 10 additions & 18 deletions frontend/src/pages/AgentDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4237,8 +4237,7 @@ function AgentDetailInner() {
const pendingHistoryInitialScrollRef = useRef(false);
const liveAutoFollowUntilRef = useRef(0);
const userPinnedAwayFromBottomRef = useRef(false);
const liveScrollJobRef = useRef(0);
const liveScrollTimersRef = useRef<number[]>([]);
const liveScrollRafRef = useRef<number | null>(null);
const chatTouchStartYRef = useRef<number | null>(null);
const [showScrollBtn, setShowScrollBtn] = useState(false);
const [chatScrollBtnBottom, setChatScrollBtnBottom] = useState(96);
Expand All @@ -4263,9 +4262,10 @@ function AgentDetailInner() {
}, [activeTab]);
const cancelLiveAutoFollow = useCallback(() => {
liveAutoFollowUntilRef.current = 0;
liveScrollJobRef.current += 1;
liveScrollTimersRef.current.forEach((timer) => window.clearTimeout(timer));
liveScrollTimersRef.current = [];
if (liveScrollRafRef.current != null) {
cancelAnimationFrame(liveScrollRafRef.current);
liveScrollRafRef.current = null;
}
}, []);
const pinChatAwayFromBottom = useCallback(() => {
cancelLiveAutoFollow();
Expand All @@ -4275,24 +4275,16 @@ function AgentDetailInner() {
}, [cancelLiveAutoFollow]);
const scheduleLiveScrollToBottom = useCallback(() => {
if (userPinnedAwayFromBottomRef.current) return;
cancelLiveAutoFollow();
const jobId = liveScrollJobRef.current;
liveAutoFollowUntilRef.current = Date.now() + 1500;
let attempts = 0;
const scroll = () => {
if (jobId !== liveScrollJobRef.current) return;
if (liveScrollRafRef.current != null) return;
liveScrollRafRef.current = requestAnimationFrame(() => {
liveScrollRafRef.current = null;
if (userPinnedAwayFromBottomRef.current) return;
const el = chatContainerRef.current;
if (el) el.scrollTop = el.scrollHeight;
setShowScrollBtn(false);
if (attempts++ < 2) requestAnimationFrame(scroll);
};
requestAnimationFrame(scroll);
liveScrollTimersRef.current = [
window.setTimeout(scroll, 80),
window.setTimeout(scroll, 220),
];
}, [cancelLiveAutoFollow]);
});
}, []);
useEffect(() => {
return () => cancelLiveAutoFollow();
}, [cancelLiveAutoFollow]);
Expand Down