use-query-params icon indicating copy to clipboard operation
use-query-params copied to clipboard

fix: notify WindowHistoryAdapter when the page's URL is updated

Open am1rb opened this issue 10 months ago • 1 comments

Fixes the issue rained here: https://github.com/pbeshai/use-query-params/discussions/283

WindowHistoryAdapter is broken because when a component updates a query param in the URL, the lib does not notify the query params consumer to read the new value. As a result, the URL is changed, but the internal react state holds the stale value.

Also, the adapter needs to consider URL changes when someone clicks on the browser's Back and Forward buttons.

PS: My solution was also broken, and finally I ended up with the same idea as @websaid shared in https://github.com/pbeshai/use-query-params/discussions/283#discussioncomment-8171698

This is a PR to add his solution to the repo.

am1rb avatar Dec 30 '24 12:12 am1rb

LGTM. We have this in production for a year now and it is working well.

websaid avatar Dec 30 '24 15:12 websaid

Seems the main thing is just forcing a re-render here by calling setState on adapter, right? will merge since it seems this solution works for window users, i've never actually used the adapter

pbeshai avatar Nov 22 '25 00:11 pbeshai