[Bug][UI] `MarkdownCopyButton` copies HTTP error pages, and caches the result until a full reload
To Reproduce
- Render
<MarkdownCopyButton markdownUrl="/docs/missing.md" />for a URL that returns 404 or 500. - Click it.
- Separately, on a page whose
.mddoes exist: click the button, change the page's source under the dev server so the.mdoutput changes, then click again without a full reload.
Current vs. Expected behavior
Current:
- For a failing URL, the error response body (the host's HTML error page) is copied as if it were the page's Markdown, and the button shows its success tick.
- The response is cached per
markdownUrlin a module-levelMap. Later clicks copy the same content, including a cached error page, until a full reload. Under the dev server, edits aren't picked up.
Expected: A non-OK response rejects, so nothing is copied and no success tick shows. A failed fetch isn't cached. Ideally there's no in-memory cache at all, since the browser's HTTP cache already covers repeat clicks on a published site.
Framework
Tanstack Start
Provide environment information
Framework: TanStack Start 1.168.50 (@tanstack/react-router 1.170.33), Vite 8.2.2
Operating System:
Platform: win32
Binaries:
Node: 24.12.0
Relevant Packages:
fumadocs-core: 16.15.15
fumadocs-ui: 16.15.15
fumadocs-mdx: 15.4.0
fumadocs-openapi: 11.4.1
react: 19.2.8
react-dom: 19.2.8Which area(s) are affected? (Select all that apply)
UI
Additional context
Observed on the versions above. The same code is in fumadocs-openapi 12.0.4 and on dev as of 1bc5374; source paths are relative to packages/ on that commit.
base-ui/src/layouts/shared/page-actions.tsx (same in radix-ui), lines 11 and 29–36:
const promise = fetch(markdownUrl).then((res) => res.text());
cache.set(markdownUrl, promise);There is no res.ok check. #3328 looks like the same symptom, with the copy button placing the dev server's 404 HTML on the clipboard. It was closed because the 404 itself came from a Nitro bug, but the button would still copy any error body. A fix that keeps the Safari-friendly ClipboardItem promise:
const promise = fetch(markdownUrl).then((res) => {
if (!res.ok) throw new Error(`Failed to fetch ${markdownUrl}: ${res.status}`);
return res.text();
});Remove the cache entry if the promise rejects, or drop the cache.
Source: fuma-nama/fumadocs