Repository navigation
fix: restore view state after present-mode callbacks - #10452
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Pull request overview
This PR fixes view-mode restoration issues when running callbacks in present mode by making runDuringPresentMode fully responsible for transitioning into/out of present mode and reliably restoring the prior view state even on rejection. This removes duplicated/restoration logic from callers (notably the export dialog) and adds focused unit tests for the lifecycle behavior across modes.
Changes:
- Update
runDuringPresentModeto only transition when starting fromedit, and to always restore the capturedviewStatein afinallyblock. - Add unit tests covering success, rejection, already-present mode, and non-edit modes (
read,home,gallery). - Simplify export dialog screenshot capture by removing manual view-state restoration logic and relying on
runDuringPresentMode.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| frontend/src/core/mode.ts | Makes runDuringPresentMode own the present-mode lifecycle with reliable state restoration. |
| frontend/src/core/tests/mode.test.ts | Adds vitest coverage for present-mode lifecycle behavior across success/error and different modes. |
| frontend/src/components/editor/actions/export-dialog/use-export-dialog.ts | Removes redundant view-state capture/restore logic and delegates lifecycle to runDuringPresentMode. |
Bundle ReportChanges will increase total bundle size by 43.84kB (0.17%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: marimo-esmAssets Changed:
Files in
Files in
|
There was a problem hiding this comment.
No issues found across 3 files
Architecture diagram
sequenceDiagram
participant Export as Export Dialog
participant Mode as runDuringPresentMode()
participant State as Jotai Store (viewStateAtom)
participant Render as Page Render
Note over Export,Render: NEW: Unified lifecycle ownership in runDuringPresentMode
Export->>Mode: capturePNG() → runDuringPresentMode(capture)
Mode->>State: get viewStateAtom
State-->>Mode: { mode, cellAnchor }
alt mode === "edit"
Mode->>State: set({ ...state, mode: "present" })
Mode->>Render: setTimeout(100ms)
Render-->>Mode: render complete
Mode->>Render: requestAnimationFrame (frame 1)
Mode->>Render: requestAnimationFrame (frame 2)
Render-->>Mode: two frames rendered
Mode->>Export: run callback fn()
Export->>Export: capture current app view
Export-->>Mode: callback complete (resolve or reject)
alt callback rejects
Mode->>Mode: catch error
Mode->>State: finally: set(original state)
Mode-->>Export: re-throw error
else callback resolves
Mode->>State: finally: set(original state)
Mode-->>Export: void
end
else mode === "present"
Mode->>Export: run callback fn() directly
Export->>Export: capture current app view
Export-->>Mode: callback complete
Mode-->>Export: void
else mode in ["read", "home", "gallery"]
Mode->>Export: run callback fn() directly
Export->>Export: capture current app view
Export-->>Mode: callback complete
Mode-->>Export: void
end
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.17-dev13 |
`runDuringPresentMode` could leave the app in `present` when its callback rejected. Calls from `read`, `home`, or `gallery` could also restore the app to `edit`, so the export dialog (marimo-team#10429) maintained its own restoration logic. This change makes `runDuringPresentMode` own the full lifecycle. It transitions from `edit` to `present`, restores the captured view state in `finally`, and runs callbacks directly in every other mode. Focused tests cover success, rejection, present mode, and non-edit modes.
runDuringPresentModecould leave the app inpresentwhen its callback rejected. Calls fromread,home, orgallerycould also restore the app toedit, so the export dialog (#10429) maintained its own restoration logic.This change makes
runDuringPresentModeown the full lifecycle. It transitions fromedittopresent, restores the captured view state infinally, and runs callbacks directly in every other mode. Focused tests cover success, rejection, present mode, and non-edit modes.