Skip to content

Fail the compile when an app without state imports the backend transport - #8034

Open
benedikt-bartscher wants to merge 31 commits into
reflex-dev:mainfrom
benedikt-bartscher:stateless-transport-guard
Open

benedikt-bartscher wants to merge 31 commits into
reflex-dev:mainfrom
benedikt-bartscher:stateless-transport-guard

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. Code that needs the backend (rx.get_upload_url, the connection banner's WebsocketTargetURL, dynamic components) compiles fine in an app with enable_state=False and only fails in the browser, where nothing connects.

Change. After #8033 every such name lives in utils/transport.js. compile_app now checks the import data of every page, memo and the app root, and fails when an app without state imports from $/utils/transport. The error names each module and what it imports:

These modules use the backend, which an app with state disabled (`rx.App(enable_state=False)`) does not have:
  page 'files': getBackendURL
They import these names from $/utils/transport, for example through `rx.get_upload_url`. Remove `enable_state=False` or the components and vars that use the backend.

It reads the parsed imports, not the emitted code, as #7965 and #7630 do for the rx.State reads of #7579. Memos register for the whole process, so it follows only the memos the pages and the app root import, directly or through another memo: an unused library @rx.memo, or one an app compiled earlier in the same process registered, doesn't fail the compile. The connection banner and overlay stay out of apps without state, as before.

Tests

test_compiler.py: a page and a memo using rx.get_upload_url fail to compile without state, compared against the whole error; a registered memo no page renders doesn't fail it; a page with client state, events and links compiles without state; rx.get_upload_url compiles with state. The full unit suite passes apart from failures it has on main here too (granian reload, bench collectors, site headings).

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The changes since the previous review appear safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The changes since the previous review appear safe to merge.

Summary

Stateless compilation now also rejects backend helpers imported through the re-exports in utils/state.js.

  • Stateless apps now apply browser events without a backend connection.
  • Compilation now names backend imports used by stateless app modules.

Reviews (10) · Last reviewed commit: "fix(compiler): catch transport names an ..." · Reviewed by Greptile

Comment thread tests/units/compiler/test_compiler.py Resolved
@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
@codspeed

codspeed Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 6.63%

2 warnings

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

⚠️ 3 benchmarks with a significant change ran on different hardware

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

Learn more about Macro Runners

See affected benchmarks

⚡ 3 improved benchmarks
✅ 143 untouched benchmarks
⏩ 8 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_route_matching[1000] 96.8 ms 90.1 ms +7.45%
⚡ test_route_matching[100] 10.1 ms 9.4 ms +7.24%
⚡ test_route_matching[10] 1.3 ms 1.2 ms +5.21%

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-transport-guard (c373966) with main (e35530c)

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. ↩

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

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

View guided diff | Re-trigger cubic

Comment thread reflex/compiler/compiler.py Resolved
Comment thread tests/units/compiler/test_compiler.py Resolved
Comment thread reflex/compiler/compiler.py Resolved
Comment thread reflex/compiler/compiler.py Resolved
Comment thread reflex/compiler/compiler.py Resolved
@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 38 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

enhancement Anything you want improved 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