From 92a38181c1dd20988ff5ea3d1caa0382a79e6ee1 Mon Sep 17 00:00:00 2001 From: Alexandru Popovici Date: Thu, 8 Feb 2024 16:23:51 +0200 Subject: [PATCH] Fix for Safari's RangeError in the object-loader (#2012) * Fix for Safari's RangeError in the object-loader * Using chunk to split the large id arrays into smaller ones. It's nicer but much slower --- packages/objectloader/src/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/objectloader/src/index.js b/packages/objectloader/src/index.js index 807fd93c65..761b0a9d85 100644 --- a/packages/objectloader/src/index.js +++ b/packages/objectloader/src/index.js @@ -8,7 +8,7 @@ import { ObjectLoaderRuntimeError } from './errors/index.js' import { polyfillReadableStreamForAsyncIterator } from './helpers/stream.js' - +import { chunk } from 'lodash' /** * Simple client that streams object info from a Speckle Server. * TODO: Object construction progress reporting is weird. @@ -364,7 +364,13 @@ export default class ObjectLoader { const newChildrenForBatch = splitBeforeCacheCheck[i].filter( (id) => !(id in cachedObjects) ) - newChildren.push(...newChildrenForBatch) + /** On Safari this would throw a RangeError for large newChildrenForBatch lengths*/ + //newChildren.push(...newChildrenForBatch) + /** The workaround for the above based off https://stackoverflow.com/a/9650855 */ + const splitN = 500 + const chunked = chunk(newChildrenForBatch, splitN) + for (let k = 0; k < chunked.length; k++) + newChildren.push.apply(newChildren, chunked[k]) } if (newChildren.length === 0) return