diff --git a/packages/ui/src/ui-component/json/JsonEditor.jsx b/packages/ui/src/ui-component/json/JsonEditor.jsx index 9da0ca4bcb6..d5a38948dd2 100644 --- a/packages/ui/src/ui-component/json/JsonEditor.jsx +++ b/packages/ui/src/ui-component/json/JsonEditor.jsx @@ -17,7 +17,15 @@ export const JsonEditorInput = ({ isDarkMode = false, isSequentialAgent = false }) => { - const [myValue, setMyValue] = useState(value ? JSON.parse(value) : {}) + const [myValue, setMyValue] = useState(() => { + if (!value || value === '') return {} + try { + return JSON.parse(value) + } catch (error) { + console.warn('Invalid JSON value provided to JsonEditorInput:', error) + return {} + } + }) const [availableNodesForVariable, setAvailableNodesForVariable] = useState([]) const [mouseUpKey, setMouseUpKey] = useState('') @@ -39,11 +47,21 @@ export const JsonEditorInput = ({ } const onClipboardCopy = (e) => { - const src = e.src - if (Array.isArray(src) || typeof src === 'object') { - navigator.clipboard.writeText(JSON.stringify(src, null, ' ')) - } else { - navigator.clipboard.writeText(src) + // Check if clipboard API is available + if (!navigator.clipboard || !navigator.clipboard.writeText) { + console.warn('Clipboard API not available') + return + } + + try { + const src = e.src + if (Array.isArray(src) || typeof src === 'object') { + navigator.clipboard.writeText(JSON.stringify(src, null, ' ')) + } else { + navigator.clipboard.writeText(src || '') + } + } catch (error) { + console.error('Error copying to clipboard:', error) } } @@ -54,6 +72,23 @@ export const JsonEditorInput = ({ } }, [disabled, inputParam, nodes, edges, nodeId]) + // Handle value changes safely + useEffect(() => { + if (value !== undefined) { + try { + if (!value || value === '') { + setMyValue({}) + } else { + const parsedValue = JSON.parse(value) + setMyValue(parsedValue) + } + } catch (error) { + console.warn('Invalid JSON value provided to JsonEditorInput:', error) + setMyValue({}) + } + } + }, [value]) + return ( <> diff --git a/packages/ui/src/views/agentexecutions/NodeExecutionDetails.jsx b/packages/ui/src/views/agentexecutions/NodeExecutionDetails.jsx index 4b750d8fa5a..ad82d86d374 100644 --- a/packages/ui/src/views/agentexecutions/NodeExecutionDetails.jsx +++ b/packages/ui/src/views/agentexecutions/NodeExecutionDetails.jsx @@ -156,11 +156,21 @@ export const NodeExecutionDetails = ({ data, label, status, metadata, isPublic, } const onClipboardCopy = (e) => { - const src = e.src - if (Array.isArray(src) || typeof src === 'object') { - navigator.clipboard.writeText(JSON.stringify(src, null, ' ')) - } else { - navigator.clipboard.writeText(src) + // Check if clipboard API is available + if (!navigator.clipboard || !navigator.clipboard.writeText) { + console.warn('Clipboard API not available') + return + } + + try { + const src = e.src + if (Array.isArray(src) || typeof src === 'object') { + navigator.clipboard.writeText(JSON.stringify(src, null, ' ')) + } else { + navigator.clipboard.writeText(src || '') + } + } catch (error) { + console.error('Error copying to clipboard:', error) } } diff --git a/packages/ui/src/views/docstore/ExpandedChunkDialog.jsx b/packages/ui/src/views/docstore/ExpandedChunkDialog.jsx index 0d7976e00a2..78245029b1a 100644 --- a/packages/ui/src/views/docstore/ExpandedChunkDialog.jsx +++ b/packages/ui/src/views/docstore/ExpandedChunkDialog.jsx @@ -26,11 +26,21 @@ const ExpandedChunkDialog = ({ show, dialogProps, onCancel, onChunkEdit, onDelet const [metadata, setMetadata] = useState({}) const onClipboardCopy = (e) => { - const src = e.src - if (Array.isArray(src) || typeof src === 'object') { - navigator.clipboard.writeText(JSON.stringify(src, null, ' ')) - } else { - navigator.clipboard.writeText(src) + // Check if clipboard API is available + if (!navigator.clipboard || !navigator.clipboard.writeText) { + console.warn('Clipboard API not available') + return + } + + try { + const src = e.src + if (Array.isArray(src) || typeof src === 'object') { + navigator.clipboard.writeText(JSON.stringify(src, null, ' ')) + } else { + navigator.clipboard.writeText(src || '') + } + } catch (error) { + console.error('Error copying to clipboard:', error) } }