-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Open
Labels
feature:multipage-appsRelated to multipage app navigationRelated to multipage app navigationfeature:query-paramsRelated to `st.query_params`Related to `st.query_params`priority:P3Medium priorityMedium prioritystatus:confirmedBug has been confirmed by the Streamlit teamBug has been confirmed by the Streamlit teamtype:bugSomething isn't working as expectedSomething isn't working as expected
Description
Checklist
- I have searched the existing issues for similar issues.
- I added a very descriptive title to this issue.
- I have provided sufficient information below to help reproduce this issue.
Summary
When using st.query_params to modify the current URL, new items are added to the browser history so one can navigate forwards and backwards to the URLs that have previously been set.
- On using the forwards and backwards buttons in the browser, the URL changes as expected, but calls to
st.query_paramssee only the final version of the URL.- This only happens if
st.navigationis used - if the app is single-page, the forwards and backwards buttons don't trigger a rerun of the back end at all (as in Back button doesn't work with elements synced with query params #13853).
- This only happens if
- If the user navigates to a different page, the forwards and backwards buttons DO cause the
st.query_paramsto change.
Reproducible Code Example
import datetime
import streamlit as st
def page():
st.write(datetime.datetime.now())
if st.button("Increment Query Param"):
value = int(st.query_params.get("value", "0"))
st.query_params["value"] = value + 1
st.write(st.query_params)
st.navigation([
st.Page(page, title="Query Params", default=True),
st.Page(lambda: None, title="Other Page", url_path="other"),
]).run()Steps To Reproduce
- Open the app URL in a browser
- Press the "Increment Query Param" button twice - the URL should now end
?value=2 - Press the browser's back button
- Press the browser's forwards button
- Click on "Other Page" in the nav bar
- Press the browser's back button
- Press the browser's back button again
Expected Behavior
- The URL has no query parameters and the printed
st.query_paramsare empty - The URL ends with
?value=2and the printedst.query_paramsshows"value": "2" - The URL ends with
?value=1and the printedst.query_paramsshows"value": "1" - The URL ends with
?value=2and the printedst.query_paramsshows"value": "2" - The URL has no query parameters, no content is shown
- The URL ends with
?value=2and the printedst.query_paramsshows"value": "2" - The URL ends with
?value=1and the printedst.query_paramsshows"value": "1"
Current Behavior
After step 3: the printed st.query_params shows "value": "2" (the timestamp and URL do update, but the st.query_params appear to be cached)
Notes:
- after steps 5 and 6 (navigate to a different page and back), step 7 (apparently identical to step 3) works as expected
- replacing step 5 with "navigate to an external site" also makes step 7 work, albeit now in a new session
Is this a regression?
- Yes, this used to work in a previous version.
Debug info
- Streamlit version:
1.54.0 - Python version:
3.11.11,3.13.1 - Operating System:
Windows 11 - Browser:
Edge 145.0,Chrome 145.0,Firefox 147.0
Additional Information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feature:multipage-appsRelated to multipage app navigationRelated to multipage app navigationfeature:query-paramsRelated to `st.query_params`Related to `st.query_params`priority:P3Medium priorityMedium prioritystatus:confirmedBug has been confirmed by the Streamlit teamBug has been confirmed by the Streamlit teamtype:bugSomething isn't working as expectedSomething isn't working as expected