Skip to content

Commit

Permalink
fix: don't update query-param-store if page navigation happens but pa…
Browse files Browse the repository at this point in the history
…rams are the same
  • Loading branch information
jacob-8 committed Mar 20, 2024
1 parent 27856e1 commit dbdd3b3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/stores/query-param-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ export function createQueryParamStore<T>(opts: QueryParamStoreOptions<T>) {
};

let firstUrlCheck = true;
let current_params_value: string

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

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

0 comments on commit dbdd3b3

Please sign in to comment.