Skip to content

feat: HTML 预览支持未保存草稿(沙箱内 srcdoc,不破坏 origin 安全) - #11

Open
Electricitysheep wants to merge 1 commit into
omdsh-dev:mainfrom
Electricitysheep:feat/html-draft-preview
Open

feat: HTML 预览支持未保存草稿(沙箱内 srcdoc,不破坏 origin 安全)#11
Electricitysheep wants to merge 1 commit into
omdsh-dev:mainfrom
Electricitysheep:feat/html-draft-preview

Conversation

@Electricitysheep

Copy link
Copy Markdown

概述

解决 README「已知限制」中的 HTML 预览渲染的是已保存文件(不反映未保存草稿),且不破坏预览的 origin 安全模型:

  • 新增零依赖纯函数 htmlPreviewTargetsrc/client/html-preview.ts):
    • dirty HTML 草稿仅在沙箱开启时通过 srcdoc 渲染——沙箱化 srcdoc frame 是 opaque origin,无法触碰 GUI origin(安全)
    • 沙箱关闭时拒绝 srcdoc,保持已保存文件的 route-src——非沙箱的 srcdoc frame 会继承 GUI origin(原有的安全注释明确此约束)
  • TextEditor 的预览 iframe 改用该决策(src vs srcDoc),并在草稿预览时显示提示条("预览中:未保存草稿(相对资源不可用…)")——srcdoc 无真实 base URL,相对资源在草稿模式下按构造不可用,已注明
  • 中英文 i18n 词条 + 样式

测试

  • 新增 tests/html-preview.spec.ts 5/5:干净 → route / dirty+沙箱 → srcdoc / dirty+沙箱关闭 → 拒绝 srcdoc(安全) / 非 HTML 忽略草稿 / draft 为 null 保持 route
  • pnpm typecheckpnpm build
  • 全量 pnpm test:413 tests,406 通过 + 7 个 Windows 平台既有失败(与本 PR 无关,macOS/CI 全绿)

破坏性变更

无(仅新增可选草稿预览行为;缺省/干净/沙箱关闭时保持原状)。

Closes the 'HTML 预览渲染的是已保存文件(不反映未保存草稿)' limitation
from the README, without breaking the preview's origin-safety model:

- html-preview.ts: dependency-free htmlPreviewTarget decision — a dirty
  HTML draft renders through srcdoc ONLY while the sandbox is enabled
  (a sandboxed srcdoc frame is opaque; it cannot touch the GUI origin).
  With the sandbox disabled, srcdoc is refused and the saved-file route
  stays, because an unsandboxed srcdoc frame would inherit the GUI origin.
- TextEditor: the preview iframe uses the decision (src vs srcDoc), with
  a 'previewing draft' hint bar; relative assets in draft mode are
  unavailable by construction (srcdoc has no real base URL).
- tests: html-preview.spec.ts 5/5 (clean/dirty/sandbox-off/non-HTML/null
  draft). Full suite: 413 tests, 7 pre-existing Windows-only failures
  unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant