Skip to content

fix(markdown): avoid import stack overflow and keep final pages reachable - #31

Open
mkroemer wants to merge 2 commits into
p10node:mainfrom
mkroemer:fix/large-markdown-import-scroll
Open

mkroemer wants to merge 2 commits into
p10node:mainfrom
mkroemer:fix/large-markdown-import-scroll

Conversation

@mkroemer

Copy link
Copy Markdown
Contributor

Opening a 50 MB Markdown file fails with Maximum call stack size exceeded because the importer passes all parsed paragraphs to one push(...items) call. After resolving that, the resulting 21,112-page document exceeds the browser’s element-height limit, leaving its final pages unreachable.

This PR fixes both:

  • Uses append loops for document-sized arrays in Markdown and HTML imports.
  • Bounds the document’s physical scroll height and maps it to logical page positions, following the existing spreadsheet viewer’s approach.
  • Applies that mapping to caret, find, outline and comment navigation, waiting for pages to reposition before measuring a navigation target.

The existing DOM rendering and visual editing path are retained, with no new runtime dependencies.

Regression coverage includes 150,000-paragraph Markdown and HTML inputs, a 150,000-line code block, and a document beyond the browser’s scroll-height limit whose final page is reached, searched, edited and saved. The original 50 MB fixture now loads completely, and its final marker is reachable and searchable.

Validation

  • All four new Chromium regression tests fail on upstream main and pass with this change.
  • 697 unit tests and 35 browser tests passed on this PR’s commit.
  • Typecheck and production build passed.
  • git diff --check passed.

The browser checks cover the new regressions plus existing document editing, selection, page setup and comments.

A caret whose paragraph moved to another page is repaired first; a caret on a page out of view then scrolls it into view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

2 participants