Skip to content

Conversation

@fulopkovacs
Copy link
Owner

@fulopkovacs fulopkovacs commented Jan 13, 2026

Summary by CodeRabbit

Release Notes

  • New Features
    • JSON responses and data structures now display with syntax highlighting for improved code readability and visual clarity.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 13, 2026

Walkthrough

Added shiki dependency and created a new CodeHighlighter component that renders syntax-highlighted code asynchronously using Shiki. Integrated CodeHighlighter into ApiRequestsPanel for JSON rendering with fallback support during highlighting.

Changes

Cohort / File(s) Summary
Dependencies
package.json
Added shiki ^3.21.0 as runtime dependency
New Component
src/components/CodeHighlighter.tsx
New React component that renders syntax-highlighted code using Shiki with async effect and loading fallback. Exports CodeHighlighter({ code, language? }) function with optional language parameter (defaults to "json"). Manages HTML generation asynchronously and renders via dangerouslySetInnerHTML with custom styling.
Integration
src/components/ApiRequestsPanel.tsx
Updated JsonViewer to use CodeHighlighter component for rendering JSON data instead of plain <pre> block. Stringifies JSON data once via jsonString constant and passes to CodeHighlighter.

Sequence Diagram(s)

sequenceDiagram
    participant ApiRequestsPanel
    participant CodeHighlighter
    participant Shiki
    
    ApiRequestsPanel->>CodeHighlighter: Render with code & language
    CodeHighlighter->>CodeHighlighter: Show fallback <pre><code> while loading
    CodeHighlighter->>Shiki: codeToHtml(code, language)
    Shiki-->>CodeHighlighter: Return highlighted HTML
    CodeHighlighter->>CodeHighlighter: Update state with HTML
    CodeHighlighter->>CodeHighlighter: Render highlighted HTML via dangerouslySetInnerHTML
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 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 accurately describes the main change: adding JSON syntax highlighting to API request content via a new CodeHighlighter component.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

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

@github-actions
Copy link

github-actions bot commented Jan 13, 2026

🚀 Preview Deployment

Status: ✅ Ready!

Preview URL: Open Preview

Commit: 789b8470b6d394b6a00d21ba9823590821700f1c

Built and deployed successfully

Copy link

@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

🤖 Fix all issues with AI agents
In @src/components/CodeHighlighter.tsx:
- Around line 18-37: The async call to codeToHtml in the CodeHighlighter
useEffect lacks error handling, so if it rejects the component can hang; update
the promise chain to handle rejections (or use try/catch with an async IIFE) and
when an error occurs, check the cancelled flag, log the error (e.g.,
console.error or a logger), and setHtml to a safe fallback (empty string or an
error placeholder) so the component exits the loading state; make the change
around the codeToHtml(...).then(...) block and also ensure the cancelled check
is applied before calling setHtml in both success and error paths.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 774d312 and 789b847.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • package.json
  • src/components/ApiRequestsPanel.tsx
  • src/components/CodeHighlighter.tsx
🧰 Additional context used
📓 Path-based instructions (5)
**/package.json

📄 CodeRabbit inference engine (AGENTS.md)

**/package.json: Always use pnpm install instead of npm install for installing dependencies
Always use pnpm add <package> instead of npm install <package> for adding packages
Always use pnpm add -D <package> instead of npm install --save-dev <package> for adding dev dependencies
Always use pnpm remove <package> instead of npm uninstall <package> for removing packages
Always use pnpm run <script> instead of npm run <script> for running scripts
Always use pnpm dlx <command> instead of npx <command>
Always use pnpm create <template> instead of npm create <template>

Files:

  • package.json
package.json

📄 CodeRabbit inference engine (AGENTS.md)

package.json: Use pnpm dev for starting the development server
Use pnpm build for production build
Use pnpm run test for running tests
Use pnpm lint for linting
Use pnpm typecheck for type checking
Use pnpm format for code formatting
Use pnpm db.generate to generate database migrations
Use pnpm db.local.migrate to apply local migrations
Use pnpm db.prod.migrate to apply production migrations

Files:

  • package.json
src/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Always ensure no formatting/linting issues exist in code - use pnpm check --fix to automatically fix issues

Files:

  • src/components/ApiRequestsPanel.tsx
  • src/components/CodeHighlighter.tsx
**/*.{tsx,ts}

📄 CodeRabbit inference engine (AGENTS.md)

Prefer functions over arrow functions for React components

Files:

  • src/components/ApiRequestsPanel.tsx
  • src/components/CodeHighlighter.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Prefer type over interface for type definitions

Files:

  • src/components/ApiRequestsPanel.tsx
  • src/components/CodeHighlighter.tsx
🧠 Learnings (2)
📚 Learning: 2025-12-24T15:25:07.106Z
Learnt from: fulopkovacs
Repo: fulopkovacs/trytanstackdb.com PR: 22
File: src/components/TodoBoards.tsx:63-81
Timestamp: 2025-12-24T15:25:07.106Z
Learning: In Tailwind CSS v4, prefer canonical classes using bg-linear-to-* (e.g., bg-linear-to-b, bg-linear-to-t, bg-linear-to-r) over the older bg-gradient-to-* syntax. This aligns with Tailwind LSP's suggestCanonicalClasses rule. Apply across TSX files (e.g., src/components/*.tsx); replace occurrences of bg-gradient-to-* with the corresponding bg-linear-to-* equivalents and verify gradients visually.

Applied to files:

  • src/components/ApiRequestsPanel.tsx
  • src/components/CodeHighlighter.tsx
📚 Learning: 2025-12-28T23:34:13.416Z
Learnt from: fulopkovacs
Repo: fulopkovacs/trytanstackdb.com PR: 32
File: src/components/HomeIntro.tsx:16-25
Timestamp: 2025-12-28T23:34:13.416Z
Learning: In Motion (motion/react), when configuring variant transitions, use delayChildren: stagger(x) to create per-child delays (e.g., delayChildren: stagger(0.2)). This is different from the older API that used a separate staggerChildren property. Apply this guidance to TSX files that declare motion variants (e.g., in src/components/**/*.tsx) and verify that stagger is imported from framer-motion. Ensure transitions reflect the intended stagger timing and that no conflicting delay values override the staggered effect.

