-
Notifications
You must be signed in to change notification settings - Fork 4k
[fix] tooltip text leaking with newlines in help #13365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Escape newlines in help text before embedding in :help[] directive to prevent text from rendering outside tooltip box. Fixes #13339
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
SummaryThis PR fixes a bug (gh-13339) where tooltip text containing newlines ( Solution implemented:
Code QualityThe implementation is clean, minimal, and well-targeted: Markdown.tsx (lines 79-82): const escapedHelp = help ? help.replace(/\n/g, "\\n") : ""
const source = help ? `${body} :help[${escapedHelp}]` : bodyStreamlitMarkdown.tsx (lines 463-466): const tooltipContent =
typeof children === "string" ? children.replace(/\\n/g, "\n") : ""✅ Comments clearly explain the workaround for text directive limitations Test CoverageE2E Tests (✅ Well covered)The PR adds comprehensive E2E tests following best practices from
Frontend Unit Tests (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Replace \\n escape with __STREAMLIT_NEWLINE__ sentinel to avoid corrupting user text containing literal \n sequences. Add frontend unit tests for: - Tooltip with newlines (verifies no text leaking) - Tooltip with literal backslash-n (verifies no conversion)
📉 Frontend coverage change detectedThe frontend unit test (vitest) coverage has decreased by 0.0000%
✅ Coverage change is within normal range. |
|
@cursor review |
- Escape ] brackets to prevent premature directive closure - Replace sentinel to avoid markdown special chars (__ for bold) - Use unicode brackets 〔〕 which have no markdown/HTML meaning - Add tests for brackets and spaces around newlines
Replace character escaping approach with cleaner context-based solution: - Use :help[] as marker (empty label) - Pass help text via React context to CustomHelpIcon - No escaping needed - all markdown features work naturally Add comprehensive tests for complex markdown in tooltips: - Code, links, bold, italic, colors, brackets, emojis - Snapshot test to verify formatting
Keep children prop for developers who manually use :help[content] directive in their markdown. Context is preferred (from help parameter) but falls back to children for flexibility. Document text directive limitations in JSDoc.
SummaryThis PR fixes issue gh-13339 where tooltip text containing newlines ( Solution: Instead of embedding the help text directly in the directive ( Code QualityThe code changes are well-structured and follow existing patterns in the codebase: Strengths
Minor Observations
Test CoverageThe test coverage is excellent and comprehensive: Unit Tests (
|
Remove check for 'st.markdown()' which isn't in the help text. Add check for 'italic' which is actually present. Ensures negative assertions catch real text leaking.
Verify that help="" doesn't render a tooltip icon to ensure no unexpected rendering occurs.
## Describe your changes Fixes tooltip rendering when help text contains newlines (`\n\n`). Previously, the `:help[]` text directive would break, causing help text to render in the markdown/caption content instead of inside the tooltip. **Solution:** - Pass help text via react context instead of in the directive. - Preserves inline tooltip rendering which is necessary for text alignment to work correctly ## GitHub Issue Link (if applicable) Fixes #13339 ## Testing Plan - [x] E2E Tests **E2E tests:** - `e2e_playwright/st_markdown.py` - Test app with tooltips containing newlines - `e2e_playwright/st_markdown_test.py` - Parameterized tests covering: - `st.markdown` with newlines in default alignment - `st.caption` with newlines - `st.markdown` with center alignment + newlines (verifies design decision) - Negative assertions to ensure text doesn't leak into element content --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Describe your changes
Fixes tooltip rendering when help text contains newlines (
\n\n). Previously, the:help[]text directive would break, causing help text to render in the markdown/caption content instead of inside the tooltip.Solution:
GitHub Issue Link (if applicable)
Fixes #13339
Testing Plan
E2E tests:
e2e_playwright/st_markdown.py- Test app with tooltips containing newlinese2e_playwright/st_markdown_test.py- Parameterized tests covering:st.markdownwith newlines in default alignmentst.captionwith newlinesst.markdownwith center alignment + newlines (verifies design decision)Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.