Skip the window.__reflex libraries in apps without state

BE
14h ago
+3989-2841

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
main548.7 KB157.0 KB485.9 KB156.4 KB
#8033 + this PR482.7 KB135.9 KB419.9 KB135.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.