Repository navigation
Fix highlighting of inline multi-file code under 'init' - #6
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation addresses both server and client failure modes with comprehensive regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes inline multi-file syntax highlighting when highlightAfter: 'init' is used without a source URL, while preventing clients from treating in-progress grammars as ready.
Changes:
- Tracks grammar scopes only after Starry Night creation or registration settles.
- Processes inline extra files through the standard parsing, transformation, enhancement, and fallback pipeline.
- Adds unit, server-rendering, client hydration, and end-to-end regression coverage.
| File | Description |
|---|---|
packages/docs/src/pipeline/parseSource/parseSource.ts |
Tracks grammar scopes that are ready for highlighting. |
packages/docs/src/pipeline/parseSource/grammarCache.ts |
Reads ready scopes instead of prematurely registered scopes. |
packages/docs/src/pipeline/parseSource/ensureGrammars.test.ts |
Tests behavior during in-progress registration. |
packages/docs/src/pipeline/loadIsomorphicCodeVariant/loadIsomorphicCodeVariant.ts |
Parses inline extra files without requiring a base URL. |
packages/docs/src/pipeline/loadIsomorphicCodeVariant/loadIsomorphicCodeVariant.test.ts |
Covers parsing, transformations, disabled parsing, and pre-parsed sources. |
packages/docs/src/CodeHighlighter/CodeSourceLoader.test.tsx |
Verifies server-rendered highlighting timing. |
packages/docs/src/CodeHighlighter/CodeHighlighterClient.stringFiles.test.tsx |
Verifies client handling of string files and grammar-registration races. |
docs/app/lib/components/code-highlighter/demos/demo-init-inline-files/test.ts |
Adds end-to-end server, hydration, and transform checks. |
docs/app/lib/components/code-highlighter/demos/demo-init-inline-files/page.tsx |
Exposes the regression fixture as a route. |
docs/app/lib/components/code-highlighter/demos/demo-init-inline-files/InlineFiles.tsx |
Configures inline multi-file highlighting scenarios. |
docs/app/lib/components/code-highlighter/demos/demo-init-inline-files/FilesContent.tsx |
Renders all files and supports TS-to-JS toggling. |
docs/app/lib/components/code-highlighter/demos/demo-init-inline-files/code.ts |
Defines the inline multi-file fixture. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch was successfully 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
With
highlightAfter: 'init'and inline multi-filecodewith nourl, the extra files were never highlighted, and the server HTML showed every file plain, the main file included. Inline sources no longer need aurlto be parsed.Cause
url,loadIsomorphicCodeVariantpassed inlineextraFilesthrough as raw strings. With strings left, the client holds the whole block's highlight gate until it can parse them, which it can't do during a server render, so every file rendered plain.areGrammarsRegisteredread Starry Night'sscopes(), which lists a grammar as soon asregister()starts, while highlighting keeps using the previous registry until it resolves. UnderCodeProviderLazy, a block rendering in that window parsed its string files into plain text and never re-parsed.Fix
url, inline source strings go through the sameloadExtraFilespipeline as with one (parse, enhance with each file's comments, TS→JS transforms, fallback, line counts). Already-parsed or empty inline sources are kept as before; the URL path is unchanged. Inline extras are now parsed for everyhighlightAftervalue, as they always were with aurl; visible timing for'idle'/'hydration'is unchanged.parseSourcerecords which scopes are ready oncecreateStarryNightorregister()settles, andareGrammarsRegisteredreads that. A failed registration still fails open.url-based block (about 10 ms per small extra file, including compression).Tests
loadIsomorphicCodeVariant: inline extra files without aurlare parsed, and match theurlresult (updated one assertion that expected the unparsed string).CodeSourceLoader: server-rendered output has every file highlighted under'init', and plain under'idle'.areGrammarsRegisteredstays false while a grammar is still registering;CodeHighlighterClienthighlights string files when their grammars are mid-registration at mount.code-highlighter/demos/demo-init-inline-files: server HTML, hydration and the TS→JS toggle, with no console errors.Verification
pnpm test --run,pnpm typescript,pnpm eslint, prettierpnpm docs:lib,pnpm docs:build,pnpm docs:validate(0 changes, twice)demo-variantsflake (about 40%, same asmain)