feat: add URL state persistence of CollectionControl#293
Conversation
|
Heads-up from the downstream side 👋 — we've been running this hook in the Denim Tears IMS app ( 1.
|
commit: |
- Remove params from write effect deps using function updater to eliminate feedback loop (setParams → params change → effect re-runs) - Fix filter value encoding: use JSON for arrays to correctly handle values containing commas (e.g. "Smith, John") - Fix hydration race condition: introduce SyncPhase lifecycle (pending → hydrated → ready) to prevent writing stale defaults to URL before hydrated state propagates - Simplify decodeFilterValue: remove startsWith check, rely on JSON.parse + Array.isArray for correctness - Replace Array.from(next.keys()) with spread syntax
decodeFilterValue only parsed JSON arrays back, so object-valued filters
(the `between` operator's { min, max } shape) round-tripped to a raw
string on reload and silently broke. Decode objects too; primitives like
"5"/"true" still fall through to strings, preserving string-vs-numeric
filter semantics.
Also harden the write-effect bail-out: compare on a sorted, JSON-encoded
snapshot (stableQueryString) rather than `.toString()`, which is
sensitive to filter key-insertion order and to `&`/`=` inside values.
Folds in fixes already running in the Denim Tears IMS copy of this hook.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
82856e6 to
c25039d
Compare
Overview
A feature to persist
CollectionControlstate (filters, sort, page size) to URL query parameters.This enables:
Cursor/pagination direction state is intentionally not persisted — a page refresh resets to page 1.