Skip to content

Astro/migration - #1813

Merged
askoufis merged 4 commits into
masterfrom
astro/migration
Nov 22, 2026
Merged

askoufis merged 4 commits into
masterfrom
astro/migration

Conversation

@askoufis

@askoufis askoufis commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Rebuilds the docs site on Astro. Each commit has a detailed description.

Highlights:

  • Pages are now static HTML, with React only in the parts that need it (via Astro islands)
  • Docs come from a content collection, and code blocks are highlighted with Shiki at build time. Not every quirk of primsjs's highlighting could be replicated, so some code blocks are highlighted quite differently, while others are barely affected.
  • ts compiled code blocks are compiled with @vanilla-extract/compiler through an mdast plugin.
  • react-router is replaced with plain links, so navigation is a full page load, legacy routes are now Astro redirects. Client-side navigation may be re-introduced in the future.
  • Removes webpack, Babel and the custom docs loaders.
  • Render code blocks without hydrating them. File tabs and the "Show Output" toggle now use form controls and CSS instead of React state.
  • Upgrade the site to React 19

Rebuilds the docs site on Astro, replacing the custom webpack setup: a client and a server render build, an HTML render plugin, a docs manifest generator, an MDX loader, and a webpack loader that compiled code blocks.

Pages are now static HTML. React only runs in the parts of the page that need it (Astro "islands"), instead of hydrating the whole site as one app.

- `layouts/Layout.astro` replaces the `<head>` from `render.tsx`, including the colour mode script and the font preload.
- `pages/index.astro` renders the homepage. The search input, colour mode toggle and GitHub stars are passed in as islands, and the code samples are highlighted at build time.
- `pages/documentation/[...slug].astro` renders each docs page from a content collection (`content.config.ts`). Page order and grouping still come from `contents.ts`.
- `DocsPage` is split into `DocsChrome` (header, primary nav and mobile menu, an island), `SecondaryNav` (an island), and `DocsMain` (static).
- `useActiveHeading` replaces `useHeadingRoute`. It highlights the heading in the secondary nav using `IntersectionObserver`, and no longer rewrites the URL hash while scrolling.
- `Link` and `ButtonLink` render plain anchors, replacing `react-router-dom` and `react-router-hash-link`.
- Legacy routes become Astro `redirects`, and static assets move to `public/`.

- A satteri mdast plugin (`markdown/docsPlugin.ts`) replaces `code-block-loader.js`. Astro passes MDX components their children as pre-rendered HTML, so the plugin handles anything that depends on the markdown's structure:
  - Code blocks are highlighted with Shiki and rendered with `CodeBlock`. A leading `// file.ts` comment becomes the title.
  - ` ```ts compiled ` blocks are compiled with `@vanilla-extract/compiler` (`markdown/compileVanillaExtract.ts`), and the CSS is shown alongside. Each block's files are served from a virtual directory named by a hash of its contents, so blocks can't import each other and edits never hit stale modules. An Astro integration closes the compiler when the build or dev server finishes.
  - Links whose only child is inline code, and paragraphs in blockquotes, are marked so `mdx-components.tsx` can style them.
- Shiki's CSS variables theme is used, with colours set per colour mode in `Code/highlighting.css.ts` and scope overrides chosen to match the old Prism colours. This replaces `react-syntax-highlighter` and `ErrorHighlighter`; homepage type errors are underlined with Shiki decorations.
- Compiled code blocks are hydrated islands (`MdxCompiledCode`), as switching files and showing the CSS output use React state.

- The site has its own `tsconfig.json`, and is type-checked with `astro check` (`pnpm lint:site`, included in `pnpm lint`) instead of the root `tsc`.
- CI no longer generates a docs manifest.
- DocSearch and its Algolia dependencies are bundled for server rendering, as their ESM builds can't be imported by Node.
- Removes webpack, Babel, the docs manifest and indexer, and their dependencies.
- `CONTRIBUTING.md` mentions Astro.
Compiled code blocks were hydrated React islands, only so their file tabs and "Show Output" button could use React state. Every block on a page was hydrated as it scrolled into view, and its highlighted code was sent twice: once as HTML and again as island props.

They're now plain HTML, using form controls and CSS for that state:

- File tabs are radio inputs, one per file, with the file name as the `<label>`. Each file's panel follows its tab in the DOM, and is hidden unless its radio is checked. Panels are ordered after all the tabs in a wrapping flex row, so they sit below them. The radios are native, so they're keyboard accessible.
- "Show Output" is a checkbox inside the button's `<label>`, covering the button. The source and output panels react to it with `:has()`. Clicking a label focuses its input, and the browser scrolls focused inputs into view. With the checkbox covering the button, that never scrolls further than the button itself.
- Compiled blocks are rendered by a `CompiledCodeBlock` MDX component, so the docs plugin no longer injects an import for the island into each MDX file. `MdxCompiledCode` and `MdxBlock` are removed.

Each file's output toggle is now independent, so switching files no longer resets "Show Output".
Highlighted code was passed around as an HTML string from Shiki and rendered with `dangerouslySetInnerHTML`. Now that code blocks aren't hydrated, the size of their props doesn't matter, so this passes Shiki's tokens instead and renders them as React elements.

- `highlight()` returns a flat list of tokens, each with its text and colour, using `codeToTokensBase`. Lines are joined with newline tokens.
- `CompiledCode` renders each token as a `<span>` coloured with Shiki's CSS variables.
- Homepage type errors are marked on the tokens instead of with Shiki decorations. Shiki merges punctuation into neighbouring tokens (e.g. `.brandd`), so tokens are split around each error identifier. The underline style moves from the homepage styles to `Code/highlighting.css.ts`.
Upgrades the docs site to React 19, mainly so `Box` can take a `ref` without being wrapped in `forwardRef`.

- `react`, `react-dom` and their types use `npm:` aliases, the same as the Next.js 16 fixture, as manypkg requires every workspace package to use the same version range and the examples and other fixtures are still on React 18.
- `Box` accepts a `ref` prop, and `DocsChrome` uses a ref for the primary nav (for the breakpoint transition fix) instead of finding it with `document.querySelector('[data-primary-nav]')`.
- React 19's types no longer declare a global `JSX` namespace, which `@types/mdx` relies on. `mdx-components.tsx` now types its components with React's own `JSX` types, and `@types/mdx` is removed.

`@docsearch/react` 3.3.3 declares a peer dependency on React below 19, so pnpm warns about it. Search still works, and upgrading DocSearch changes its styles, so it's left as is.
@changeset-bot

changeset-bot Bot commented Nov 22, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f49a5c7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@askoufis
askoufis merged commit 600c9b3 into master Nov 22, 2026
11 of 13 checks passed
@askoufis
askoufis deleted the astro/migration branch November 22, 2026 05:18
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.

1 participant