Make the production frontend build reproducible

Merged
H4
1mo ago
+84-3

Description

Fixes #7562.

  • state.js no longer imports reflex.json. It reads the Reflex version from env.json, which set_env_json() writes from values that only change with the config (REFLEX_VERSION is added next to TRANSPORT and TEST_MODE). reflex.json itself is unchanged: the CLI still keeps the project hash and the last run time there.
  • format_ref replaces the Var marker (<reflex.Var>{hash}</reflex.Var>) with a short digest of the Var's expression and type as text. An f-string id around a Var then gets the same ref name in every run, and Vars that differ only by type keep separate refs. It is still one ref per component, as before.

The backend's subprotocol check (HTTP_SEC_WEBSOCKET_PROTOCOL against constants.Reflex.VERSION in EventNamespace.on_connect) gets the same value as before.

Testing

  • New unit tests: test_set_env_json_holds_the_reflex_version and test_format_ref_names_an_f_string_var_by_its_expression_and_type.
  • tests/units pass.
  • On an app with f-string Var ids, two clean reflex export --frontend-only --no-zip --env prod runs in separate web folders:
    • on main: different manifests (manifest-0ee1b19e.js, manifest-ba20c90e.js), and every page's HTML differs;
    • with this change: the same manifest in both runs, and diff -rq finds no difference in build/client.

Type of change

  • Bug fix (non-breaking change which fixes an issue)