Skip to content

NoSessionRerun and Fragment reruns#239

Draft
smelis wants to merge 1 commit intowhitphx:mainfrom
smelis:session-rerun-suppression
Draft

NoSessionRerun and Fragment reruns#239
smelis wants to merge 1 commit intowhitphx:mainfrom
smelis:session-rerun-suppression

Conversation

@smelis
Copy link

@smelis smelis commented Feb 10, 2025

Adds NoSessionRerun, so you can do:

with no_session_rerun:
    server_state['foo'] = bar

This will cause all sessions bound to 'foo' to be rerun except the session setting the value.
The idea is that the session that sets the value already knows the value and does not require a rerun.
This is also helpful to prevent circular updates.

Adds fragment reruns, so you can have specific fragments rerun when a certain key in the server_state is mutated.
Like:

@st.fragment
def messages_fragment():
    server_state.register_current_fragment_rerun(for_updates_to='messages')
    with lock...:
        st.write(server_state['messages'])
...

server_state['messages'] = server_state['messages'] + [message]

When the 'messages' array is updated it does not do a complete app rerun, but instead only reruns a specific fragment (in all sessions).

with no_session_rerun:
    server_state['foo'] = bar
so that all sessions EXCEPT the one setting the value are rerun. The idea is that the session that sets the value already knows the value and does not require a rerun.
- adds fragment reruns, so you can have specific fragments rerun when a certain key in the server_state is mutated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments