fix(preview): stop flattenTree overflowing the stack on a huge directory - #6439
Merged
Conversation
decocms Bot
pushed a commit
that referenced
this pull request
Aug 24, 2026
PR: #6439 fix(preview): stop flattenTree overflowing the stack on a huge directory Bump type: patch - decocms (apps/api/package.json): 4.260.7 -> 4.260.8 - @decocms/native (apps/native/package.json): 4.260.7 -> 4.260.8 Deploy-Scope: web
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
flattenTree(the file-explorer's tree→row flattener,apps/web/src/components/sandbox/preview/file-explorer/utils.ts) recursed into an expanded directory's children and merged the result back withrows.push(...flattenTree(...)). Spreading an array into a call's argument list is bounded by the JS engine's max-arguments limit, well below what a legitimate sandbox directory can hold (build output, generated assets, a largenode_modules/.bin-style dump, etc.) — once a single expanded directory has enough direct children (~700k in this engine), the spread throwsRangeError: Maximum call stack size exceededand the whole file explorer crashes instead of rendering a (possibly slow but working) tree.The fix
Replaced the spread-push with a plain
for...ofloop appending one row at a time — same output, no argument-list ceiling. Net change: +8/-1 inutils.ts.Failure scenario + regression test
Expanding a directory with a very large number of direct children (build output, a huge asset dump, etc.) crashed the whole panel. Added a test in
utils.test.tsbuilding a 700,000-child directory and assertingflattenTreereturns all rows instead of throwing — this reproducibly threw theRangeErrorbefore the fix (confirmed by hand against the old spread-based implementation) and passes after it.How a reviewer confirms
bun test apps/web/src/components/sandbox/preview/file-explorer/utils.test.ts— 33 pass / 0 fail.Checks run locally
bun run fmt— cleancd apps/web && bunx tsc --noEmit— cleanbun test apps/web/src/components/sandbox/preview/file-explorer/utils.test.ts— 33 pass / 0 failbunx oxlinton both changed files — 0 warnings / 0 errorsFull CI validates the rest.
Summary by cubic
Prevents the file explorer from crashing when expanding a directory with a very large number of children. Previously
flattenTreeusedrows.push(...flattenTree(...)), which hit the engine’s max-arguments limit and threw; now it appends rows in a loop and renders the full tree.flattenTree: replace spread-push with afor...ofloop. Output is identical; no API changes.flattenTreereturns all rows without throwing.Written for commit c94cb0b. Summary will update on new commits.