Preserve URL fragment identifier / anchor when updating query params

Open
#9,664 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
web-dev

Research direction

Start by tracing the internal handling of st.query_params updates and reproduce the minimal example from the issue with a URL containing #subsection. Done means changing query parameters no longer removes the fragment identifier, so the page still jumps to the requested subsection.

Written by the indexing model from the issue text.

Description

feature:query-params type:enhancement
Checklist
  • I have searched the existing issues for similar feature requests.
  • I added a descriptive title and summary to this issue.
Summary

Currently, updating query parameters via st.query_params removes fragment identifiers, if one is present in the URL. This makes it so that links to the page intended to jump to a subsection of the page will fail to jump to the subsection if query params are modified before that subsection is generated.

Why?

I have an app with multiple sections, and I'd like to send emails out with a link to specific subsections, like myapp.com/?account_id=123#subsection. During generation of the app, before generating the subsections I'd want to link to, the query params get read and modified, which removes the #subsection fragment identifier, so the page doesn't jump to that section once it's generated.

As a minimal example, with this app:

import time
import streamlit as st

st.title("Title")

st.write("Content " * 50)

st.query_params["foo"] = "bar"

time.sleep(1)
st.subheader("Subsection")

st.write("Content " * 500)

Navigating to http://localhost:8501/#subsection does not jump to the subsection because of the query params modification. But if you comment that out, it works just fine.

How?

The change I'm suggesting would likely only be an internal change. I imagine the expected behavior of modifying query params would be preserving the fragment identifier and preserving the ability to jump to the specified id.

Additional Context

Here is a forum question from someone else whose issue would likely be resolved by this change: https://discuss.streamlit.io/t/query-params-anchors/77951/2

Dominant language
Python
Stars
45.8k
Forks
4.4k
Avg merge
21h 22m
Merged PRs (30d)
316

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from streamlit/streamlit

All issues in streamlit/streamlit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.