Skip to content

Back button changes URL query params but not st.query_params until user leaves page and comes back #13963

@PhilipCavanagh

Description

@PhilipCavanagh

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_params see only the final version of the URL.
  • If the user navigates to a different page, the forwards and backwards buttons DO cause the st.query_params to 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

  1. Open the app URL in a browser
  2. Press the "Increment Query Param" button twice - the URL should now end ?value=2
  3. Press the browser's back button
  4. Press the browser's forwards button
  5. Click on "Other Page" in the nav bar
  6. Press the browser's back button
  7. Press the browser's back button again

Expected Behavior

  1. The URL has no query parameters and the printed st.query_params are empty
  2. The URL ends with ?value=2 and the printed st.query_params shows "value": "2"
  3. The URL ends with ?value=1 and the printed st.query_params shows "value": "1"
  4. The URL ends with ?value=2 and the printed st.query_params shows "value": "2"
  5. The URL has no query parameters, no content is shown
  6. The URL ends with ?value=2 and the printed st.query_params shows "value": "2"
  7. The URL ends with ?value=1 and the printed st.query_params shows "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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:multipage-appsRelated to multipage app navigationfeature:query-paramsRelated to `st.query_params`priority:P3Medium prioritystatus:confirmedBug has been confirmed by the Streamlit teamtype:bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions