Skip to content

Commit d1ecb4d

Browse files
committed
fix: Snapshot state data when normalized to get rid of proxies
Svelte proxies prevent data serialization. `$state.snapshot()` is now used to ensure a proxy-free data object.
1 parent 3d1780f commit d1ecb4d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/lib/kernel/LocationState.svelte.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export class LocationState {
2222

2323
/**
2424
* Normalizes state data to ensure it conforms to the expected State interface.
25+
*
26+
* **NOTE**: In order to avoid serialization errors of the provided data, which might contain reactive Svelte
27+
* proxies, the returned data is a clean snapshot of the normalized data.
28+
*
2529
* @param state The state to normalize
2630
* @param defaultState Optional default state to use if normalization is needed
2731
* @returns Normalized state that conforms to the State interface
@@ -34,6 +38,6 @@ export class LocationState {
3438
logger.warn(`Non-conformant state data detected. ${action}`);
3539
}
3640

37-
return validState ? state : (defaultState ?? { path: undefined, hash: {} });
41+
return $state.snapshot(validState ? state : (defaultState ?? { path: undefined, hash: {} }));
3842
}
3943
}

0 commit comments

Comments
 (0)