(SP: 3) [Frontend] Q&A: Code block renderer fails on legacy answerBlocks#413
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
📝 WalkthroughWalkthroughThe PR adds backward-compatibility support for Q&A code block rendering by allowing both Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
frontend/components/q&a/CodeBlock.tsx (1)
20-25: Consider disabling the copy button when there's no code.The guard at line 21 silently returns when
safeCodeis empty, but the "Copy" button remains visible and clickable. Users clicking it would see no feedback.💡 Optional: Disable button when code is empty
<button onClick={handleCopy} aria-label="Copy code" + disabled={!safeCode} className="absolute top-2 right-3 flex cursor-pointer items-center gap-1 rounded-md bg-white/70 px-2 py-1 text-xs text-gray-400 backdrop-blur transition-colors hover:text-gray-700 dark:bg-black/40 dark:hover:text-gray-200" >🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/components/q`&a/CodeBlock.tsx around lines 20 - 25, The copy handler handleCopy currently returns early when safeCode is empty but the Copy button remains active; update the CodeBlock component so the Copy button is disabled (and optionally styled/aria-disabled) whenever safeCode is falsy. Locate the handleCopy function and the JSX for the Copy button in CodeBlock.tsx and add a disabled={Boolean(!safeCode)} prop (or equivalent) and ensure clicks are ignored when disabled; keep existing setCopied behavior for successful copies.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@frontend/components/q`&a/CodeBlock.tsx:
- Around line 20-25: The copy handler handleCopy currently returns early when
safeCode is empty but the Copy button remains active; update the CodeBlock
component so the Copy button is disabled (and optionally styled/aria-disabled)
whenever safeCode is falsy. Locate the handleCopy function and the JSX for the
Copy button in CodeBlock.tsx and add a disabled={Boolean(!safeCode)} prop (or
equivalent) and ensure clicks are ignored when disabled; keep existing setCopied
behavior for successful copies.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 383f5c64-f850-462e-9881-ff19152e608b
📒 Files selected for processing (3)
frontend/components/q&a/AccordionList.tsxfrontend/components/q&a/CodeBlock.tsxfrontend/components/q&a/types.ts
Issue
Q&A page crashes for some records where code blocks are stored with code field instead of content.
Current behavior
Renderer expects:
{ "type": "code", "content": "..." }But DB may contain:
{ "type": "code", "code": "..." }This causes undefined.trim() in CodeBlock and breaks rendering.
Expected behavior
Code blocks should render safely for both legacy (code) and current (content) formats without runtime errors.
Acceptance criteria
Q&A renderer supports both content and code for type: "code" blocks
CodeBlock does not crash when input is missing/undefined
Existing content format remains fully compatible
No runtime error: Cannot read properties of undefined (reading 'trim')
Notes
Scope is a backward-compatibility bugfix in frontend rendering only.
Closes #412
Summary by CodeRabbit
Refactor
Bug Fixes