fix: sync query_params on browser back/forward navigation#9490
Open
kimjune01 wants to merge 3 commits into
Open
fix: sync query_params on browser back/forward navigation#9490kimjune01 wants to merge 3 commits into
kimjune01 wants to merge 3 commits into
Conversation
Fixes marimo-team#4153. When users navigate using browser back/forward buttons, query_params now updates and dependent cells re-execute. Changes: - Add UpdateQueryParamsCommand to sync URL state with kernel - Add popstate listener to detect browser navigation - Add /api/kernel/update_query_params endpoint - Update QueryParams state triggers cell re-execution via State system The fix leverages marimo's existing State system: when the browser URL changes via popstate, the frontend sends the new params to the kernel, which updates the QueryParams state object, triggering re-execution of cells that depend on query_params.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
All contributors have signed the CLA ✍️ ✅ |
for more information, see https://pre-commit.ci
Contributor
There was a problem hiding this comment.
No issues found across 11 files
Architecture diagram
sequenceDiagram
participant Browser as Browser (User)
participant FE as Frontend Runtime (useMarimoKernelConnection)
participant Router as URL Router (pushState/popstate)
participant RequestClient as Request Client (sendUpdateQueryParams)
participant API as API Server (/api/kernel/update_query_params)
participant Kernel as Kernel Runtime (control handler)
participant QueryParams as QueryParams State
participant Scheduler as Cell Scheduler
Note over Browser,Scheduler: Browser Back/Forward Navigation → Query Param Sync
Browser->>Router: browser back/forward click
Router->>Router: URL changes (popstate event)
Router->>FE: popstate event fires
FE->>FE: parseQueryParams() from window.location.href
FE->>RequestClient: sendUpdateQueryParams({ queryParams: {...} })
alt Static/Wasm (Islands or Pyodide)
RequestClient->>RequestClient: putControlRequest(type: "update-query-params")
else Server mode
RequestClient->>API: POST /api/kernel/update_query_params
API->>API: @requires("read") permission check
API->>Kernel: dispatchControlRequest(UpdateQueryParamsRequest)
end
Kernel->>Kernel: handle_update_query_params()
Kernel->>QueryParams: clear() + update(request.query_params)
QueryParams->>QueryParams: _set_value() triggers state change
QueryParams->>Scheduler: state update notification
Scheduler->>Scheduler: _run_cells(set()) re-executes dependent cells
Scheduler->>Kernel: broadcastNotification(CompletedRunNotification)
Kernel-->>API: SuccessResponse
API-->>RequestClient: 200 OK
RequestClient-->>FE: null (void)
FE-->>Browser: UI updates with new cell values
Note over Browser,Kernel: Same pattern as set_ui_element_value
Author
|
I have read the CLA Document and I hereby sign the CLA |
… wiring The new update_query_params endpoint was missing from the OpenAPI schema generation (MODELS list) and the generated TypeScript types. Also missing from the frontend mock, lazy-request proxy, and toasting wrapper—causing TypeScript build failures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4153
When users navigate with browser back/forward buttons, the URL changes but
mo.query_paramsdoesn't update, leaving cells stale. The frontend tracks URL changes viapushStatewhen cells update query params, but the reverse path (browser navigation → kernel update) was missing.Fix
Add a
popstatelistener inuseMarimoKernelConnectionthat parses the new query params and sends them to the kernel via a newupdate_query_paramsendpoint. The kernel clears and updates itsquery_paramsstate, then re-runs dependent cells.Backend wiring follows the same pattern as
set_ui_element_value—@requires("read")permission, command dispatched through the kernel's control request handler.