Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMax Stack Size Exceeded for huge HTML #4694
Comments
the compiling process involves push spreading all nodes into another array at some point and the v8 engine does not support spreading that many items |
Interesting. I've run into this before in V8 and ended up using an array spread and a reassignment, rather than an argument spread in I'm not sure how many places we're doing |
Same issue when using Tailwind UI. In a regular svelte + tailwindcss project if I add in the Could we update the issue name as well to include tailwindUI word? @siebeneicher |
same here im building a large single page app / single file app, with many many html nodes error is
with
chunks.push(
c(') '),
...handle(node.body, state)
); .... as expected, using push instead of reassign compiles to const chunks = [c('for (')];
//
chunks.push(
c(') '),
...handle(node.body, state)
); todo: push ----> reassign like let chunks = [c('for (')];
//
chunks = [
...chunks,
c(') '),
...handle(node.body, state)
]; |
my svelte compiler is fixed
here is a quick-and-dirty patch script /*
node_modules/svelte/patch-compiler.js
replace push with reassign
cd node_modules/svelte
mv compiler.js compiler.js.orig
ln -s compiler.js.new compiler.js
node patch-compiler.js
*/
const acorn_parse = require("acorn").parse;
const estree_walk = require("estree-walker").walk;
const node_tosource = require("tosource");
const magicString = require("magic-string");
const fs = require("fs");
const input_file = "compiler.js.orig";
const output_file = "compiler.js.new";
// input
const content = fs.readFileSync(input_file, 'utf8');
// output
let code = new magicString(content);
const ast = acorn_parse(
content, {
// ecmaVersion: 10, // default in year 2019
sourceType: 'module',
});
const funcName = "push";
let arrayNameList = [];
function setCharAt(str, index, chr) {
if (index > str.length-1) return str;
return str.substr(0,index) + chr + str.substr(index+1);
}
estree_walk( ast, {
enter: function ( node, parent, prop, index ) {
// filter for array.push()
if (
node.type !== 'CallExpression' ||
node.callee === undefined ||
node.callee.property === undefined ||
node.callee.property.name !== funcName
) {
return;
}
// filter for spread operator
if (node.arguments.find(a => {
return (a.type == 'SpreadElement');
}) === undefined) {
return;
}
const nodeSrc = content.substring(
node.start, node.end);
const arrayName = content.substring(
node.callee.object.start,
node.callee.object.end);
arrayNameList.push(arrayName);
// patch .push(
let nodePatch = nodeSrc.replace(
".push(", " /* PATCHED */ = [..."+arrayName+", ");
// patch closing bracket
nodePatch = setCharAt(nodePatch, nodePatch.lastIndexOf(")"), "]");
code.overwrite(node.start, node.end, nodePatch);
}});
code = code.toString();
function filterUnique(value, index, array) {
return array.indexOf(value) === index;
}
// replace const with let
arrayNameList.filter(filterUnique).forEach(arrayName => {
console.log(`arrayName = ${arrayName}`)
code = code.replace(
new RegExp("const "+arrayName+" = ", 'g'), // global = replace all
"/* PATCHED const "+arrayName+" */ let "+arrayName+" = "
);
})
fs.writeFileSync(output_file, code); edit: included patch by rhythm-section |
@milahu Thank you for the compiler patch. It works great. With version
Because of the tertiary operator the Not sure if it is a good solution or if it leads to other issues with other svelte versions, but the following worked for me. I changed the regex from:
to:
Hope this helps someone still having troubles. |
Describe the bug
The content of the the svelte file is a large HTML chunk, withouy any script logics or styling being involved. Max stack size exceeded error while compiling.
To Reproduce
https://svelte.dev/repl/a9dfcc17551c4aeb95e8fe748a97061d?version=3.20.1
Expected behavior
Compiling should not break
Information about your Svelte project:
Svelte 3.20.1, Rollup, Windows
Severity
Its probably an uncommon case for most people. I ran into it, when using a generated data privacy HTML template. I would not see this as a priority. Workaround for me: copy the HTML into a JS template literal variable and inject it via @html: https://svelte.dev/repl/1ab32c5a3c2c426e973512cfc8da023c?version=3.20.1