Skip to content

Commit 7741da6

Browse files
committed
fix(docs): drop a highlighter registration that can never fire
fumadocs-openapi calls `renderCodeBlock` with a hard-coded `"json"` from both of its call sites (`request-tabs.js:76`, `response-tabs.js:48`), so the docs `CodeBlock` it routes through never receives a shell language. The `getHighlighter('js', { langs: [curlJsonBodyGrammar] })` registering the shell-scoped JSON-body injection therefore did nothing but await on every API sample render, and the docblock claiming the grammar covers those samples was wrong. - Delete the call and its imports. - State the grammar's real coverage: prose fences only, via `langs`. Both API reference paths are unreachable — samples are JSON, and the cURL usage tabs highlight client-side off fumadocs' own factory. - Correct `code-block.tsx`'s TSDoc, which still said API samples come from fumadocs' own renderer. They come through this component; `UsageTab` is the renderer that bypasses it. - Re-home a comment orphaned when two CSS rules merged — it had drifted onto the rule below and read as documenting it. - Drop a `.nd-copy-ignore` claim about transformers emitting those nodes; nothing here does, and upstream parity is the reason the clone exists.
1 parent 3ae2cd7 commit 7741da6

4 files changed

Lines changed: 21 additions & 27 deletions

File tree

apps/docs/app/[lang]/[[...slug]]/page.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type React from 'react'
2-
import { getHighlighter, highlight } from 'fumadocs-core/highlight'
2+
import { highlight } from 'fumadocs-core/highlight'
33
import type { Root } from 'fumadocs-core/page-tree'
44
import { findNeighbour } from 'fumadocs-core/page-tree'
55
import type { ApiPageProps } from 'fumadocs-openapi/ui'
@@ -18,7 +18,6 @@ import { Heading } from '@/components/ui/heading'
1818
import { ResponseSection } from '@/components/ui/response-section'
1919
import { i18n } from '@/lib/i18n'
2020
import { getApiSpecContent, getAuthenticatedCodeSamples, openapi } from '@/lib/openapi'
21-
import { curlJsonBodyGrammar } from '@/lib/shiki-curl-json'
2221
import { simShikiOptions } from '@/lib/shiki-theme'
2322
import { type PageData, source } from '@/lib/source'
2423
import { DOCS_BASE_URL } from '@/lib/urls'
@@ -77,13 +76,8 @@ function stripLocalePrefix(url: string, lang: string): string {
7776
* rather than fumadocs-openapi's built-in one, so those blocks get the emcn copy control
7877
* instead of fumadocs' lucide clipboard. Mirrors the default renderer — same `highlight` call,
7978
* same `Pre` component, same `my-0` — differing only in which shell wraps the result.
80-
*
81-
* The `getHighlighter` call registers the JSON-body injection on the shared highlighter
82-
* `highlight` resolves. An injection is a property of the highlighter, not a per-call option, and
83-
* already-loaded grammars are skipped.
8479
*/
8580
async function ApiCodeBlock({ lang, code }: { lang: string; code: string }) {
86-
await getHighlighter('js', { langs: [curlJsonBodyGrammar] })
8781
return (
8882
<CodeBlock className='my-0'>
8983
{await highlight(code, { lang, ...simShikiOptions, components: { pre: Pre } })}

apps/docs/app/global.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,8 @@ figure.shiki code:has(.line ~ .line) .line::before {
17341734
the code surface. The viewport is the one box all three renderers agree on. */
17351735
figure.shiki > div[role="region"] {
17361736
background-color: var(--code-surface);
1737+
/* fumadocs ships 14px of vertical padding, the platform's viewer 8px; 10px splits them and
1738+
keeps a single-line fence from looking hollow at the tighter 21px line box. */
17371739
padding-block: 10px;
17381740
}
17391741

@@ -1743,9 +1745,6 @@ figure.shiki pre {
17431745
background-color: transparent;
17441746
}
17451747

1746-
/* Viewport padding — fumadocs ships 14px vertical; the platform's viewer uses 8px. Split the
1747-
difference at 10px, which keeps a single-line fence from looking hollow at the tighter
1748-
21px line box. */
17491748
/* Untitled blocks float the copy control over the code, so the last column has to clear it:
17501749
an 8px offset plus emcn's 20px icon button, with room to breathe. fumadocs reserves 32px,
17511750
which the glyphs run into.

apps/docs/components/ui/code-block.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,24 @@ function CopyButton({ getCode }: { getCode: () => string }) {
3333
}
3434

3535
/**
36-
* Docs code block for prose fences, wired into the MDX `pre` mapping.
36+
* Docs code block for prose fences and the API reference's request/response samples — the MDX
37+
* `pre` mapping and fumadocs-openapi's `renderCodeBlock` both render it.
3738
*
38-
* The shell — radius, hairline, fill — is not set here. Request and response samples in the
39-
* API reference come from fumadocs-openapi's own renderer, so the two share chrome through a
40-
* `figure.shiki` rule in `global.css` instead; see the note there. What stays here is the
41-
* part only this path has: the copy control, and the `my-4` prose rhythm that API samples,
42-
* which sit flush in their panel, must not inherit.
39+
* The shell — radius, hairline, fill — is not set here. A third renderer, fumadocs-openapi's
40+
* `UsageTab`, emits these figures without going through any component, so all three share
41+
* chrome through a `figure.shiki` rule in `global.css` instead; see the note there. What stays
42+
* here is the copy control, and the `my-4` prose rhythm that API samples, which sit flush in
43+
* their panel, override with `my-0`.
4344
*/
4445
export function CodeBlock({ title, ...props }: React.ComponentProps<typeof FumadocsCodeBlock>) {
4546
const figureRef = useRef<HTMLElement>(null)
4647

4748
/**
4849
* Reads the block's text the way fumadocs' own `CopyButton` does: from a clone, with
49-
* `.nd-copy-ignore` nodes replaced by newlines. Shiki transformers emit those to mark content
50-
* that is displayed but is not part of the code, so reading `pre.textContent` directly would
51-
* copy it. (The line-number gutter here is a `::before`, and pseudo-element content never
52-
* reaches `textContent` — it is not what this guards.)
50+
* `.nd-copy-ignore` nodes replaced by newlines — kept in step with upstream so a fence that
51+
* gains such a node copies the same text there and here. (The line-number gutter is a
52+
* `::before`, and pseudo-element content never reaches `textContent`, so it is not what this
53+
* guards.)
5354
*/
5455
function getCode() {
5556
const pre = figureRef.current?.getElementsByTagName('pre').item(0)

apps/docs/lib/shiki-curl-json.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import type { LanguageRegistration } from 'shiki'
1919
* directly to Client Components" takes down every API reference page. A grammar is plain data,
2020
* so it survives that boundary.
2121
*
22-
* Where it applies: prose fences, via `langs` on the MDX pipeline, and the API reference's
23-
* request/response samples, via the `getHighlighter` call in the docs page. NOT the API
24-
* reference's cURL usage tabs — those highlight in the browser off fumadocs' own factory, and
25-
* `ClientCodeBlockProvider` sits in a `"use client"` module the package does not expose through
26-
* its `exports` map, so reaching it means importing `fumadocs-openapi/ui/base` from client code
27-
* and dragging `remark` and `@fumari/json-schema-ts` into the browser bundle. That broke the
28-
* deployment once; it is not worth a second attempt.
22+
* Applies to prose fences only, via `langs` on the MDX pipeline. Not the API reference:
23+
* fumadocs-openapi calls `renderCodeBlock` with a hard-coded `"json"` for request and response
24+
* samples, so a shell injection can never fire there, and its cURL usage tabs highlight in the
25+
* browser off fumadocs' own factory — `ClientCodeBlockProvider` sits in a `"use client"` module
26+
* the package does not expose through its `exports` map, so reaching it means importing
27+
* `fumadocs-openapi/ui/base` from client code and dragging `remark` and
28+
* `@fumari/json-schema-ts` into the browser bundle. That broke the deployment once.
2929
*
3030
* The opening brace requires a `}`, a quoted key, or end-of-line after it. That is what keeps
3131
* `awk '{print $1}'` out, while still matching a body whose brace ends the line — Oniguruma

0 commit comments

Comments
 (0)