feat: add YAML syntax highlighting for resource details#293
Conversation
Signed-off-by: A69SHUBHAM <spacekrai0@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @A69SHUBHAM! It looks like this is your first PR to volcano-sh/dashboard 🎉 |
There was a problem hiding this comment.
Code Review
This pull request introduces a new YamlViewer component using react-syntax-highlighter to display syntax-highlighted YAML configurations across several dashboard management pages, including jobs, podgroups, pods, and queues. Feedback on the changes points out potential SSR import errors and hydration mismatches in Next.js (App Router) when using react-syntax-highlighter directly. It is recommended to use CommonJS imports and implement a client-side mounting check to prevent these issues.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| import { Light as SyntaxHighlighter } from 'react-syntax-highlighter'; | ||
| import yamlLang from 'react-syntax-highlighter/dist/esm/languages/hljs/yaml'; | ||
| import { vs2015 } from 'react-syntax-highlighter/dist/esm/styles/hljs'; | ||
|
|
||
| SyntaxHighlighter.registerLanguage('yaml', yamlLang); | ||
|
|
||
| export function YamlViewer({ yaml }: { yaml: string | undefined }) { | ||
| if (!yaml) return null; | ||
|
|
||
| return ( | ||
| <div className="rounded-lg overflow-hidden text-sm border border-gray-800"> | ||
| <SyntaxHighlighter language="yaml" style={vs2015} customStyle={{ margin: 0, padding: '1rem', backgroundColor: '#111827' }}> | ||
| {yaml} | ||
| </SyntaxHighlighter> | ||
| </div> | ||
| ); | ||
| } |
There was a problem hiding this comment.
In Next.js (App Router), using react-syntax-highlighter directly can lead to two major issues:
- SSR Import Errors: Importing from
dist/esm/...can causeSyntaxError: Cannot use import statement outside a moduleduring server-side rendering. Using thedist/cjs/...paths resolves this compatibility issue. - Hydration Mismatches: The HTML generated by
react-syntax-highlighteron the server may differ slightly from the client-side rendering, leading to React hydration warnings/errors.
To prevent these issues, we can:
- Switch to CommonJS (
dist/cjs/...) imports. - Use a
mountedstate withuseEffectto render a simple<pre><code>block as a fallback during SSR/hydration, and swap in the syntax highlighter once mounted on the client. This avoids hydration mismatches and prevents layout shifts.
import { useEffect, useState } from 'react';
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
import yamlLang from 'react-syntax-highlighter/dist/cjs/languages/hljs/yaml';
import { vs2015 } from 'react-syntax-highlighter/dist/cjs/styles/hljs';
SyntaxHighlighter.registerLanguage('yaml', yamlLang);
export function YamlViewer({ yaml }: { yaml: string | undefined }) {
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
if (!yaml) return null;
if (!mounted) {
return (
<div className="rounded-lg overflow-hidden text-sm border border-gray-800 bg-[#111827] p-4">
<pre className="whitespace-pre overflow-x-auto text-gray-300">
<code>{yaml}</code>
</pre>
</div>
);
}
return (
<div className="rounded-lg overflow-hidden text-sm border border-gray-800">
<SyntaxHighlighter language="yaml" style={vs2015} customStyle={{ margin: 0, padding: '1rem', backgroundColor: '#111827' }}>
{yaml}
</SyntaxHighlighter>
</div>
);
}
Summary
This PR improves the YAML viewing experience across the dashboard by adding syntax highlighting for resource manifests.
Changes
YamlViewercomponent.<pre><code>blocks in:react-syntax-highlighterlight build with only the YAML language registered.Verification
Motivation
The previous implementation displayed YAML as plain text, making larger manifests harder to read. Syntax highlighting improves readability while reducing duplicated rendering code through a reusable component.
Closes #292