Skip to content

Fix empty Markdown code blocks rendering as “undefined”#13074

Merged
sfc-gh-bnisco merged 15 commits intostreamlit:developfrom
ashm-dev:fix/md
Nov 21, 2025
Merged

Fix empty Markdown code blocks rendering as “undefined”#13074
sfc-gh-bnisco merged 15 commits intostreamlit:developfrom
ashm-dev:fix/md

Conversation

@ashm-dev
Copy link
Copy Markdown
Contributor

Fixes #12986

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Nov 20, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@sfc-gh-bnisco sfc-gh-bnisco added feature:markdown Related to Markdown rendering change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Nov 20, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where empty Markdown code blocks render as "undefined" instead of being empty. The fix processes the children prop to filter out "undefined" strings and handle null/empty values properly.

Key changes:

  • Made the children prop optional in the component interface
  • Added preprocessing logic to handle various children states (array, null, string, "undefined")
  • Simplified the copy button conditional rendering to use the processed text

Comment thread frontend/lib/src/components/elements/CodeBlock/StreamlitSyntaxHighlighter.tsx Outdated
Comment thread frontend/lib/src/components/elements/CodeBlock/StreamlitSyntaxHighlighter.tsx Outdated
@sfc-gh-bnisco sfc-gh-bnisco self-assigned this Nov 20, 2025
Comment thread frontend/lib/src/components/elements/CodeBlock/StreamlitSyntaxHighlighter.tsx Outdated
@ashm-dev
Copy link
Copy Markdown
Contributor Author

@sfc-gh-bnisco I'm not very good at front-end development. Could you review my PR?

Copy link
Copy Markdown
Collaborator

@sfc-gh-bnisco sfc-gh-bnisco left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution and iterations @ashm-dev! I made some updates and added tests.

Copy link
Copy Markdown
Contributor

@sfc-gh-nbellante sfc-gh-nbellante left a comment

Choose a reason for hiding this comment

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

Only 1 q, other than that LGTM 👍

@sfc-gh-bnisco sfc-gh-bnisco merged commit e902ded into streamlit:develop Nov 21, 2025
38 checks passed
@ashm-dev ashm-dev deleted the fix/md branch November 21, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation feature:markdown Related to Markdown rendering impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown rendering empty triple-backtick code fence adds the string "undefined"

4 participants