Skip to content

Commit 76d8571

Browse files
authored
🐛 Escape generic type params in MDX to fix /x/worker/ page (#1142)
JSDoc comments containing generic type references like `Result<T>` were being interpreted as JSX tags by MDX, causing the worker extension page to fail with a parse error. Escape uppercase-starting angle bracket patterns to HTML entities before MDX processing.
1 parent 08f35c0 commit 76d8571

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

www/hooks/use-markdown.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ export function* useMarkdown(
4949
);
5050
let sanitized = yield* sanitize(markdown);
5151

52+
// Escape generic type parameters like <T>, <TSend, TRecv> that MDX
53+
// would interpret as JSX tags. Only matches uppercase-starting identifiers
54+
// inside angle brackets to avoid escaping actual HTML tags.
55+
sanitized = sanitized.replace(
56+
/<([A-Z]\w*(?:\s*,\s*[A-Z]\w*)*)>/g,
57+
"&lt;$1&gt;",
58+
);
59+
5260
let mod = yield* useMDX(sanitized, {
5361
remarkPlugins: [remarkGfm, ...(options?.remarkPlugins ?? [])],
5462
rehypePlugins: [

0 commit comments

Comments
 (0)