From ccde0af9959c4b0bb4da3c2dbccf61650bfaad48 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Fri, 10 Apr 2026 01:07:18 +0200 Subject: [PATCH] refactor: convert MarkdownContent to server component, remove context --- components/markdown-content.tsx | 88 ++++++++++++++------------------- 1 file changed, 38 insertions(+), 50 deletions(-) diff --git a/components/markdown-content.tsx b/components/markdown-content.tsx index 260efb4..e004b17 100644 --- a/components/markdown-content.tsx +++ b/components/markdown-content.tsx @@ -1,15 +1,8 @@ -"use client"; - -import React, { createContext, useContext } from "react"; +import React from "react"; import ReactMarkdown from "react-markdown"; import type { Components } from "react-markdown"; import type { Element } from "hast"; -// Lets the `code` renderer know it's inside a `pre` block vs. inline. -// React renders parent-to-child, so the Provider in `pre` is active -// when `code` renders inside it. -const InsidePreContext = createContext(false); - function GoldDot() { return ( - {children} - - ); - } - - return ( - - {children} - - ); -} const components: Components = { h1: ({ children }) => ( @@ -286,10 +245,15 @@ const components: Components = { {children} ), - // `pre` wraps `code` for fenced code blocks. The Provider lets the - // nested `code` renderer know it's in a block context (not inline). - pre: ({ children }) => ( - + // `pre` reads code text directly from the HAST node so `code` renderer + // is only ever called for inline code — no client-side context needed. + pre: ({ node }) => { + const codeEl = node?.children?.[0] as Element | undefined; + const codeText = (codeEl?.children ?? []) + .filter((c): c is { type: "text"; value: string } => c.type === "text") + .map((c) => c.value) + .join(""); + return (
-        {children}
+        
+          {codeText}
+        
       
-
- ), + ); + }, - code: CodeRenderer, + // Always inline — block code is handled entirely by the `pre` renderer above. + code: ({ children }) => ( + + {children} + + ), }; export default function MarkdownContent({ content }: { content: string }) {