Skip to content

Commit 4f8bba2

Browse files
trueadmdummdidumm
andauthored
fix: cleanup array prototype monkeypatching (#11634)
* fix: cleanup array prototype monkeypatching * Update packages/svelte/src/internal/client/dev/equality.js --------- Co-authored-by: Simon H <[email protected]>
1 parent e5e7ec2 commit 4f8bba2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/svelte/src/internal/client/dev/equality.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { get_proxied_value } from '../proxy.js';
33

44
export function init_array_prototype_warnings() {
55
const array_prototype = Array.prototype;
6+
// The REPL ends up here over and over, and this prevents it from adding more and more patches
7+
// of the same kind to the prototype, which would slow down everything over time.
8+
// @ts-expect-error
9+
const cleanup = Array.__svelte_cleanup;
10+
if (cleanup) {
11+
cleanup();
12+
}
13+
614
const { indexOf, lastIndexOf, includes } = array_prototype;
715

816
array_prototype.indexOf = function (item, from_index) {
@@ -55,6 +63,13 @@ export function init_array_prototype_warnings() {
5563

5664
return has;
5765
};
66+
67+
// @ts-expect-error
68+
Array.__svelte_cleanup = () => {
69+
array_prototype.indexOf = indexOf;
70+
array_prototype.lastIndexOf = lastIndexOf;
71+
array_prototype.includes = includes;
72+
};
5873
}
5974

6075
/**

0 commit comments

Comments
 (0)