Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Nov 17, 2025

Describe your changes

Adds support for passing query parameters to st.switch_page

GitHub Issue Link (if applicable)

Testing Plan

  • Added unit & e2e tests.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Contributor

snyk-io bot commented Nov 17, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 17, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-13027/streamlit-1.51.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-13027.streamlit.app (☁️ Deploy here if not accessible)

@lukasmasuch lukasmasuch added security-assessment-completed Security assessment has been completed for PR change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Nov 17, 2025
@lukasmasuch lukasmasuch requested a review from Copilot November 17, 2025 20:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for passing query parameters to st.switch_page, allowing developers to programmatically navigate to pages with specific query string values. This enhances the navigation API by providing a way to pass data between pages via URL parameters.

Key Changes

  • Added optional query_params parameter to st.switch_page that accepts either a mapping or iterable of key-value pairs
  • Frontend now stores and applies query parameters from the server during page navigation
  • Query parameters are applied before the page rerun, ensuring they're available to the target page

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/streamlit/commands/execution_control.py Added query_params parameter to switch_page(), including type definitions, validation logic, and updated documentation
lib/tests/streamlit/commands/execution_control_test.py Added unit tests covering valid dict/iterable query params and invalid input rejection
frontend/app/src/App.tsx Updated state management to store and apply query parameters from server during page navigation
e2e_playwright/multipage_apps_v2/mpa_v2_basics.py Added test button and query params display for E2E testing
e2e_playwright/multipage_apps_v2/mpa_v2_basics_test.py Added E2E test to verify query params are correctly applied when switching pages

@lukasmasuch lukasmasuch marked this pull request as ready for review November 17, 2025 21:53
@lukasmasuch lukasmasuch added the flaky-verify If applied to PR will run flaky test verification workflow label Nov 17, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch added flaky-verify If applied to PR will run flaky test verification workflow and removed flaky-verify If applied to PR will run flaky test verification workflow labels Nov 17, 2025
@lukasmasuch lukasmasuch added flaky-verify If applied to PR will run flaky test verification workflow and removed flaky-verify If applied to PR will run flaky test verification workflow labels Nov 18, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch added flaky-verify If applied to PR will run flaky test verification workflow and removed flaky-verify If applied to PR will run flaky test verification workflow labels Nov 18, 2025
@lukasmasuch lukasmasuch added flaky-verify If applied to PR will run flaky test verification workflow and removed flaky-verify If applied to PR will run flaky test verification workflow labels Nov 18, 2025
@lukasmasuch lukasmasuch added flaky-verify If applied to PR will run flaky test verification workflow and removed flaky-verify If applied to PR will run flaky test verification workflow labels Nov 19, 2025
@lukasmasuch lukasmasuch added flaky-verify If applied to PR will run flaky test verification workflow and removed flaky-verify If applied to PR will run flaky test verification workflow labels Nov 19, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch added flaky-verify If applied to PR will run flaky test verification workflow and removed flaky-verify If applied to PR will run flaky test verification workflow labels Nov 19, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch removed the flaky-verify If applied to PR will run flaky test verification workflow label Nov 19, 2025
@lukasmasuch lukasmasuch enabled auto-merge (squash) November 22, 2025 13:03
Comment on lines +122 to +128
if isinstance(new_query_params, Mapping) or (
isinstance(new_query_params, Iterable)
and not isinstance(
new_query_params, # type: ignore[unreachable]
(str, bytes),
)
):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type checker marks this condition as unreachable because by the time the code checks if new_query_params is a string/bytes, it has already confirmed it's an Iterable (since strings are iterable). This could cause unexpected behavior with string inputs.

Consider restructuring the condition to check for string/bytes first:

if isinstance(new_query_params, (str, bytes)):
    raise StreamlitAPIException(f"`query_params` must be a mapping or an iterable of (key, value) pairs not a string.")
elif isinstance(new_query_params, Mapping) or isinstance(new_query_params, Iterable):
    query_params_state.from_dict(new_query_params)

This would make the logic clearer and remove the need for the # type: ignore[unreachable] comment.

Suggested change
if isinstance(new_query_params, Mapping) or (
isinstance(new_query_params, Iterable)
and not isinstance(
new_query_params, # type: ignore[unreachable]
(str, bytes),
)
):
if isinstance(new_query_params, (str, bytes)):
raise StreamlitAPIException(
f"`query_params` must be a mapping or an iterable of (key, value) pairs not a string."
)
elif isinstance(new_query_params, Mapping) or isinstance(new_query_params, Iterable):

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@lukasmasuch lukasmasuch merged commit 58dc378 into develop Nov 22, 2025
43 of 44 checks passed
@lukasmasuch lukasmasuch deleted the feature/query-params-for-switch-page branch November 22, 2025 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passing query parameters on switch_page

4 participants