From 88c51a7f4a1803c12570bf325fdfc8ec9578e3f5 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Sat, 10 Aug 2024 19:57:35 -0700 Subject: [PATCH] fix: push one value at a time to avoid stack overflows (#43) --- src/turbo-stream.spec.ts | 2 +- src/unflatten.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/turbo-stream.spec.ts b/src/turbo-stream.spec.ts index ef4a55a..319fdba 100644 --- a/src/turbo-stream.spec.ts +++ b/src/turbo-stream.spec.ts @@ -164,7 +164,7 @@ test("should encode and decode object", async () => { test("should encode and decode large payload", async () => { const input: unknown[] = []; - for (let i = 0; i < 10000; i++) { + for (let i = 0; i < 100000; i++) { input.push({ [Math.random().toString(36).slice(2)]: Math.random() .toString(36) diff --git a/src/unflatten.ts b/src/unflatten.ts index b221e1a..3f10fa6 100644 --- a/src/unflatten.ts +++ b/src/unflatten.ts @@ -36,7 +36,9 @@ export function unflatten(this: ThisDecode, parsed: unknown): unknown { if (!Array.isArray(parsed) || !parsed.length) throw new SyntaxError(); const startIndex = values.length; - values.push(...parsed); + for (const value of parsed) { + values.push(value); + } hydrated.length = values.length; return hydrate.call(this, startIndex);