Skip to content

fix(CodeBlock): handle ReactNode children with angle-bracket placeholders#950

Open
mneedham wants to merge 5 commits intoClickHouse:mainfrom
mneedham:fix/codeblock-react-node-children
Open

fix(CodeBlock): handle ReactNode children with angle-bracket placeholders#950
mneedham wants to merge 5 commits intoClickHouse:mainfrom
mneedham:fix/codeblock-react-node-children

Conversation

@mneedham
Copy link
Collaborator

Summary

  • Changed children prop type from string to ReactNode in CodeBlock.types.ts
  • Added nodeToString() helper that recursively converts ReactNode to a plain string, reconstructing <tag> syntax for React element nodes
  • All internal uses of children as a string now go through nodeToString(children)

Problem

When code content contains <placeholder> style text (e.g. shell scripts with <project_id>, <email>), JSX parses those as React elements rather than raw text. SyntaxHighlighter then receives objects instead of a string and renders [object Object] throughout the block.

Test plan

  • Pass a code block with <placeholder> style content and verify it renders literally
  • Verify $VARIABLE style content still renders as-is
  • Verify copy button copies the correct plain-text string
  • Verify existing SQL/bash/JSON syntax highlighting still works

🤖 Generated with Claude Code

…ders

JSX parses <placeholder> style content as React elements, causing
SyntaxHighlighter to receive objects instead of strings and render
[object Object]. Accept ReactNode children and stringify them,
reconstructing <tag> syntax for element nodes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Mar 25, 2026

⚠️ No Changeset found

Latest commit: 636031e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Collaborator

@punkbit punkbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mneedham thanks for your contribution, mind add the missing changeset? Check https://github.com/clickHouse/click-ui?tab=readme-ov-file#add-a-new-changeset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants