Skip to content

fix: serialize elements iteratively so deep nesting does not overflow the stack - #326

Open
zzoraemon043 wants to merge 1 commit into
taoqf:mainfrom
zzoraemon043:fix/iterative-serialize
Open

zzoraemon043 wants to merge 1 commit into
taoqf:mainfrom
zzoraemon043:fix/iterative-serialize

Conversation

@zzoraemon043

Copy link
Copy Markdown

Fixes #324

HTMLElement.toString() and innerHTML called each other recursively, so serializing a tree nested a few thousand levels deep threw RangeError: Maximum call stack size exceeded, while parse() handled it fine. Both now go through one iterative serializer with an explicit stack. The output is the same: void tags still go through voidTag.formatNode (so addClosingSlash and custom void tags keep working), other elements get <tag attrs>…</tag>, and text and comment nodes use their own toString().

Added test/tests/issues/324.js (depth 10000 round trip for toString, outerHTML and innerHTML, plus a mixed void tag / comment / attribute case). With npm run test:src the new tests pass; the two Module Import failures are the same with and without this change (they need the built package).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

outerHTML/toString() crashes with 'Maximum call stack size exceeded' on deeply nested documents

1 participant