Skip to content

Commit 7c822d8

Browse files
committed
make sure there is a hydrate event before we assume
if the app is stateless, then presumably we don't end up connecting a websocket at all, so we wouldn't hit this code. also if `initialEvents` was empty for whatever reason, then the app probably wouldn't work... but lets make it look a bit safer.
1 parent ef19541 commit 7c822d8

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

reflex/.templates/web/utils/state.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -618,16 +618,19 @@ export const connect = async (
618618
window.addEventListener("unload", disconnectTrigger);
619619
if (socket.current.rehydrate) {
620620
socket.current.rehydrate = false;
621-
// On reconnect, we only hydrate, do not re-run on_load events.
622-
const hydrate_event = initialEvents()[0];
623-
hydrate_event.payload.is_reconnect = true;
624-
queueEvents(
625-
[hydrate_event],
626-
socket,
627-
true,
628-
navigate,
629-
() => params.current,
630-
);
621+
const events = initialEvents();
622+
if (events.length > 0) {
623+
// On reconnect, we only hydrate, do not re-run on_load events.
624+
const hydrate_event = initialEvents()[0];
625+
hydrate_event.payload.is_reconnect = true;
626+
queueEvents(
627+
[hydrate_event],
628+
socket,
629+
true,
630+
navigate,
631+
() => params.current,
632+
);
633+
}
631634
}
632635
// Drain any initial events from the queue.
633636
while (event_queue.length > 0 && !event_processing) {

0 commit comments

Comments
 (0)