Skip the window.__reflex libraries in apps without state
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 nowindow.__reflexand no namespace import, with and withoutfrontend_lazy_bundled_libraries; with state both stay.test_compiler.py:compile_appwriteswindow.__reflexonly 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.