Drop the f-string Var marker from ref names without a digest

Merged
FA
1mo ago
+14-41

Description

Follow-up to #7564.

format_ref replaced the marker of an f-string Var with sha256(js_expr + type)[:8]. To get the type, it looked up the Var in _global_vars and guarded against markers of no known Var. This PR drops the marker instead. The Var's expression already follows the marker, so the ref name stays the same in every build.

This removes _stable_var_digest, _VAR_DIGEST_LENGTH, the hashlib import, the registry lookup and the guard. The name no longer depends on str(var_type).

rx.input(id=f"pick-{item}") in a foreach now compiles to ref_pick_item_rx_state_ instead of ref_pick_642ceae8item_rx_state_.

One behavior change: the type kept two foreach blocks apart only when their callbacks use the same parameter name and their items differ in type, for example list[str] and list[int]. These blocks now share one ref. Blocks of the same type already shared a ref before, and the items of one block always share their block's ref, so a ref on a foreach item never targets one item.

Testing

  • test_format_ref_names_an_f_string_var_by_its_expression expects ref_zone_item for a str Var and an int Var. It fails on main and passes for PYTHONHASHSEED 1, 2 and 3.
  • test_format_ref_drops_a_marker_of_no_known_var still passes.
  • On the #7564 example app, two clean reflex export --frontend-only --no-zip --env prod runs give the same manifest, and diff -rq build/client finds no difference.
  • In the running app, rx.set_value and rx.set_focus work on f-string ids from the frontend and the backend, on a static id, and on an id with two Vars.

Known limit: expressions that differ only in punctuation, such as f"cell-{State.i + 1}" and f"cell-{State.i - 1}", share a ref. This does not matter: a ref name is fixed at compile time, while an id with a state Var changes at runtime, so a ref on such an id never follows its value.

Changelog

No news fragment: #7564 is not released, and its fragment ("same ref name in every build") still describes this change.

Type of change

  • Code cleanup (no user-facing change since the last release)