diff --git a/packages/frontend-2/lib/viewer/composables/setup.ts b/packages/frontend-2/lib/viewer/composables/setup.ts index 529bebf485..a4abd0e5b0 100644 --- a/packages/frontend-2/lib/viewer/composables/setup.ts +++ b/packages/frontend-2/lib/viewer/composables/setup.ts @@ -116,6 +116,10 @@ export type InjectableViewerState = Readonly<{ views: ComputedRef filteringState: ComputedRef> } + /** + * Whether the Viewer has finished doing the initial object loading + */ + hasDoneInitialLoad: Ref } /** * Loaded/loadable resources @@ -395,6 +399,7 @@ function setupInitialState(params: UseSetupViewerParams): InitialSetupState { createViewerDataBuilder({ viewerDebug }) ) || { initPromise: Promise.resolve() } initPromise.then(() => (isInitialized.value = true)) + const hasDoneInitialLoad = ref(false) return { projectId, @@ -412,7 +417,8 @@ function setupInitialState(params: UseSetupViewerParams): InitialSetupState { availableFilters: computed(() => undefined), views: computed(() => []), filteringState: computed(() => undefined) - } + }, + hasDoneInitialLoad } as unknown as InitialSetupState['viewer']) : { instance, @@ -421,7 +427,8 @@ function setupInitialState(params: UseSetupViewerParams): InitialSetupState { promise: initPromise, ref: computed(() => isInitialized.value) }, - metadata: setupViewerMetadata({ viewer: instance }) + metadata: setupViewerMetadata({ viewer: instance }), + hasDoneInitialLoad }, urlHashState: setupUrlHashState() } diff --git a/packages/frontend-2/lib/viewer/composables/setup/postSetup.ts b/packages/frontend-2/lib/viewer/composables/setup/postSetup.ts index 2d17599840..bd319d1249 100644 --- a/packages/frontend-2/lib/viewer/composables/setup/postSetup.ts +++ b/packages/frontend-2/lib/viewer/composables/setup/postSetup.ts @@ -82,7 +82,8 @@ function useViewerObjectAutoLoading() { projectId, viewer: { instance: viewer, - init: { ref: isInitialized } + init: { ref: isInitialized }, + hasDoneInitialLoad }, resources: { response: { resourceItems } @@ -112,21 +113,24 @@ function useViewerObjectAutoLoading() { uniq(resourceItems.map((i) => i.objectId)) watch( - () => [resourceItems.value, isInitialized.value], - async ([newResources, newIsInitialized], oldData) => { + () => [resourceItems.value, isInitialized.value, hasDoneInitialLoad.value], + async ([newResources, newIsInitialized, newHasDoneInitialLoad], oldData) => { // Wait till viewer loaded in if (!newIsInitialized) return - const [oldResources, oldIsInitialized] = oldData || [[], false] + const [oldResources] = oldData || [[], false] const zoomToObject = !focusedThreadId.value // we want to zoom to the thread instead // Viewer initialized - load in all resources - if (newIsInitialized && !oldIsInitialized) { + if (!newHasDoneInitialLoad) { const allObjectIds = getUniqueObjectIds(newResources) - await Promise.all( + const res = await Promise.all( allObjectIds.map((i) => loadObject(i, false, { zoomToObject })) ) + if (res.length) { + hasDoneInitialLoad.value = true + } return } @@ -139,7 +143,7 @@ function useViewerObjectAutoLoading() { await Promise.all(removableObjectIds.map((i) => loadObject(i, true))) await Promise.all( - addableObjectIds.map((i) => loadObject(i, false, { zoomToObject })) + addableObjectIds.map((i) => loadObject(i, false, { zoomToObject: false })) ) }, { deep: true, immediate: true }