Skip to content

Commit a1df253

Browse files
committed
PB-1383: Avoid concurrency between app setup and URL parsing
Issue: When starting the app for the first time, the URL sync plugin would start being active before the topics were fully set, causing (mainly) the background layer parameter to be ignored and replaced with the topic's default one Fix: The `ConfigLoaded` state now wait for the background layer to be set before being fulfilled.
1 parent 38a0f0b commit a1df253

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/viewer/src/store/modules/app/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,24 @@ const initiateUrlParsing: AppState = {
5151

5252
const parseLegacyUrlParams: AppState = {
5353
name: AppStateNames.LegacyParsing,
54-
isFulfilled: () => !isLegacyParams(window?.location?.search),
54+
isFulfilled: () => {
55+
return !isLegacyParams(window?.location?.search)
56+
},
5557
next: () => {
5658
return initiateUrlParsing
5759
},
5860
}
5961

6062
const configLoaded: AppState = {
6163
name: AppStateNames.ConfigLoaded,
62-
isFulfilled: () => true, // there's always a topic set, so no need to check if topicStore.current is defined
64+
isFulfilled: () => {
65+
// When initializing the config, we could run into issues where the URL parser was active while
66+
// the app was setting the default background, writing the topic default background layer over the URL
67+
// parameter. This check ensure the topics have set what they need to before we activate the URL sync tool
68+
const topicsStore = useTopicsStore()
69+
const layerStore = useLayersStore()
70+
return topicsStore.currentTopic?.defaultBackgroundLayer?.id === layerStore.currentBackgroundLayerId
71+
},
6372
next: () => {
6473
if (isLegacyParams(window?.location?.search)) {
6574
return parseLegacyUrlParams

packages/viewer/src/store/plugins/storeSync/params/bgLayer.param.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const backgroundLayerParamConfig = new UrlParamConfig<string>({
3434
queryValue,
3535
!!queryValue &&
3636
(queryValue === 'void' ||
37-
useLayersStore().backgroundLayers?.some((layer) => layer.id == queryValue)),
37+
useLayersStore().backgroundLayers?.some((layer) => layer.id === queryValue)),
3838
'bgLayer'
3939
),
4040
})

0 commit comments

Comments
 (0)