Applied to files:

  • src/components/ApiRequestsPanel.tsx
  • src/components/CodeHighlighter.tsx
🧬 Code graph analysis (2)
src/components/ApiRequestsPanel.tsx (1)
src/components/CodeHighlighter.tsx (1)
  • CodeHighlighter (12-55)
src/components/CodeHighlighter.tsx (1)
vite.config.ts (1)
  • pre (44-51)
🪛 ast-grep (0.40.4)
src/components/CodeHighlighter.tsx

[warning] 51-51: Usage of dangerouslySetInnerHTML detected. This bypasses React's built-in XSS protection. Always sanitize HTML content using libraries like DOMPurify before injecting it into the DOM to prevent XSS attacks.
Context: dangerouslySetInnerHTML
Note: [CWE-79] Improper Neutralization of Input During Web Page Generation [REFERENCES]
- https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml
- https://cwe.mitre.org/data/definitions/79.html

(react-unsafe-html-injection)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Deploy Preview
🔇 Additional comments (7)
package.json (1)

67-67: Consider aligning shiki version with existing @shikijs packages.

The existing @shikijs/rehype and @shikijs/transformers are at ^3.20.0 (lines 42-43), while this adds shiki at ^3.21.0. This should work fine due to semver, but you may want to align versions for consistency.

src/components/ApiRequestsPanel.tsx (2)

62-64: LGTM!

The jsonString computation correctly handles both string and non-string data, with appropriate pretty-printing for objects.


76-76: LGTM!

Clean integration of the CodeHighlighter component with the appropriate props.

src/components/CodeHighlighter.tsx (4)

1-7: LGTM!

Clean imports and type definition following the coding guidelines (using type over interface).


9-10: Styling approach is reasonable.

The use of child selectors and !important modifiers is appropriate here to override Shiki's default inline styles.


39-46: Good fallback pattern.

Showing plain text immediately while the async highlighting loads provides a good user experience.


48-54: Usage of dangerouslySetInnerHTML is acceptable here.

The static analysis warning is a general caution, but Shiki's codeToHtml output is safe — it properly escapes input and generates deterministic HTML based on language grammar. The biome-ignore comment appropriately documents this.

Comment on lines +18 to +37
useEffect(() => {
let cancelled = false;

codeToHtml(code, {
lang: language,
themes: {
light: "material-theme-lighter",
dark: "material-theme-darker",
},
defaultColor: false,
}).then((result) => {
if (!cancelled) {
setHtml(result);
}
});

return () => {
cancelled = true;
};
}, [code, language]);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add error handling for the async highlighting operation.

If codeToHtml rejects (e.g., invalid language), the component will silently stay in the loading state indefinitely.

🛠️ Proposed fix
   useEffect(() => {
     let cancelled = false;
 
     codeToHtml(code, {
       lang: language,
       themes: {
         light: "material-theme-lighter",
         dark: "material-theme-darker",
       },
       defaultColor: false,
-    }).then((result) => {
-      if (!cancelled) {
-        setHtml(result);
-      }
-    });
+    })
+      .then((result) => {
+        if (!cancelled) {
+          setHtml(result);
+        }
+      })
+      .catch(() => {
+        // On error, keep showing plain text fallback
+        if (!cancelled) {
+          setHtml(null);
+        }
+      });
 
     return () => {
       cancelled = true;
     };
   }, [code, language]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
let cancelled = false;
codeToHtml(code, {
lang: language,
themes: {
light: "material-theme-lighter",
dark: "material-theme-darker",
},
defaultColor: false,
}).then((result) => {
if (!cancelled) {
setHtml(result);
}
});
return () => {
cancelled = true;
};
}, [code, language]);
useEffect(() => {
let cancelled = false;
codeToHtml(code, {
lang: language,
themes: {
light: "material-theme-lighter",
dark: "material-theme-darker",
},
defaultColor: false,
})
.then((result) => {
if (!cancelled) {
setHtml(result);
}
})
.catch(() => {
// On error, keep showing plain text fallback
if (!cancelled) {
setHtml(null);
}
});
return () => {
cancelled = true;
};
}, [code, language]);
🤖 Prompt for AI Agents
In @src/components/CodeHighlighter.tsx around lines 18 - 37, The async call to
codeToHtml in the CodeHighlighter useEffect lacks error handling, so if it
rejects the component can hang; update the promise chain to handle rejections
(or use try/catch with an async IIFE) and when an error occurs, check the
cancelled flag, log the error (e.g., console.error or a logger), and setHtml to
a safe fallback (empty string or an error placeholder) so the component exits
the loading state; make the change around the codeToHtml(...).then(...) block
and also ensure the cancelled check is applied before calling setHtml in both
success and error paths.

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