From 428fdfcc0a00cb297460bb1cdda6f8cad5b309db Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 5 Mar 2024 12:10:50 +0000 Subject: [PATCH] Handle errors when stringifying component context in case there somehow is a cyclical reference which is unserialisable --- packages/client/src/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/client/src/index.js b/packages/client/src/index.js index 5886128396..1ce7101466 100644 --- a/packages/client/src/index.js +++ b/packages/client/src/index.js @@ -87,8 +87,14 @@ const loadBudibase = async () => { } else if (type === "request-context") { const { selectedComponentInstance } = get(componentStore) const context = selectedComponentInstance?.getDataContext() + let stringifiedContext = null + try { + stringifiedContext = JSON.stringify(context) + } catch (error) { + // Ignore - invalid context + } eventStore.actions.dispatchEvent("provide-context", { - context: JSON.stringify(context), + context: stringifiedContext, }) } else if (type === "hover-component") { hoverStore.actions.hoverComponent(data)