Skip to content
10 changes: 8 additions & 2 deletions src/plots/cartesian/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,15 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
selection = [];
for(i = 0; i < searchTraces.length; i++) {
searchInfo = searchTraces[i];
[].push.apply(selection, fillSelectionItem(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a reported bug AFAIK, but this use of push.apply overloads the stack for large plots. Doesn't look to me as though any of the other places we use push.apply are susceptible to this issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone interested in writing a syntax test to 🔒 this down?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do use push.apply in a few other places - but they get max a few items in the array so it's not a problem - so if we wanted to 🔒 it, we'd have to also remove those other uses.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcjohnson funny enough I stumbled upon this stack overflow in selection for regl. I replaced it with .concat here https://github.com/plotly/plotly.js/pull/1869/files#diff-8c5d8f688f2bb41a18d35397e5f58864R211, since it is being called only as many times as there is traces per subplot, which is small. (related tweet)

var thisSelection = fillSelectionItem(
searchInfo.selectPoints(searchInfo, poly), searchInfo
));
);
if(selection.length) {
for(var j = 0; j < thisSelection.length; j++) {
selection.push(thisSelection[j]);
}
}
else selection = thisSelection;
}

eventData = {points: selection};
Expand Down