Repository navigation
Astro/migration - #1813
Merged
Merged
Astro/migration#1813
Conversation
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.
|
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.
Rebuilds the docs site on Astro. Each commit has a detailed description.
Highlights:
primsjs's highlighting could be replicated, so some code blocks are highlighted quite differently, while others are barely affected.ts compiledcode blocks are compiled with @vanilla-extract/compiler through an mdast plugin.react-routeris 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.