diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/ButtonActionDrawer.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/ButtonActionDrawer.svelte index 1d18fa3a92..b2daf0a2d7 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/ButtonActionDrawer.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/ButtonActionDrawer.svelte @@ -74,8 +74,18 @@ } const deleteAction = index => { + // Check if we're deleting the selected action + const selectedIndex = actions.indexOf(selectedAction) + const isSelected = index === selectedIndex + + // Delete the action actions.splice(index, 1) actions = actions + + // Select a new action if we deleted the selected one + if (isSelected) { + selectedAction = actions?.length ? actions[0] : null + } } const toggleActionList = () => { diff --git a/packages/client/src/components/Component.svelte b/packages/client/src/components/Component.svelte index aa03b3ce8a..f109449f38 100644 --- a/packages/client/src/components/Component.svelte +++ b/packages/client/src/components/Component.svelte @@ -171,6 +171,15 @@ $: pad = pad || (interactive && hasChildren && inDndPath) $: $dndIsDragging, (pad = false) + // Determine whether we should render a skeleton loader for this component + $: showSkeleton = + $loading && + definition.name !== "Screenslot" && + children.length === 0 && + !instance._blockElementHasChildren && + !definition.block && + definition.skeleton !== false + // Update component context $: store.set({ id, @@ -473,14 +482,6 @@ componentStore.actions.unregisterInstance(id) } }) - - $: showSkeleton = - $loading && - definition.name !== "Screenslot" && - children.length === 0 && - !instance._blockElementHasChildren && - !definition.block && - definition.skeleton !== false {#if showSkeleton} diff --git a/packages/client/src/components/app/DataProvider.svelte b/packages/client/src/components/app/DataProvider.svelte index c28cdef24c..1b4504e689 100644 --- a/packages/client/src/components/app/DataProvider.svelte +++ b/packages/client/src/components/app/DataProvider.svelte @@ -11,20 +11,23 @@ export let limit export let paginate - const loading = writable(false) - const { styleable, Provider, ActionTypes, API } = getContext("sdk") const component = getContext("component") + // Update loading state + const parentLoading = getContext("loading") + const loading = writable(true) + setContext("loading", loading) + // We need to manage our lucene query manually as we want to allow components // to extend it let queryExtensions = {} $: defaultQuery = LuceneUtils.buildLuceneQuery(filter) $: query = extendQuery(defaultQuery, queryExtensions) - // Keep our data fetch instance up to date - $: fetch = createFetch(dataSource) - $: fetch.update({ + // Fetch data and refresh when needed + $: fetch = createFetch(dataSource, $parentLoading) + $: updateFetch({ query, sortColumn, sortOrder, @@ -32,6 +35,9 @@ paginate, }) + // Keep loading context updated + $: loading.set($parentLoading || !$fetch.loaded) + // Build our action context $: actions = [ { @@ -80,14 +86,21 @@ sortColumn: $fetch.sortColumn, sortOrder: $fetch.sortOrder, }, - limit: limit, + limit, } - const parentLoading = getContext("loading") - setContext("loading", loading) - $: loading.set($parentLoading || !$fetch.loaded) + const createFetch = (datasource, parentLoading) => { + // Return a dummy fetch if parent is still loading. We do this so that we + // can still properly subscribe to a valid fetch object and check all + // properties, but we want to avoid fetching the real data until all parents + // have finished loading. + // This logic is only needed due to skeleton loaders, as previously we + // simply blocked component rendering until data was ready. + if (parentLoading) { + return fetchData({ API }) + } - const createFetch = datasource => { + // Otherwise return the real thing return fetchData({ API, datasource, @@ -101,6 +114,14 @@ }) } + const updateFetch = opts => { + // Only update fetch if parents have stopped loading. Otherwise we will + // trigger a fetch of the real data before parents are ready. + if (!$parentLoading) { + fetch.update(opts) + } + } + const addQueryExtension = (key, extension) => { if (!key || !extension) { return diff --git a/packages/client/src/components/app/forms/Form.svelte b/packages/client/src/components/app/forms/Form.svelte index 977b940d1f..f155474d9f 100644 --- a/packages/client/src/components/app/forms/Form.svelte +++ b/packages/client/src/components/app/forms/Form.svelte @@ -1,7 +1,8 @@