Skip to content

Skip the window.__reflex libraries in apps without state - #8035

Open
benedikt-bartscher wants to merge 23 commits into
reflex-dev:mainfrom
benedikt-bartscher:stateless-no-window-reflex
Open

benedikt-bartscher wants to merge 23 commits into
reflex-dev:mainfrom
benedikt-bartscher:stateless-no-window-reflex

Conversation

@benedikt-bartscher

@benedikt-bartscher benedikt-bartscher commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Type of change

  • New feature (non-breaking change which adds functionality)

Description

Depends on #8033: its commits are part of this diff until it merges.

Problem. The app root imports the namespaces of the bundled libraries ($/utils/state, $/utils/context, ...) and puts them on window.__reflex, where dynamic components look them up. A namespace import keeps every export, so an app with enable_state=False ships the backend transport and socket.io, although dynamic components only ever come from the backend.

Change. compile_app_root takes stateful. Without state, the root imports no library namespaces and sets neither window.__reflex nor window.__reflex_load.

Measured with #8033, on a two-page stateless app with client state (reflex export, JS loaded by the first view):

/ raw / gzip /b raw /b gzip
main 548.7 KB 157.0 KB 485.9 KB 156.4 KB
#8033 + this PR 482.7 KB 135.9 KB 419.9 KB 135.3 KB

The shared chunk with state.js and socket.io (93.4 KB, 30.9 KB gzip) is gone.

Tests

  • test_dynamic_components_codegen.py: an app root without state has no window.__reflex and no namespace import, with and without frontend_lazy_bundled_libraries; with state both stay.
  • test_compiler.py: compile_app writes window.__reflex only for an app with state.
  • Playwright test_stateless_app.py, prod: no script a stateless page loads contains the transport or engine.io-client. It fails without this change.

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no new actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

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

Summary

Apps compiled with enable_state=False skip the library imports that populate window.__reflex, allowing production builds to leave out the backend connection code and socket.io.

  • Stateless apps run browser-side events without a backend connection.
  • Stateless app roots skip bundled libraries and their unused transport code.

Reviews (8) · Last reviewed commit: "Merge branch 'stateless-runtime' into st..." · Reviewed by Greptile

@codspeed

codspeed Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 6.88%

2 warnings

⚠️ 14 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

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 1 improved benchmark
✅ 145 untouched benchmarks
⏩ 8 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_state_access[read_cached_computed] 48.2 ms 45.1 ms +6.88%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing benedikt-bartscher:stateless-no-window-reflex (5c0c113) with main (8ef3f5f)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@benedikt-bartscher
benedikt-bartscher marked this pull request as ready for review November 26, 2026 22:37
@benedikt-bartscher
benedikt-bartscher requested a review from a team as a code owner November 26, 2026 22:37

@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 36 files

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

View guided diff | Re-trigger cubic

@FarhanAliRaza FarhanAliRaza added the priority: P2 Medium: valid edge-case bug, reasonable feature, or docs fix label Nov 30, 2026 — with Claude
@benedikt-bartscher

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review

@benedikt-bartscher I have started the AI code review. It will take a few minutes to complete.

@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 39 files

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

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf Performance-improving changes priority: P2 Medium: valid edge-case bug, reasonable feature, or docs fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants