diff --git a/AppBuilder/platform/ABModel.js b/AppBuilder/platform/ABModel.js index f70cf741..8b8e7149 100644 --- a/AppBuilder/platform/ABModel.js +++ b/AppBuilder/platform/ABModel.js @@ -102,6 +102,20 @@ module.exports = class ABModel extends ABModelCore { let lengthPacked = JSON.stringify(data).length; data = this.csvUnpack(data); + // Fix TypeError: Converting circular structure to JSON + const getCircularReplacer = () => { + const seen = new WeakSet(); + return (key, value) => { + if (typeof value === "object" && value !== null) { + if (seen.has(value)) { + return; + } + seen.add(value); + } + return value; + }; + }; + // JOHNNY: getting "RangeError: Invalid string length" // when data.data is too large. So we are just going // to .stringify() the rows individually and count the @@ -110,10 +124,16 @@ module.exports = class ABModel extends ABModelCore { let lengthUnpacked = 0; if (Array.isArray(data.data)) { for (var d = 0; d < data.data.length; d++) { - lengthUnpacked += JSON.stringify(data.data[d]).length; + lengthUnpacked += JSON.stringify( + data.data[d], + getCircularReplacer() + ).length; } } else { - lengthUnpacked += JSON.stringify(data.data).length; + lengthUnpacked += JSON.stringify( + data.data, + getCircularReplacer() + ).length; } Object.keys(data)