fix: polish uncached computed var delta deduplication (#7253)

SH
8h ago
+208-33

Fixes #7253

Summary

Addresses the three follow-up polish items for uncached computed var (@rx.var(cache=False)) delta deduplication:

  1. 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_substates and respecting _record_delta_values).
    • Invoked it in State.hydrate and State.hydrate_and_load so the immediate on_load_internal / next event delta does not redundantly re-send unchanged uncached vars.
  2. Sort dict keys when computing delta value digests (packages/reflex-base/src/reflex_base/vars/base.py):
    • Passed sort_keys=True to json_dumps(value, sort_keys=True) in _delta_value_key so dicts with identical key-value pairs in different insertion orders deduplicate cleanly.
  3. Fix dead _UNKEYABLE_VALUE branch (packages/reflex-base/src/reflex_base/vars/base.py):
    • Since None is already handled by _ATOMIC_DELTA_VALUE_TYPES, any non-None value that serializes to "null" (e.g. complex, object(), or custom classes without a registered serializer) now returns _UNKEYABLE_VALUE instead of deduplicating distinct unserializable values against each other.

Testing

  • Added 3 unit tests in tests/units/test_state.py:
    • test_uncached_computed_var_unserializable_type_always_sent
    • test_uncached_computed_var_dict_key_order_deduped
    • test_uncached_computed_var_recorded_on_hydrate
  • Verified pytest tests/units/test_state.py (346 passed, 0 failed) and ruff check / ruff format --check.

Note: This PR was developed with AI assistance and locally verified against the test suite and linter.