Skip to content
Merged
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
6 changes: 5 additions & 1 deletion src/lib/kernel/LocationState.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export class LocationState {

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

return validState ? state : (defaultState ?? { path: undefined, hash: {} });
return $state.snapshot(validState ? state : (defaultState ?? { path: undefined, hash: {} }));
}
}