Skip to content

Fix stale on_load during websocket connection - #7522

Merged
masenf merged 9 commits into
reflex-dev:mainfrom
harsh21234i:fix/7487-stale-on-load
Oct 27, 2026
Merged

masenf merged 9 commits into
reflex-dev:mainfrom
harsh21234i:fix/7487-stale-on-load

Conversation

@harsh21234i

@harsh21234i harsh21234i commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7487. The websocket’s initial hydration event now uses the route current when the connection begins, preventing navigation during connection setup from running the previous page’s on_load handler or triggering its redirect.

Coalesces queued internal on_load events when the hydration event already covers the current route. Adds unit and dev/production browser regression tests.

View guided diff

@harsh21234i
harsh21234i requested a review from a team as a code owner October 8, 2026 19:19

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread tests/units/compiler/state_js.test.mjs Outdated
@greptile-apps

greptile-apps Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

The PR builds the first websocket hydration event from the route current when the connection begins.

  • Websocket hydration loads the route current when the namespace connects.

Reviews (8) · Last reviewed commit: "fix: keep the last queued on_load after ..." · Reviewed by Greptile

Comment thread tests/units/compiler/state_js.test.mjs Outdated
…7487-stale-on-load

# Conflicts:
#	packages/reflex-base/src/reflex_base/.templates/web/utils/state.js
@codspeed

codspeed Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 19 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 148 untouched benchmarks


Comparing harsh21234i:fix/7487-stale-on-load (4c61fa3) with main (9c64f1e)

Open in CodSpeed

# Conflicts:
#	packages/reflex-base/src/reflex_base/.templates/web/utils/state.js
#	tests/units/compiler/state_js.test.mjs
@masenf masenf added the bug Something isn't working label Oct 22, 2026 — with ChatGPT Codex Connector
@FarhanAliRaza FarhanAliRaza added the on deck PRs lined up to review / merge next label Oct 22, 2026
Comment thread packages/reflex-base/src/reflex_base/.templates/web/utils/state.js Outdated
Comment thread packages/reflex-base/src/reflex_base/.templates/web/utils/state.js Outdated
Comment thread packages/reflex-base/src/reflex_base/.templates/web/utils/state.js Outdated
Comment thread tests/integration/tests_playwright/test_navigation_before_connect.py Outdated
harsh21234i and others added 3 commits October 23, 2026 12:46
Every queued on_load_internal loads the route current when it is sent, so
keeping all of them ran the new page's on_load once per navigation made
during the websocket handshake. Keep only the first one, in its queue
position, when the route changed after the auth event was built.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread packages/reflex-base/src/reflex_base/.templates/web/utils/state.js Outdated
Each navigation queues the browser storage it read, then its on_load.
Keeping the first queued on_load ran the page's handlers before a later
navigation's storage update. Keep the last one instead, so the handlers
see the newest storage values.
@masenf
masenf merged commit e9933a4 into reflex-dev:main Oct 27, 2026
169 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working on deck PRs lined up to review / merge next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Navigating before the websocket connects runs the previous page's on_load first (and a redirect from it hijacks the new page)

3 participants