Merge pull request #13394 from Budibase/fix/screen-load-actions
Fix race condition when running screen load actions
This commit is contained in:
commit
718b43db5c
1 changed files with 9 additions and 9 deletions
|
@ -5,29 +5,29 @@
|
||||||
import Provider from "./context/Provider.svelte"
|
import Provider from "./context/Provider.svelte"
|
||||||
import { onMount, getContext } from "svelte"
|
import { onMount, getContext } from "svelte"
|
||||||
import { enrichButtonActions } from "../utils/buttonActions.js"
|
import { enrichButtonActions } from "../utils/buttonActions.js"
|
||||||
|
import { memo } from "@budibase/frontend-core"
|
||||||
|
|
||||||
export let params = {}
|
export let params = {}
|
||||||
|
|
||||||
const context = getContext("context")
|
const context = getContext("context")
|
||||||
|
const onLoadActions = memo()
|
||||||
|
|
||||||
// Get the screen definition for the current route
|
// Get the screen definition for the current route
|
||||||
$: screenDefinition = $screenStore.activeScreen?.props
|
$: screenDefinition = $screenStore.activeScreen?.props
|
||||||
|
$: onLoadActions.set($screenStore.activeScreen?.onLoad)
|
||||||
$: runOnLoadActions(params)
|
$: runOnLoadActions($onLoadActions, params)
|
||||||
|
|
||||||
// Enrich and execute any on load actions.
|
// Enrich and execute any on load actions.
|
||||||
// We manually construct the full context here as this component is the
|
// We manually construct the full context here as this component is the
|
||||||
// one that provides the url context, so it is not available in $context yet
|
// one that provides the url context, so it is not available in $context yet
|
||||||
const runOnLoadActions = params => {
|
const runOnLoadActions = (actions, params) => {
|
||||||
const screenState = get(screenStore)
|
if (actions?.length && !get(builderStore).inBuilder) {
|
||||||
|
const enrichedActions = enrichButtonActions(actions, {
|
||||||
if (screenState.activeScreen?.onLoad && !get(builderStore).inBuilder) {
|
|
||||||
const actions = enrichButtonActions(screenState.activeScreen.onLoad, {
|
|
||||||
...get(context),
|
...get(context),
|
||||||
url: params,
|
url: params,
|
||||||
})
|
})
|
||||||
if (actions != null) {
|
if (enrichedActions != null) {
|
||||||
actions()
|
enrichedActions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue