Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hiding default value with arrays and objects #72

Open
brennerm opened this issue Mar 1, 2024 · 1 comment
Open

hiding default value with arrays and objects #72

brennerm opened this issue Mar 1, 2024 · 1 comment

Comments

@brennerm
Copy link

brennerm commented Mar 1, 2024

Describe the bug

Not sure if this is a bug, but let me explain.

When I create a new query param store with an empty array as the default value and showDefaults set to false, everything is fine on the first load. The query param is not added to the URL.

Adding an element to the array and the URL updates accordingly.

But now when I remove the object again or assign [] to the store, the query param is added to the URL with an empty array value.

@paoloricciuti Would love to hear you opinion on what the expected behavior should be. IMO the query param should disappear again after it has been reset to its default value.

Already have an idea that the issue comes from comparison by reference instead of comparison by value, but want to wait for your feedback first, before jumping into any code.

Cheers!

Reproduction

// creating the store, no query param in the URL
const params = queryParam('params', ssp.array([]), { showDefaults: false });

// adding element to store array, URL updates to ?params=["foo"]
$params = ['foo']

// resetting store to empty array, URL updates to ?params=[]
$params = []

Logs

No response

@paoloricciuti
Copy link
Owner

Oh yeah I'm pretty sure is for reference equality...I will check as soon as I can, thanks for reporting

herronelou added a commit to herronelou/sveltekit-search-params that referenced this issue Sep 20, 2024
…faults is False and the values are equivalent to the default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants