Skip to content

Avoid eager work in host file previews - #2092

Merged
ymichael merged 1 commit into
mainfrom
bb/post-merge-fix-hidden-host-previews-retain-dupli-thr_feh8g7agvg
Aug 20, 2026
Merged

Avoid eager work in host file previews#2092
ymichael merged 1 commit into
mainfrom
bb/post-merge-fix-hidden-host-previews-retain-dupli-thr_feh8g7agvg

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

What was wrong

PR #2005 added an absolute-host preview query that treated heavy preview work as eager and lightweight: it read the complete file and built a base64 fallback before attempting the preview lease, kept the retained panel query enabled after the panel closed, and used React Query's default five-minute payload retention. A successful media or HTML lease could therefore duplicate host I/O, while a hidden panel could start or continue a large read and keep its payload observed indefinitely. This addresses the connected findings in the eager payload review, the hidden-panel review, and the retention review.

What changed

  • Pass the primitive plugin-panel isOpen state through the existing lazy host-preview boundary and use it to gate useHostFilePreview.
  • Move a disabled retained observer off the active host/path key so closing the panel aborts the existing SDK request and starts cache GC without unmounting or changing the lazy-loading boundary.
  • Attempt the existing sdk.files.createPreview lease first. Successful image/video leases now return a lightweight URL-backed preview without reading or retaining file bytes. Text and HTML still read the source bytes they render, but no longer build a base64 fallback after a lease succeeds; lease failures build a data URL only for preview kinds that need one.
  • Apply HEAVY_PAYLOAD_QUERY_POLICY, giving inactive host-preview payloads the shared one-minute retention period.
  • Cover hidden/open/reopen gating, cancellation and GC, lease-first media and fallback behavior, HTML source preservation, and the ambiguous .ts source-preview case.

This is direct app query/component plumbing over the existing SDK APIs. It adds no server or daemon contract fields, so HOST_DAEMON_PROTOCOL_VERSION is unchanged. It also needs no CLI, guide, or public SDK documentation change.

How you verified

  • Before the implementation, pnpm exec turbo run test --filter=@bb/app -- src/hooks/queries/host-file-preview-query.test.tsx src/components/secondary-panel/ThreadSecondaryPanelTabContent.panelGate.test.tsx src/components/plugin/PluginPanelRightPanelHost.test.tsx reproduced the findings: 5 failed and 13 passed. The failures showed the hidden initial read, missing isOpen plumbing, media byte read, base64-before-lease HTML work, and read-before-failed-lease ordering.
  • After rebasing onto origin/main at 7f3d2ac66, the same focused command passed 3 files / 20 tests.
  • pnpm exec turbo run test --filter=@bb/app --force passed 412 files / 3,162 tests, with 3 skipped.
  • pnpm exec turbo run typecheck build --filter=@bb/app passed.
  • pnpm exec turbo run lint --filter=@bb/app passed with 0 errors and 156 existing warnings outside the changed lines.

Post-merge follow-up to #2005; no matching issue.

AGENT GENERATED: by GPT-5.6-Sol

@ymichael
ymichael force-pushed the bb/post-merge-fix-hidden-host-previews-retain-dupli-thr_feh8g7agvg branch from 4af983f to d6e673d Compare August 20, 2026 23:04
@ymichael
ymichael merged commit 3f4fdcc into main Aug 20, 2026
13 checks passed
@ymichael
ymichael deleted the bb/post-merge-fix-hidden-host-previews-retain-dupli-thr_feh8g7agvg branch August 20, 2026 23:11
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