From dcfb49585d71e0c02cf2aa8ef38b0b689a1eafec Mon Sep 17 00:00:00 2001 From: nmemmert <67961292+nmemmert@users.noreply.github.com> Date: Wed, 29 Jul 2026 17:23:03 -0400 Subject: [PATCH] Fix docx import crash on large files by chunking base64 encoding btoa(String.fromCharCode(...new Uint8Array(buf))) exceeds V8's function argument stack limit for files larger than ~65k bytes. Process in 8k chunks instead to handle any file size. Co-Authored-By: Claude Sonnet 4.6 --- public/admin.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/public/admin.js b/public/admin.js index 5c581dc..51f8bf5 100644 --- a/public/admin.js +++ b/public/admin.js @@ -611,7 +611,12 @@ $('#import-go-btn').addEventListener('click', async () => { $('#import-status').textContent = '🔍 Extracting content… this may take a minute.'; try { const arrayBuffer = await file.arrayBuffer(); - const base64 = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer))); + const bytes = new Uint8Array(arrayBuffer); + let binary = ''; + for (let i = 0; i < bytes.length; i += 8192) { + binary += String.fromCharCode(...bytes.subarray(i, Math.min(i + 8192, bytes.length))); + } + const base64 = btoa(binary); const result = await api('/api/admin/import-docx', { method: 'POST', body: { base64, mode } }); if (!$('#ie-title').value && result.title) $('#ie-title').value = result.title; if (mode === 'quiz' && result.questions) {