Skip to content

fix(docs): make copy markdown work for index pages in production#7520

Merged
mhartington merged 1 commit intomainfrom
fix/copy-as-markdown
Feb 18, 2026
Merged

fix(docs): make copy markdown work for index pages in production#7520
mhartington merged 1 commit intomainfrom
fix/copy-as-markdown

Conversation

@aidankmcalister
Copy link
Member

@aidankmcalister aidankmcalister commented Feb 18, 2026

Retry markdown fetch with an /index.mdx fallback when the slug-based .mdx URL returns 404.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of content fetching by implementing an automatic fallback mechanism when initial fetch attempts fail.
    • Enhanced clipboard copying functionality to utilize improved fetch strategy and better manage content caching.
    • Optimized content resolution and caching logic for more consistent behavior.

Retry markdown fetch with an /index.mdx fallback when the slug-based .mdx URL returns 404.
@vercel
Copy link

vercel bot commented Feb 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Feb 18, 2026 0:24am

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

Walkthrough

This change implements a fallback fetch strategy for Markdown/MDX content in the page-actions component. Two new utility functions handle URL derivation and content fetching with fallback logic, while LLMCopyButton is updated to leverage this strategy with enhanced caching.

Changes

Cohort / File(s) Summary
MDX Content Fallback Strategy
apps/docs/src/components/page-actions.tsx
Added toIndexMarkdownUrl() to normalize .mdx URLs to index.mdx equivalents. Added fetchMarkdownWithFallback() to attempt original URL fetch and gracefully fall back to index.mdx variant. Updated LLMCopyButton to use new fetch strategy and cache both original and resolved URLs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(docs): make copy markdown work for index pages in production' directly addresses the main change: implementing a fallback fetch strategy so the copy markdown feature works for index pages. It accurately summarizes the core problem and solution.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

🍈 Lychee Link Check Report

3660 links: ✅ 2985 OK | 🚫 9 errors | 🔀 0 redirects | 👻 664 excluded

❌ Errors

./apps/docs/content/docs.v6/(index)/prisma-orm/add-to-existing-project/mongodb.mdx

./apps/docs/content/docs.v6/(index)/prisma-orm/quickstart/mongodb.mdx

./apps/docs/content/docs.v6/orm/more/ai-tools/tabnine.mdx

./apps/docs/content/docs.v6/orm/prisma-client/deployment/traditional/deploy-to-railway.mdx

./apps/docs/content/docs.v6/orm/prisma-client/setup-and-configuration/databases-connections/index.mdx

./apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/mongodb.mdx

./apps/docs/content/docs/(index)/prisma-orm/quickstart/mongodb.mdx

./apps/docs/content/docs/ai/tools/tabnine.mdx

./apps/docs/content/docs/orm/prisma-client/deployment/traditional/deploy-to-railway.mdx


Full Statistics Table
Status Count
✅ Successful 2985
🔀 Redirected 0
👻 Excluded 664
🚫 Errors 9
⛔ Unsupported 2
⏳ Timeouts 0
❓ Unknown 0

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/docs/src/components/page-actions.tsx`:
- Around line 61-78: The promise passed into ClipboardItem via
fetchMarkdownWithFallback can reject and that error is currently uncaught, so
update the onClick handler (the useCopyButton callback) to wrap the
navigator.clipboard.write call in try/catch around the await and handle failures
from fetchMarkdownWithFallback/ClipboardItem; on error, ensure you still clear
loading (setLoading(false) is in finally) and surface user feedback (e.g., set
an error state or call your app’s toast/notification function) and optionally
log the error and avoid caching on failure—refer to fetchMarkdownWithFallback,
ClipboardItem, navigator.clipboard.write, setLoading, cache, and the
useCopyButton callback to locate the change.

Comment on lines 61 to 78
const [checked, onClick] = useCopyButton(async () => {
const cached = cache.get(markdownUrl);
const fallbackUrl = toIndexMarkdownUrl(markdownUrl);
const cached = cache.get(markdownUrl) ?? (fallbackUrl ? cache.get(fallbackUrl) : undefined);
if (cached) return navigator.clipboard.writeText(cached);

setLoading(true);

try {
await navigator.clipboard.write([
new ClipboardItem({
'text/plain': fetch(markdownUrl).then(async (res) => {
const content = await res.text();
'text/plain': fetchMarkdownWithFallback(markdownUrl).then(({ content, resolvedUrl }) => {
cache.set(markdownUrl, content);
cache.set(resolvedUrl, content);

return content;
return new Blob([content], { type: 'text/plain' });
}),
}),
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Smart dual-key caching strategy.

The cache lookup logic on lines 62-63 is clever—by pre-computing the potential fallback URL and checking both cache keys before fetching, you avoid unnecessary network requests when content was previously loaded via either path. The dual caching on lines 72-73 completes this nicely.

One observation: if fetchMarkdownWithFallback rejects (network failure or both URLs returning errors), the promise passed to ClipboardItem will reject. The finally block correctly resets the loading state, but the error itself isn't caught. The user would see the button stop loading with no indication of what went wrong. Consider whether a user-facing error state or toast notification would improve the experience.

💡 Optional: Add error feedback
+  const [error, setError] = useState<string | null>(null);
   const [checked, onClick] = useCopyButton(async () => {
+    setError(null);
     const fallbackUrl = toIndexMarkdownUrl(markdownUrl);
     const cached = cache.get(markdownUrl) ?? (fallbackUrl ? cache.get(fallbackUrl) : undefined);
     if (cached) return navigator.clipboard.writeText(cached);

     setLoading(true);

     try {
       await navigator.clipboard.write([
         new ClipboardItem({
           'text/plain': fetchMarkdownWithFallback(markdownUrl).then(({ content, resolvedUrl }) => {
             cache.set(markdownUrl, content);
             cache.set(resolvedUrl, content);

             return new Blob([content], { type: 'text/plain' });
           }),
         }),
       ]);
+    } catch (e) {
+      setError('Failed to copy markdown');
+      console.error(e);
     } finally {
       setLoading(false);
     }
   });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/docs/src/components/page-actions.tsx` around lines 61 - 78, The promise
passed into ClipboardItem via fetchMarkdownWithFallback can reject and that
error is currently uncaught, so update the onClick handler (the useCopyButton
callback) to wrap the navigator.clipboard.write call in try/catch around the
await and handle failures from fetchMarkdownWithFallback/ClipboardItem; on
error, ensure you still clear loading (setLoading(false) is in finally) and
surface user feedback (e.g., set an error state or call your app’s
toast/notification function) and optionally log the error and avoid caching on
failure—refer to fetchMarkdownWithFallback, ClipboardItem,
navigator.clipboard.write, setLoading, cache, and the useCopyButton callback to
locate the change.

@mhartington mhartington merged commit e394c5e into main Feb 18, 2026
6 of 10 checks passed
@mhartington mhartington deleted the fix/copy-as-markdown branch February 18, 2026 00:35
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.

2 participants

Comments