fix(demo): ship the highlighter's grammars so the docs site highlights - #134
Merged
Conversation
Every code block on the docs site rendered plain, and
equality.eqtylab.io/components/code-block/ answered 404 for
/_astro/grammars/json.js and its siblings.
The highlighter reaches a grammar through import(`./grammars/${language}.js`),
a specifier no bundler expands, so the 37 grammar modules were never written
to the build. The loader catches the failed import and returns null, which
reads as "no grammar for this language" — so nothing is logged and the block
just loses its colour. A dev server serves the modules from their real path
in node_modules, which is why this only showed up on the deployed site.
A vite plugin now emits them beside whichever chunk carries that import,
which Astro hashes into _astro/. Resolved through the ui package, since that
is what declares the highlighter; the demo itself cannot resolve it.
Removable once the highlighter can be handed its grammars directly.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Every code block on the docs site renders plain. equality.eqtylab.io/components/code-block/ answers 404 for
/_astro/grammars/json.js,bash.js,javascript.jsandtsx.js.Cause
The highlighter reaches a grammar through a computed dynamic import (
microlighter/grammar-dependencies.js):No bundler expands that specifier — it is inside
node_modules, and Rollup emits no warning — so the 37 grammar modules are never written to the build. At runtime the browser resolves the path against the chunk's own URL, which Astro hashes into_astro/, giving/_astro/grammars/json.js. Nothing is there.The
.catch(() => null)then swallows it, and the highlighter readsnullas "no grammar for this language", so the block silently loses its colour with nothing logged.Confirmed locally before the fix:
dist/_astro/code-block.Dhmj5oy2.jscarries the unexpanded import, there is nodist/_astro/grammars/directory, and no grammar module appears anywhere indist/.A dev server serves the modules from their real path in
node_modules, which is why this only ever showed up on the deployed site.Fix
A vite plugin emits the grammars beside whichever chunk carries the import, deriving the directory from that chunk's own
fileNameso it follows Astro's asset layout rather than hardcoding_astro.It resolves the highlighter through the ui package, which is what declares it —
packages/democannot resolvemicrolighterat all (MODULE_NOT_FOUND), since it only gets it transitively through the workspace.Verification
Built locally and served, then checked in a real browser:
37 grammars emitted to
dist/_astro/grammars/. prettier and eslint clean.Scope
This is the same defect already fixed in eqtylab/explorer#63 and Guardian's studio — the docs site is the third consumer hit by it. Each build has to place the files itself, because the specifier resolves against the importing chunk and bundling equality's dist relocates the path, so this package cannot fix it for consumers from the library side.
All three copies come out once the highlighter can be handed its grammars directly, which is worth raising upstream. If the plugin outlives that by long, it is worth exporting from this package as
@eqtylab/equality/viteso there is one implementation instead of three.No publish: this touches only
packages/demo, andpublish.yamltriggers onpackages/ui/package.json. Merging does redeploy the docs, sincedocs.yamlwatchespackages/**.🤖 Generated with Claude Code