How to save widget value to URL without triggering re-run?

I’ve created some wrapper classes that implement stuff we want around all our input widgets. That includes getting defaults from URL parameters using st.query_param so that we can share links with default values, setting up the dashboard in the same way for the recipient of the link (i.e. deep linking).

I also want to add the new value to the URL parameters so that the new state is captured ready for sharing a link. However, doing this with st.query_params causes problems where some widgets like st.multiselect now require two clicks to select anything. I think it’s because setting a URL parameter triggers a kind of rerun.

How do I add a widget value to the query parameters in the ULR without interfering with the way the widgets work from a user’s point of view?