fix: polish uncached computed var delta deduplication (#7253)
SH
8h ago+208+208+012345678901234567890123456789-33-33-01234567890123456789
Fixes #7253
Summary
Addresses the three follow-up polish items for uncached computed var (@rx.var(cache=False)) delta deduplication:
- Record uncached var delta keys on hydrate (
reflex/istate/delta.py,reflex/state.py):- Added
record_delta_values(state, delta)to record uncached computed var keys from delivered full-state snapshot deltas (walking only_always_dirty_substatesand respecting_record_delta_values). - Invoked it in
State.hydrateandState.hydrate_and_loadso the immediateon_load_internal/ next event delta does not redundantly re-send unchanged uncached vars.
- Added
- Sort dict keys when computing delta value digests (
packages/reflex-base/src/reflex_base/vars/base.py):- Passed
sort_keys=Truetojson_dumps(value, sort_keys=True)in_delta_value_keyso dicts with identical key-value pairs in different insertion orders deduplicate cleanly.
- Passed
- Fix dead
_UNKEYABLE_VALUEbranch (packages/reflex-base/src/reflex_base/vars/base.py):- Since
Noneis already handled by_ATOMIC_DELTA_VALUE_TYPES, any non-Nonevalue that serializes to"null"(e.g.complex,object(), or custom classes without a registered serializer) now returns_UNKEYABLE_VALUEinstead of deduplicating distinct unserializable values against each other.
- Since
Testing
- Added 3 unit tests in
tests/units/test_state.py:test_uncached_computed_var_unserializable_type_always_senttest_uncached_computed_var_dict_key_order_dedupedtest_uncached_computed_var_recorded_on_hydrate
- Verified
pytest tests/units/test_state.py(346 passed, 0 failed) andruff check/ruff format --check.
Note: This PR was developed with AI assistance and locally verified against the test suite and linter.