diff --git a/packages/editor-sdk/src/components/Form/ExpressionEditor/ExpressionEditor.tsx b/packages/editor-sdk/src/components/Form/ExpressionEditor/ExpressionEditor.tsx index 9d261484..14b0c5ef 100644 --- a/packages/editor-sdk/src/components/Form/ExpressionEditor/ExpressionEditor.tsx +++ b/packages/editor-sdk/src/components/Form/ExpressionEditor/ExpressionEditor.tsx @@ -36,6 +36,7 @@ import tern, { Def } from 'tern'; import { getTypeString } from '../../../utils/type'; import ecmascript from '../../../constants/ecmascript'; import { PREVENT_POPOVER_WIDGET_CLOSE_CLASS } from '../../../constants'; +import { stringify } from '../../../utils/object'; injectGlobal` .CodeMirror-hints { @@ -386,7 +387,7 @@ export const ExpressionEditor = React.forwardRef< {error ? 'Error' : getTypeString(evaledValue?.value)} - {error || JSON.stringify(evaledValue?.value, null, 2)} + {error || stringify(evaledValue?.value)} ); diff --git a/packages/editor-sdk/src/utils/object.ts b/packages/editor-sdk/src/utils/object.ts new file mode 100644 index 00000000..8afc7f32 --- /dev/null +++ b/packages/editor-sdk/src/utils/object.ts @@ -0,0 +1,17 @@ +function stringify(obj: unknown) { + const cache: unknown[] = []; + + JSON.stringify(obj, (_, value) => { + if (typeof value === 'object' && value !== null) { + // Duplicate reference found, discard key + if (cache.includes(value)) return; + + // Store value in our collection + cache.push(value); + } + + return value; + }); +} + +export { stringify };