question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useURLSearchParams is not safe when used concurrently

See original GitHub issue

Describe the bug

Two different parameters kick each other out.

const useA = defineStore({
  state: {
    params: useURLSearchParams()
  },
  actions: {
    test() {
      this.params.a = 'test';
    }
  }
})
const useB = defineStore({
  state: {
    params: useURLSearchParams()
  },
  actions: {
    test() {
      this.params.b = 'test';
    }
  }
})
useA().test();
useB().test();

Param b kicks out param a from URL!

Expected:

?a=test&b=test

i.e. the same behavior as URLSearchParams.set.

Got:

?b=test

Reproduction

https://github.com/mskr/useUrlSearchParamsTest

System Info

"@vueuse/core": "^8.5.0",
"pinia": "^2.0.12",
"vue": "^3.2.31"

Used Package Manager

npm

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
huynl-96commented, Aug 2, 2022

It looks like you want to control the params throughout all the pages for the entire app. For that case, you should only use 1 store to manage the params for the whole app

Dividing params into 2 stores means you want to treat your params as 2 different states, i.e. each page will have its own search params. Hence, it does not make sense to merge the params from page A to the one from page B

0reactions
stale[bot]commented, Oct 4, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SCRIPT5009: 'URLSearchParams' is undefined in IE 11
I was able to solve this by using url-search-params-polyfill. Just import into the file you're using URLSearchParams in:
Read more >
URLSearchParams | Can I use... Support tables for ... - CanIUse
The URLSearchParams interface defines utility methods to work with the query string of a URL. Usage % of. all users, all tracked, tracked...
Read more >
Dealing with URL query parameters in Javascript using ...
Interacting with the browsers URL search parameters was never easier with URLSearchParams. No need for external libraries.
Read more >
Targeting CSS Shadow Parts via URL search params
Allow for removing parts of the UI when embedding in an iframe. In order to achieve this, I mixed together some interesting solutions....
Read more >
How to POST *Data* with the Fetch API - Chip Cullen
To do that, the trick was using URLSearchParams, which is built into JavaScript, much like Math() or Date() . What it does is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found