Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Nov 22, 2025

Describe your changes

Adds support for passing query parameters to st.page_link:

st.page_link(..., query_params={"foo": "bar", "baz": ["1", "2"]})

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.

Copilot AI review requested due to automatic review settings November 22, 2025 23:47
@lukasmasuch lukasmasuch requested a review from a team as a code owner November 22, 2025 23:47
@snyk-io
Copy link
Contributor

snyk-io bot commented Nov 22, 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 22, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-13093/streamlit-1.51.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-13093.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 22, 2025
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.page_link, enabling developers to navigate to pages with pre-set query parameters for both internal multipage apps and external URLs.

Key Changes

  • Added query_string field to the PageLink protobuf message
  • Implemented process_query_params() helper function to convert query param dicts/iterables into URL-encoded strings
  • Updated frontend to append query params to external link hrefs and pass them through onPageChange for internal navigation

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
proto/streamlit/proto/PageLink.proto Added query_string field to PageLink message for storing URL-encoded query parameters
lib/streamlit/runtime/state/query_params.py Added process_query_params() and _set_item_in_dict() helper functions to process and validate query params
lib/streamlit/elements/widgets/button.py Added query_params parameter to page_link() and _page_link() methods with processing logic
lib/tests/streamlit/runtime/state/query_params_test.py Added comprehensive unit tests for process_query_params() covering dicts, iterables, list values, type conversions, and validation
lib/tests/streamlit/elements/page_link_test.py Added test for query_params parameter with external URL
frontend/lib/src/components/elements/PageLink/PageLink.tsx Updated to append query string to external link hrefs and pass to onPageChange for internal navigation
frontend/lib/src/components/core/NavigationContext.tsx Updated onPageChange signature to accept optional queryString parameter
frontend/app/src/App.tsx Updated onPageChange and sendRerunBackMsg to handle query string overrides with proper embed param preservation
e2e_playwright/multipage_apps_v2/mpa_v2_basics.py Added test page link with query params
e2e_playwright/multipage_apps_v2/mpa_v2_basics_test.py Added E2E test verifying query params are properly set when navigating via page link

@lukasmasuch lukasmasuch marked this pull request as draft November 24, 2025 15:48
@lukasmasuch lukasmasuch changed the title Support passing query params to st.page_link [WIP] Support passing query params to st.page_link Nov 24, 2025
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

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

@lukasmasuch lukasmasuch changed the title [WIP] Support passing query params to st.page_link Support passing query params to st.page_link Nov 25, 2025
@lukasmasuch lukasmasuch marked this pull request as ready for review November 25, 2025 14:44
queryString = preservedQueryParams
this.setState({ queryParams: preservedQueryParams })

if (queryStringOverride !== undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] This could be a bit easier to read if it were separated out into a function so that the reader can get a high level idea of what it happening based on the function name.

E.g.

queryString = getQueryString(queryStringOverride, preservedQueryParams)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved into helper function 👍

}
}

let href = element.page
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] It would also be more readable here to separate this into a function.

const href = buildHref(element)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved into helper function 👍

"""Set an item in a dictionary."""
if isinstance(value, dict):
raise StreamlitAPIException(
f"You cannot set a query params key `{key}` to a dictionary."
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] This isn't new, but I find this error message phrasing odd. Should it be more like, "Query params cannot be a dictionary. Provide a string or iterable as the value for {key}"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Update the error messgae 👍

if key in processed_params:
# If the key already exists, we need to accumulate the values.
if isinstance(value, dict):
raise StreamlitAPIException(
Copy link
Collaborator

Choose a reason for hiding this comment

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

[suggestion] Maybe this should be defined as a specific error message since it is used in two places to keep the message consistent.

Copy link
Collaborator Author

@lukasmasuch lukasmasuch Nov 26, 2025

Choose a reason for hiding this comment

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

Updated the error and reused the message 👍

Copy link
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby left a comment

Choose a reason for hiding this comment

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

LGTM, left some minor comments.

@lukasmasuch lukasmasuch enabled auto-merge (squash) November 26, 2025 16:04
@lukasmasuch lukasmasuch disabled auto-merge November 26, 2025 16:11
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

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

@lukasmasuch lukasmasuch enabled auto-merge (squash) November 26, 2025 16:56
@lukasmasuch lukasmasuch merged commit 63d7f6f into develop Nov 26, 2025
43 checks passed
@lukasmasuch lukasmasuch deleted the add-query-params-to-page-link branch November 26, 2025 17:12
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.

Support query params in st.page_link

3 participants