useURLSearchParams is not safe when used concurrently
See original GitHub issueDescribe 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a VueUse issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 theparams
for the whole appDividing
params
into 2 stores means you want to treat yourparams
as 2 different states, i.e. each page will have its own search params. Hence, it does not make sense to merge theparams
from pageA
to the one from pageB
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.