Skip to content

feat: add useUrlCollectionState hook#293

Open
IzumiSy wants to merge 1 commit into
mainfrom
improve-use-url-collection-state
Open

feat: add useUrlCollectionState hook#293
IzumiSy wants to merge 1 commit into
mainfrom
improve-use-url-collection-state

Conversation

@IzumiSy
Copy link
Copy Markdown
Contributor

@IzumiSy IzumiSy commented May 27, 2026

Overview

useUrlCollectionState is a hook that persists CollectionControl state (filters, sort, page size) to URL query parameters.

This enables:

  • Bookmarkable page state — Users can share or save URLs with applied filters and sort
  • Browser back/forward support — State is restored through URL history
  • Entity-agnostic design — Uses short key names and automatic encoding derived from the Filter shape, making it usable with any resource

Cursor/pagination direction state is intentionally not persisted — a page refresh resets to page 1.

- 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
@IzumiSy IzumiSy changed the title improve: simplify and harden useUrlCollectionState feat: add useUrlCollectionState hook May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant