Warning: In HTML, <div> cannot be a descendant of <p>.
This will cause a hydration error.
The Badge component renders a <div> element, but it was being used inside a <p> tag in the FunctionGraphViewer component. This is invalid HTML because block-level elements (<div>) cannot be nested inside inline elements (<p>).
<p>
<strong>Change Type:</strong>
<Badge> <!-- This renders as <div> -->
modified
</Badge>
</p>This causes React hydration errors because:
- The browser automatically closes the
<p>tag when it encounters the<div> - React's virtual DOM expects the structure to match the server-rendered HTML
- The mismatch causes a hydration error
File: nextjs-frontend/src/components/graph/FunctionGraphViewer.tsx
Line: 603-607
Changed the <p> tag to a <div> tag for the line containing the Badge component.
<div className="space-y-1 text-sm">
<p><strong>Name:</strong> {selectedNode.name}</p>
<p><strong>Type:</strong> {selectedNode.type}</p>
<p><strong>File:</strong> {selectedNode.filePath}</p>
<p><strong>Change Type:</strong>
<Badge className={`ml-2 ${getNodeColor(selectedNode.changeType)}`}>
{selectedNode.changeType}
</Badge>
</p>
<p><strong>Similarity:</strong> {(selectedNode.similarity * 100).toFixed(1)}%</p>
</div><div className="space-y-1 text-sm">
<p><strong>Name:</strong> {selectedNode.name}</p>
<p><strong>Type:</strong> {selectedNode.type}</p>
<p><strong>File:</strong> {selectedNode.filePath}</p>
<div><strong>Change Type:</strong>
<Badge className={`ml-2 ${getNodeColor(selectedNode.changeType)}`}>
{selectedNode.changeType}
</Badge>
</div>
<p><strong>Similarity:</strong> {(selectedNode.similarity * 100).toFixed(1)}%</p>
</div><div>is a block-level element that can contain other block-level elements- The Badge component (which renders as
<div>) can now be properly nested - The visual appearance remains the same (both
<p>and<div>are block elements) - React hydration now succeeds because the HTML structure is valid
None - The change is purely structural. The <div> and <p> tags both:
- Display as block elements
- Have the same default spacing (controlled by the parent's
space-y-1class) - Render identically in the browser
- Change Badge to render
<span>- Would work, but Badge is semantically a container and<div>is more appropriate - Use
<span>wrapper - Adds unnecessary nesting - Change all
<p>to<div>- Overkill; only the one with Badge needed changing
To verify the fix:
- Open the application - No hydration error in console
- Click on a graph node - Modal opens with function details
- Check "Change Type" field - Badge displays correctly
- Inspect console - No React warnings or errors
<p>can only contain phrasing content (inline elements like<span>,<strong>,<em>)<p>cannot contain flow content (block elements like<div>,<section>,<article>)<div>can contain both phrasing and flow content
- Server-side rendering generates HTML
- Client-side React must match that HTML exactly
- Invalid HTML causes browser to "fix" it, creating mismatches
- Mismatches trigger hydration errors
To avoid similar issues in the future:
- Never nest Badge in
<p>tags - Badge renders as<div> - Use
<div>for complex content - If you need to nest components, use<div> - Use
<p>only for simple text - Keep paragraphs for actual paragraph content - Check component implementations - Know what HTML your components render
nextjs-frontend/src/components/graph/FunctionGraphViewer.tsx(line 603)
✅ Fixed - Hydration error resolved, no visual changes, valid HTML structure