fix(components): add download action to HTML preview surface (#321) - #342
Conversation
|
Hi @hasak21, I still can not see the dialog with download, could you check and attach a screenshot? |
|
Hi @Leeeon233, Thanks for reviewing! Here are the screenshots and a breakdown clarifying the behavior before and after this change: 1. Before (
|
|
I think a more accurate fix would be to preserve the existing behavior—clicking an HTML attachment opens the HTML preview first and add a download action to the preview surface or attachment card. |
e175f77 to
10279a3
Compare
|
Hi @Leeeon233, Thank you for the guidance! That makes total sense. I have updated the PR accordingly:
All CI checks, typecheck, and |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 10279a377f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const handleDownloadHtml = useCallback(() => { | ||
| if (data.status !== 'ready' || data.snapshot.kind !== 'text') return; | ||
| const content = latestEditorTextRef.current ?? data.snapshot.text; | ||
| downloadBytesAsFile(normalizedPath, new TextEncoder().encode(content)); |
There was a problem hiding this comment.
Gate HTML downloads through the shared action model
For a same-machine Electron HTML file with a resolvable host path, this unconditional handler bypasses sessionFileActions.download even though that action is intentionally null; it therefore exposes the forbidden download alternative and, when a local viewer read has truncated: true, saves the partial preview bytes as though they were the complete file. Invoke and gate the toolbar control through sessionFileActions.download so local files retain open/reveal actions and remote downloads retain the centralized size/error handling.
AGENTS.md reference: packages/components/src/components/sessions/AGENTS.md:L865-L887
Useful? React with 👍 / 👎.
10279a3 to
dc88d9f
Compare
|
Hi @Leeeon233, Following up with the visual verification and screenshots for this update: 1. Rendered Preview ModeWhen opening the HTML live preview, the top toolbar now features a dedicated Download action ( (Note: I also consolidated the reload and provider refresh buttons in rendered mode—suppressing the redundant duplicate refresh icon and wiring the reload action to reload the sandbox iframe while pulling fresh disk content if a provider is present.) 2. Source Code ModeThe same download action is also accessible in the toolbar when inspecting or editing the HTML source code: All 34 unit tests, typecheck, and formatting checks are passing cleanly. |




Related issue
Closes #321
Problem / pressure
Clicking an HTML file attachment uploaded via
lody_upload_fileswith a workspacesourcePathopens the rendered HTML preview directly in the file viewer (SessionFileContentView). However, the HTML preview surface lacked a download action in its toolbar, leaving users unable to save the artifact HTML file bytes to their local machine.Summary
SessionFileContentView).Downloadicon button) to the toolbar inSessionFileContentViewwhen viewing HTML files (isHtmlFile && isTextFileReady), allowing users to download the file directly in both rendered preview and source code mode.showRefreshButtonwhileshowHtmlRenderedis active (!showHtmlRendered), and wire the rendered modeReloadbutton to reload the sandbox iframe while also triggeringhandleProviderRefreshif a provider is present, avoiding duplicate refresh icons in the toolbar.packages/components/tests/session-file-content-view.test.tsxverifying the toolbar download action and the unified reload action.Before / after
Test plan
pnpm --filter @lody/components test tests/session-file-content-view.test.tsx tests/session-html-attachment-action.test.ts(all 34 tests passed).pnpm --filter @lody/components typecheck(0 errors).Context handoff
Instructions for reviewing agents
handleDownloadHtmland the toolbar Download button inpackages/components/src/components/sessions/session-file-content-view.tsx.Authoring context
SessionFileCardbutton semantics or break existing preview routing.SessionFileContentViewtop bar for HTML files.resolveSessionHtmlAttachmentActionrouting.downloadBytesAsFileinvocation with expected payload.