fix(desktop): retain new-workspace image attachments across navigation

Merged
KI
3mo ago
+232-57

Problem

On the v2 new-workspace page (/new-workspace route and the empty-dashboard create screen), typed prompt text survives navigating away and back, but attached images vanish.

The text lives in the module-level useNewWorkspaceDraftStore; attachments lived in React state inside PromptInputProvider, which those surfaces mount inside the route. Navigating away unmounts the provider, dropping the file list and revoking every blob URL. The control-arm modal never had the bug only because its provider sits in the always-mounted layout.

Fix

  • packages/ui prompt-input.tsx: PromptInputProvider accepts an opt-in attachmentsStore (created via createPromptInputAttachmentsStore()). When provided, attachment state lives in that module-scoped store and blob URLs are no longer revoked on provider unmount — the store owns their lifetime. Without the prop, behavior is unchanged.
  • new-workspace-attachments.ts (new): singleton store wired into all three create surfaces (route, empty screen, modal — both experiment arms now share one draft, matching the text). A subscription on the draft store's resetKey clears attachments + revokes URLs on successful create/discard, even while no create surface is mounted.
  • NewWorkspaceScreen: the filename→source-path map backing "Reveal in Finder" was also component-local; hoisted into the same module and cleared on reset.

Attachment ids survive navigation, so the idempotent upload cache (keyed (fileId, hostUrl)) keeps its entries — no re-upload on return, and the per-host visibility filter still matches.

Testing

  • New new-workspace-attachments.test.ts (4 cases): persistence, reset clearing + URL revocation, subscriber notification. Verified the reset test fails when the reset handler is mutated.
  • Monorepo typecheck, bun run lint, and packages/ui tests pass.

Summary by cubic

Fixes lost image attachments on the v2 new-workspace screens. Attachments now persist across navigation and only clear on successful create or discard.

  • Bug Fixes

    • Store attachments in a module-scoped singleton for the new-workspace draft; all three create surfaces use it, so files survive route changes and modal toggles.
    • Clear attachments and revoke blob URLs on draft reset via a resetKey subscription; also hoist and clear the filename→source-path map for “Reveal in Finder.”
    • Preserve attachment IDs to keep the upload cache intact and avoid re-uploads.
    • Added unit tests for persistence, reset behavior, and subscriber notifications.
  • New Features

    • PromptInputProvider in @superset/ui/ai-elements/prompt-input accepts an optional attachmentsStore.
    • Added createPromptInputAttachmentsStore() to hold attachment state outside the provider; blob URLs are not revoked on provider unmount when used. Behavior is unchanged when not provided.