From aa4604305ebbdf51788316863bf691714ef8e3f8 Mon Sep 17 00:00:00 2001 From: "pong.promrat" Date: Wed, 18 Feb 2026 16:17:15 +0700 Subject: [PATCH] *Fix circular reference error in CSV packing measurement --- AppBuilder/platform/ABModel.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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)