highlight the json content of the api requests #44
- 1
🚀 Preview Deployment#
Status: ✅ Ready!
Preview URL: Open Preview
Commit:
789b8470b6d394b6a00d21ba9823590821700f1cBuilt and deployed successfully
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 774d3128676cb8d78bc8da55eb136427172f6d0a and 789b8470b6d394b6a00d21ba9823590821700f1c.
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
package.jsonsrc/components/ApiRequestsPanel.tsxsrc/components/CodeHighlighter.tsx
🧰 Additional context used
📓 Path-based instructions (5)
**/package.json
📄 CodeRabbit inference engine (AGENTS.md)
**/package.json: Always usepnpm installinstead ofnpm installfor installing dependencies Always usepnpm add <package>instead ofnpm install <package>for adding packages Always usepnpm add -D <package>instead ofnpm install --save-dev <package>for adding dev dependencies Always usepnpm remove <package>instead ofnpm uninstall <package>for removing packages Always usepnpm run <script>instead ofnpm run <script>for running scripts Always usepnpm dlx <command>instead ofnpx <command>Always usepnpm create <template>instead ofnpm create <template>Files:
package.json
package.json
📄 CodeRabbit inference engine (AGENTS.md)
package.json: Usepnpm devfor starting the development server Usepnpm buildfor production build Usepnpm run testfor running tests Usepnpm lintfor linting Usepnpm typecheckfor type checking Usepnpm formatfor code formatting Usepnpm db.generateto generate database migrations Usepnpm db.local.migrateto apply local migrations Usepnpm db.prod.migrateto apply production migrationsFiles:
package.json
src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Always ensure no formatting/linting issues exist in code - use
pnpm check --fixto automatically fix issuesFiles:
src/components/ApiRequestsPanel.tsxsrc/components/CodeHighlighter.tsx
**/*.{tsx,ts}
📄 CodeRabbit inference engine (AGENTS.md)
Prefer functions over arrow functions for React components
Files:
src/components/ApiRequestsPanel.tsxsrc/components/CodeHighlighter.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Prefer
typeoverinterfacefor type definitionsFiles:
src/components/ApiRequestsPanel.tsxsrc/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.tsxsrc/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.tsxsrc/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/rehypeand@shikijs/transformersare at^3.20.0(lines 42-43), while this addsshikiat^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
jsonStringcomputation correctly handles both string and non-string data, with appropriate pretty-printing for objects.
76-76: LGTM!Clean integration of the
CodeHighlightercomponent with the appropriate props.src/components/CodeHighlighter.tsx (4)
1-7: LGTM!Clean imports and type definition following the coding guidelines (using
typeoverinterface).
9-10: Styling approach is reasonable.The use of child selectors and
!importantmodifiers 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
codeToHtmloutput is safe — it properly escapes input and generates deterministic HTML based on language grammar. The biome-ignore comment appropriately documents this.src/components/CodeHighlighter.tsx lines 18 to 37@@ -0,0 +17,21 @@17+18+ useEffect(() => {19+ let cancelled = false;20+21+ codeToHtml(code, {22+ lang: language,23+ themes: {24+ light: "material-theme-lighter",25+ dark: "material-theme-darker",26+ },27+ defaultColor: false,28+ }).then((result) => {29+ if (!cancelled) {30+ setHtml(result);31+ }32+ });33+34+ return () => {35+ cancelled = true;36+ };37+ }, [code, language]);⚠️ Potential issue | 🟡 Minor
Add error handling for the async highlighting operation.
If
codeToHtmlrejects (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.
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.fuko merged this8d4914f
fuko closed this
Sign in to join this conversation.
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#
package.jsonsrc/components/CodeHighlighter.tsxCodeHighlighter({ code, language? })function with optional language parameter (defaults to "json"). Manages HTML generation asynchronously and renders viadangerouslySetInnerHTMLwith custom styling.src/components/ApiRequestsPanel.tsx<pre>block. Stringifies JSON data once viajsonStringconstant and passes to CodeHighlighter.Sequence Diagram(s)#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
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