Handle errors when stringifying component context in case there somehow is a cyclical reference which is unserialisable

This commit is contained in:
Andrew Kingston 2024-03-05 12:10:50 +00:00
parent 97375d1a33
commit 428fdfcc0a
1 changed files with 7 additions and 1 deletions

View File

@ -87,8 +87,14 @@ const loadBudibase = async () => {
} else if (type === "request-context") { } else if (type === "request-context") {
const { selectedComponentInstance } = get(componentStore) const { selectedComponentInstance } = get(componentStore)
const context = selectedComponentInstance?.getDataContext() const context = selectedComponentInstance?.getDataContext()
let stringifiedContext = null
try {
stringifiedContext = JSON.stringify(context)
} catch (error) {
// Ignore - invalid context
}
eventStore.actions.dispatchEvent("provide-context", { eventStore.actions.dispatchEvent("provide-context", {
context: JSON.stringify(context), context: stringifiedContext,
}) })
} else if (type === "hover-component") { } else if (type === "hover-component") {
hoverStore.actions.hoverComponent(data) hoverStore.actions.hoverComponent(data)