Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/polite-eels-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"runed": patch
---

fix(useSearchParams): unsafe state mutation
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { goto } from "$app/navigation";
import { page } from "$app/state";
import { IsMounted } from "../is-mounted/is-mounted.svelte.js";
import { BROWSER } from "esm-env";
import { untrack } from "svelte";

/**
* Configuration options for useSearchParams
Expand Down Expand Up @@ -365,7 +366,7 @@ class SearchParams<Schema extends StandardSchemaV1> {
* When updateURL is false, this cache is the sole source of truth
* @private
*/
#localCache = $state(new SvelteURLSearchParams());
#localCache = $state(new URLSearchParams());

/**
* Flag to track if local cache has been initialized from URL
Expand Down Expand Up @@ -431,15 +432,15 @@ class SearchParams<Schema extends StandardSchemaV1> {

if (decompressed) {
const decompressedObj = JSON.parse(decompressed);
const newCache = new SvelteURLSearchParams();
const newCache = new URLSearchParams();

// populate cache with decompressed values
for (const [key, value] of Object.entries(decompressedObj)) {
const stringValue = this.#serializeValue(value);
newCache.set(key, stringValue);
}

this.#localCache = newCache;
untrack(() => (this.#localCache = newCache));
return;
}
} catch (e) {
Expand All @@ -452,7 +453,7 @@ class SearchParams<Schema extends StandardSchemaV1> {
for (const [key, value] of urlParams.entries()) {
newCache.set(key, value);
}
this.#localCache = newCache;
untrack(() => (this.#localCache = newCache));
}

/**
Expand Down