Fail the compile when an app without state imports the backend transport
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).