Repository navigation
fix: stop source view renders from running API workers out of memory - #1605
Merged
Merged
Conversation
Highlighting multi-megabyte files (generated vocabularies, bundled JSON schemas) in the file view pushed API worker isolates past their memory limit, taking every concurrent request on them down with exceededMemory. Files over the cap are now trimmed at the last full line before it and flagged with `truncated`, and the file view shows a notice when a file was cut short.
The API no longer highlights files for the file view. `/source` now returns the (capped) file text as `content`, along with the import and export specifier links as UTF-16 ranges into it, and the frontend highlights it with Prism into the same markup and classes as before, so line numbers, `#L` anchors and specifier links keep working. This also drops the second full copy of every file the response used to carry in the copy button's `data-copy` attribute. BREAKING: `view` is replaced by `content` and `links` in the source endpoint's file response.
Docs code blocks are now highlighted in the frontend too. The API emits them unhighlighted, tagged with their language as `data-lang` on the `<code>` element, and the frontend highlights them with the same Prism highlighter as the file view while loading the docs payload. This covers docs pages, the markdown preview and the diff view. That leaves the API with no syntax highlighting at all, so tree-sitter and its 14 grammar crates are gone.
littledivy
approved these changes
Nov 29, 2026
This branch was previously deployed
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.
Prod
jsr-apilogged ~4,700exceededMemoryinvocations in 24h. Most were cheap requests (package GETs,/downloads: ~5ms CPU, long wall times) on isolates that died while they were in flight. The requests actually doing heavy work were/sourcerenders of very large generated files:@fedify/vocab'svocab.ts(3.2 MB),@skmtc/core's_schemas/cloudflare.json(10.3 MB) andstripe.json(6.8 MB), plus a few large/docsrenders. The handler highlighted the whole file with tree-sitter, buffered the highlighted HTML and a second full copy of the file for the copy button, then copied all of it into JS.Three commits:
fix: cap the source file view at 512 KiB: files over the cap are trimmed at the last full line before it and flaggedtruncated. The file view shows a notice when that happens.feat: highlight the source file view in the frontend:/sourcereturns the capped text ascontentplus the specifier links as UTF-16 ranges. The frontend highlights it with Prism into the same markup andpl-*classes, so line numbers,#Lanchors and specifier links keep working. At the cap, the worst case (vocab.ts) takes ~66ms and ~33 MB of transient heap.refactor: remove tree-sitter: docs code blocks are emitted unhighlighted withdata-lang, and the frontend highlights them while loading docs (docs pages, markdown preview, diff view). The API no longer does any syntax highlighting, and tree-sitter plus its 14 grammar crates are removed.