Conversation
…slash flag transformerTwoslash builds a typescript virtual filesystem on construction and was constructed once per code block; with explicitTrigger it is a no-op unless the block carries the twoslash meta flag
createHighlighter compiled all 30 default grammars before the first block was highlighted, and the twoslash renderer pulled in typescript at module load. both now load on demand, which halves cold-start cost for the compile route
highlighted output is a pure function of code, language and themes for bundled grammars, and localized docs repeat nearly every block across locales. keep an lru of recent results and hand out clones, since later plugins mutate the tree
adds vitest and tests that pass on main and on this branch: default and lazily loaded grammars, unknown-language fallback, twoslash gating by the meta flag, and repeated blocks yielding equal but independent trees
twoslash highlights popup snippets through shiki with whatever language the docs contain and relied on the eager highlighter having every default grammar loaded; caught by the new tests. also trims comments to one line
This reverts commit 669bf62. # Conflicts: # packages/mdx/src/plugins/rehype/rehypeSyntaxHighlighting.ts
This branch has not been 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.
Summary
Two changes to
rehypeSyntaxHighlighting, output verified byte-identical against the published build on a set of real pages and on a twoslash block.transformerTwoslash()builds a TypeScript virtual filesystem on construction and was constructed once per code block; withexplicitTriggerit is a no-op unless the block carries thetwoslashmeta flag. On a page with several hundred code blocks this was about a quarter of compile time.createHighlightercompiled all 30 default grammars up front, and the twoslash renderer pulled intypescriptat module load. Both now load on demand; twoslash blocks preload the default grammar set because their popups render arbitrary snippets through shiki. Local cold path (import + first compile) drops from ~1370ms to ~610ms.An in-process cache of highlighted blocks was tried and reverted in this branch; it only pays on warm long-lived instances and its memory bound needs more thought, so it will come as its own change if at all.
Test Plan
yarn typeandyarn buildclean (eslint could not run locally:@mintlify/eslint-config-typescriptis not resolvable in this checkout)ts twoslashblock produces the same hash and popup count as the published build@mintlify/mdxbump once this is released