Skip to content

Commit 80afd4d

Browse files
fix(kumo): correct return types for ShikiProvider and CodeHighlighted (#244)
* fix(kumo): correct return types for ShikiProvider and CodeHighlighted - Change return type from ReactNode to React.JSX.Element for JSX compatibility - Fixes TypeScript errors when consuming components in stricter tsconfig environments - Add CodeHighlighted to docs search, exclude deprecated Code/CodeBlock * chore: add changeset
1 parent 0ad2d7f commit 80afd4d

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@cloudflare/kumo": patch
3+
---
4+
5+
Fix TypeScript return types for ShikiProvider and CodeHighlighted components.
6+
7+
Changed return type from `ReactNode` to `React.JSX.Element` to resolve JSX compatibility errors. This fixes issues when consuming these components in projects with stricter TypeScript configurations (e.g., `skipLibCheck: false`), where `ReactNode` was incorrectly inferred as a valid JSX element return type.

packages/kumo-docs-astro/src/components/SearchDialog.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
* 3. Add its description to COMPONENT_DESCRIPTIONS below
2020
*/
2121
const COMPONENTS_WITHOUT_DOCS = new Set([
22+
"Code", // Deprecated: use CodeHighlighted from @cloudflare/kumo/code
23+
"CodeBlock", // Deprecated: use CodeHighlighted from @cloudflare/kumo/code
2224
"DateRangePicker", // Deprecated: use DatePicker with mode="range"
2325
"Field",
2426
"Icon",
@@ -31,6 +33,7 @@ const COMPONENTS_WITHOUT_DOCS = new Set([
3133
* Only needed when the name doesn't match the standard kebab-case conversion.
3234
*/
3335
const SLUG_OVERRIDES: Record<string, string> = {
36+
CodeHighlighted: "code-highlighted",
3437
DropdownMenu: "dropdown",
3538
};
3639

@@ -43,6 +46,7 @@ const STATIC_PAGES: Array<{
4346
description: string;
4447
url: string;
4548
category: string;
49+
type?: "component" | "block" | "layout" | "page";
4650
}> = [
4751
{
4852
name: "Installation",
@@ -100,6 +104,13 @@ const STATIC_PAGES: Array<{
100104
url: "/registry",
101105
category: "Guides",
102106
},
107+
{
108+
name: "CodeHighlighted",
109+
description: "Syntax-highlighted code blocks powered by Shiki.",
110+
url: "/components/code-highlighted",
111+
category: "Components",
112+
type: "component",
113+
},
103114
];
104115

105116
/** Better descriptions from the Astro doc pages */
@@ -332,7 +343,7 @@ export function SearchDialog({ open, onOpenChange }: SearchDialogProps) {
332343
// Always include static pages
333344
const staticItems: SearchItem[] = STATIC_PAGES.map((page) => ({
334345
name: page.name,
335-
type: "page" as const,
346+
type: page.type ?? "page",
336347
description: page.description,
337348
category: page.category,
338349
url: page.url,

packages/kumo/src/code/code-highlighted.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useState, useCallback, useMemo, type ReactNode } from "react";
3+
import React, { useState, useCallback, useMemo } from "react";
44
import { cn } from "../utils/cn";
55
import { Button } from "../components/button";
66
import { useShikiHighlighter } from "./use-shiki-highlighter";
@@ -39,7 +39,7 @@ export function CodeHighlighted({
3939
showCopyButton = false,
4040
labels: labelOverrides,
4141
className,
42-
}: CodeHighlightedProps): ReactNode {
42+
}: CodeHighlightedProps): React.JSX.Element {
4343
const {
4444
highlight,
4545
isLoading,

packages/kumo/src/code/provider.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useState, useEffect, useMemo, type ReactNode } from "react";
3+
import React, { useState, useEffect, useMemo } from "react";
44
import { ShikiContext, type ShikiContextValue } from "./context";
55
import type { ShikiProviderProps, SupportedLanguage } from "./types";
66

@@ -65,7 +65,7 @@ export function ShikiProvider({
6565
languages,
6666
labels,
6767
children,
68-
}: ShikiProviderProps): ReactNode {
68+
}: ShikiProviderProps): React.JSX.Element {
6969
const [state, setState] = useState<{
7070
highlighter: ShikiContextValue["highlighter"];
7171
isLoading: boolean;
@@ -111,7 +111,7 @@ export function ShikiProvider({
111111

112112
const highlighter = await createHighlighterCore({
113113
themes: [githubLight.default, vesper.default],
114-
114+
115115
langs: langModules.map((m) => m.default) as any,
116116
engine: engineInstance,
117117
});

0 commit comments

Comments
 (0)