Skip to content

Commit dbdd3b3

Browse files
committed
fix: don't update query-param-store if page navigation happens but params are the same
1 parent 27856e1 commit dbdd3b3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/lib/stores/query-param-store.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,16 @@ export function createQueryParamStore<T>(opts: QueryParamStoreOptions<T>) {
8484
};
8585

8686
let firstUrlCheck = true;
87+
let current_params_value: string
8788

8889
const start = () => {
8990
const unsubscribe_from_page_store = page.subscribe(({ url: { searchParams } }) => {
9091
let value = searchParams.get(key);
92+
if (current_params_value && value === current_params_value) {
93+
if (log) console.info('query params are same value, skipping set')
94+
return // don't emit store change if page navigation happened with same query params
95+
}
96+
current_params_value = value
9197

9298
// Set store value from url - skipped on first load
9399
if (!firstUrlCheck) return setStoreValue(value);

0 commit comments

Comments
 (0)