Prevent unnecessary URL param updates in design page

This commit is contained in:
Andrew Kingston 2021-01-21 10:38:23 +00:00
parent b1c292b79c
commit a16ea4da09
1 changed files with 18 additions and 0 deletions

View File

@ -8,6 +8,11 @@
let initialised = false let initialised = false
// Cache previous values so we don't update the URL more than necessary
let previousType
let previousAsset
let previousComponentId
// Hydrate state from query param on mount // Hydrate state from query param on mount
onMount(() => { onMount(() => {
const assetId = decodeURI($params.asset) const assetId = decodeURI($params.asset)
@ -48,6 +53,19 @@
return return
} }
// Check we have different params than last invocation
if (
assetType === previousType &&
asset === previousAsset &&
componentId === previousComponentId
) {
return
} else {
previousType = assetType
previousAsset = asset
previousComponentId = componentId
}
// Extract current URL params // Extract current URL params
const currentParams = get(params) const currentParams = get(params)
const currentLeftover = get(leftover) const currentLeftover = get(leftover)