Skip to content

Commit 07e03ef

Browse files
committed
Reassociate sid and token when connecting websocket
If there are active background tasks for a given client_token, reassociate the token and sid in the state when reconnecting so that updates from the background task go to to the new websocket.
1 parent f226bb8 commit 07e03ef

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

reflex/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,3 +2189,10 @@ async def link_token_to_sid(self, sid: str, token: str):
21892189
if new_token:
21902190
# Duplicate detected, emit new token to client
21912191
await self.emit("new_token", new_token, to=sid)
2192+
2193+
# Update client state to apply new sid/token for running background tasks.
2194+
async with self.app.modify_state(
2195+
_substate_key(new_token or token, self.app.state_manager.state)
2196+
) as state:
2197+
state.router_data[constants.RouteVar.SESSION_ID] = sid
2198+
state.router = RouterData.from_router_data(state.router_data)

0 commit comments

Comments
 (0)