Drop the f-string Var marker from ref names without a digest
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_expressionexpectsref_zone_itemfor astrVar and anintVar. It fails onmainand passes forPYTHONHASHSEED1, 2 and 3.test_format_ref_drops_a_marker_of_no_known_varstill passes.- On the #7564 example app, two clean
reflex export --frontend-only --no-zip --env prodruns give the same manifest, anddiff -rq build/clientfinds no difference. - In the running app,
rx.set_valueandrx.set_focuswork 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)