From 4f8bba2f802dd99888d83909abbc336cd7127f80 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 15 May 2024 14:08:53 +0100 Subject: [PATCH] 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 <5968653+dummdidumm@users.noreply.github.com> --- .../svelte/src/internal/client/dev/equality.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/svelte/src/internal/client/dev/equality.js b/packages/svelte/src/internal/client/dev/equality.js index bd03a84ac6..61fa77a12e 100644 --- a/packages/svelte/src/internal/client/dev/equality.js +++ b/packages/svelte/src/internal/client/dev/equality.js @@ -3,6 +3,14 @@ import { get_proxied_value } from '../proxy.js'; export function init_array_prototype_warnings() { const array_prototype = Array.prototype; + // The REPL ends up here over and over, and this prevents it from adding more and more patches + // of the same kind to the prototype, which would slow down everything over time. + // @ts-expect-error + const cleanup = Array.__svelte_cleanup; + if (cleanup) { + cleanup(); + } + const { indexOf, lastIndexOf, includes } = array_prototype; array_prototype.indexOf = function (item, from_index) { @@ -55,6 +63,13 @@ export function init_array_prototype_warnings() { return has; }; + + // @ts-expect-error + Array.__svelte_cleanup = () => { + array_prototype.indexOf = indexOf; + array_prototype.lastIndexOf = lastIndexOf; + array_prototype.includes = includes; + }; } /**