Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions AppBuilder/platform/ABModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Loading