Skip to content

Commit

Permalink
Fix for Safari's RangeError in the object-loader (#2012)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AlexandruPopovici authored Feb 8, 2024
1 parent 001992a commit 92a3818
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/objectloader/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 92a3818

Please sign in to comment.