[feat] Complete incomplete markdown syntax during streaming#13939
[feat] Complete incomplete markdown syntax during streaming#13939lukasmasuch merged 9 commits intodevelopfrom
Conversation
|
| Status | Scan Engine | Total (0) | ||||
|---|---|---|---|---|---|---|
| Open Source Security | 0 | 0 | 0 | 0 | See details | |
| Licenses | 0 | 0 | 0 | 0 | See details |
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.
✅ PR preview is ready!
|
There was a problem hiding this comment.
Pull request overview
This PR integrates the remend package to automatically complete incomplete markdown syntax during streaming operations via st.write_stream. This improves the visual appearance by showing properly styled text instead of raw markdown characters while content is being streamed character-by-character.
Changes:
- Added
remendnpm package (v1.2.0) dependency for markdown syntax completion - Integrated
remendinStreamlitMarkdowncomponent to auto-close unclosed markdown (bold, italic, code blocks, etc.) during rendering - Added comprehensive unit tests for remend integration covering both positive cases (completion) and negative cases (when NOT to apply)
- Added E2E tests to verify the feature works end-to-end with actual streaming
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/yarn.lock | Added yarn lock entries for the new [email protected] dependency |
| frontend/lib/package.json | Added remend package dependency |
| frontend/lib/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.tsx | Integrated remend to complete incomplete markdown syntax, skipping for labels and HTML content; updated useMemo dependencies |
| frontend/lib/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.test.tsx | Added comprehensive unit tests for remend integration including positive and negative test cases |
| e2e_playwright/st_write_stream.py | Added test cases for streaming incomplete bold and code block markdown |
| e2e_playwright/st_write_stream_test.py | Added E2E tests to verify incomplete markdown is properly styled during streaming |
| NOTICES | Added Apache 2.0 license notice for the remend package from Vercel |
✅ Bundle size change is within normal range
|
## Describe your changes Automated snapshot updates for #13939 created via the snapshot autofix CI workflow. This workflow was triggered by adding the `update-snapshots` label to a PR after Playwright E2E tests failed with snapshot mismatches. **Updated snapshots:** 12 file(s)⚠️ **Please review the snapshot changes carefully** - they could mask visual bugs if accepted blindly. This PR targets a feature branch and can be merged without review approval. Co-authored-by: Streamlit Bot <[email protected]>
Integrates the remend package to automatically close unclosed markdown syntax (e.g., **bold, *italic, `code, ```code blocks) while content is being streamed via st.write_stream. This improves the visual appearance during streaming by showing properly styled text instead of raw markdown syntax characters.
- Pass generator directly to write_stream instead of wrapping in lambda (lambda returns a generator but is not itself a generator function) - Add negative assertions to verify raw markdown syntax is not visible
Underscores in identifiers (like Python repr strings `<bound method Foo._bar>`) were incorrectly being treated as incomplete italic markdown and getting extra underscores appended. This caused the st_components_v1 E2E test to fail. Disabled italic completion in remend (both `*` and `_` styles) to prevent this issue. Bold (`**`) completion still works for streaming scenarios.
Automated snapshot updates for #13939 created via the snapshot autofix CI workflow. This workflow was triggered by adding the `update-snapshots` label to a PR after Playwright E2E tests failed with snapshot mismatches. **Updated snapshots:** 12 file(s)⚠️ **Please review the snapshot changes carefully** - they could mask visual bugs if accepted blindly. This PR targets a feature branch and can be merged without review approval. Co-authored-by: Streamlit Bot <[email protected]>
…pport - Add internal `_markdown` method to avoid code duplication in markdown handling - Add `unterminated_parsing` proto field to control remend markdown completion - Update `write_stream` to use `_markdown` with `unterminated_parsing=True` during streaming - Update frontend to conditionally apply remend only when `unterminatedParsing=true` - Remove E2E tests for incomplete markdown (cannot reliably capture mid-stream state) - Add Python and frontend unit tests for `_markdown` with `unterminated_parsing` parameter Co-Authored-By: Claude Opus 4.6 <[email protected]>
69fc289 to
0a53b93
Compare
|
❌ Orphaned Snapshots Detected This PR contains orphaned e2e snapshots that are no longer used by tests. Orphaned snapshots by test: These are the snapshots I found that appear to be orphaned: "st_write_stream-incomplete_bold[chromium].png",
"st_write_stream-incomplete_bold[firefox].png",
"st_write_stream-incomplete_bold[webkit].png",
"st_write_stream-incomplete_code_block[chromium].png",
"st_write_stream-incomplete_code_block[firefox].png",
"st_write_stream-incomplete_code_block[webkit].png",To fix this:
This helps keep our snapshot directory clean and our tests maintainable. |
- Delete orphaned st_write_stream snapshots (incomplete_bold, incomplete_code_block) that no longer correspond to existing tests - Revert st_table-10/21 snapshot changes that were accidentally included from a previous snapshot autofix run but are unrelated to this PR Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
@cursor review |
SummaryThis PR adds automatic completion of incomplete markdown syntax during Key changes:
Code QualityAll three reviewers agreed: the code is clean, well-structured, and follows Streamlit's established patterns. Specific strengths noted across reviews:
No code quality issues identified by any reviewer. Test CoveragePython unit tests (
Frontend unit tests (
E2E tests: No new E2E tests added. All reviewers agreed this is reasonable since mid-stream state cannot be reliably tested end-to-end. Minor gap (noted by 2 of 3 reviewers): The existing Backwards CompatibilityAll three reviewers agreed: no breaking changes.
Security & RiskAll three reviewers agreed: low risk, no security concerns.
One reviewer ( External test recommendation
AccessibilityAll three reviewers agreed: no accessibility concerns. The changes only affect intermediate visual representation during streaming. One reviewer ( Recommendations
Reviewer Consensus
All three reviewers unanimously approved with no blocking issues. The only recommendations are minor, non-blocking test hardening and optimization suggestions. Missing ReviewsAll expected models completed their reviews:
VerdictAPPROVED: All three reviewers unanimously approved. The feature is well-implemented, follows Streamlit patterns, is backward-compatible, adequately tested, and introduces no security, accessibility, or regression risks. The only recommendations are non-blocking minor test improvements. This is a consolidated AI review by 📋 Review by `gemini-3.1-pro`SummaryThis PR introduces support for completing incomplete markdown syntax (like Code QualityThe code changes are well-structured and clean. The extraction of the internal Test Coverage
Backwards CompatibilityThe changes are fully backwards compatible. The public Security & RiskNo significant security or regression risks identified. The External test recommendation
AccessibilityNo accessibility concerns. The changes only affect the intermediate visual representation of markdown during streaming, which improves the user experience by reducing raw syntax flicker. RecommendationsNo specific recommendations for improvement. The implementation is solid and well-tested. VerdictAPPROVED: The changes are well-implemented, safely scoped to streaming contexts, and adequately tested. This is an automated AI review by 📋 Review by `gpt-5.3-codex-high`SummaryThis PR adds streaming-specific markdown completion for unterminated syntax (via Code QualityThe implementation is clean and well-scoped:
No merge-blocking code quality issues found. Test CoverageCoverage is generally good for the new behavior:
Minor gap:
Backwards CompatibilityBackwards compatibility looks good:
Security & RiskNo high-risk security concerns identified in this diff:
Risk note:
External test recommendation
AccessibilityNo accessibility regressions identified:
Recommendations
VerdictAPPROVED: The feature is well-implemented, backward-compatible, and adequately tested for its primary behavior, with only minor non-blocking test hardening opportunities. This is an automated AI review by 📋 Review by `opus-4.6-thinking`SummaryThis PR adds automatic completion of incomplete markdown syntax during Key changes:
Code QualityThe code is well-structured and follows Streamlit's established patterns:
No issues found with code quality. Test CoveragePython unit tests (
Frontend unit tests (
E2E tests: No new E2E tests were added. The PR description notes that mid-stream state can't be reliably tested in E2E. The existing Minor observation: The existing Overall, the test coverage is adequate for the scope of the changes. Backwards CompatibilityNo breaking changes:
Security & RiskLow risk. The changes are purely a rendering enhancement:
External test recommendation
AccessibilityNo accessibility impact. The changes affect only the text content passed to the existing markdown renderer during streaming. No new interactive elements, ARIA attributes, or focus management changes are introduced. The rendered markdown structure remains the same — Recommendations
VerdictAPPROVED: Clean, well-structured feature that improves streaming UX by completing incomplete markdown syntax. The implementation follows Streamlit patterns, test coverage is adequate, and there are no security, compatibility, or accessibility concerns. This is an automated AI review by |
This reverts the italic disable that was added to work around underscore issues. Italic completion (*text*) is now enabled during streaming. Also fixes a latent test bug where the allowHTML=true test case wasn't waiting for the async plugin to load. Co-Authored-By: Claude Opus 4.6 <[email protected]>
lib/streamlit/elements/markdown.py
Outdated
| text_alignment: TextAlignment = "left", | ||
| unterminated_parsing: bool = False, | ||
| ) -> DeltaGenerator: | ||
| """Internal markdown with streaming support via unterminated_parsing.""" |
There was a problem hiding this comment.
nit: This comment doesn't seem 100% aligned to the scope of this function, since not all instances of this will use unterminated_parsing.
Address PR review comment: the docstring now accurately reflects that this is a general internal method with extended options, not specifically for streaming with unterminated_parsing. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Describe your changes
_markdownmethod withunterminated_parsingparameter for streaming supportunterminated_parsingproto field to control frontend markdown completion behaviorremendpackage to automatically close unclosed markdown syntax (e.g.,**bold,`code,```code blocks) while content is being streamed viast.write_streamwrite_streamto use_markdownwithunterminated_parsing=Trueduring streamingunterminatedParsing=trueunterminatedParsingis not setTesting Plan
_markdownwithunterminated_parsingparameterunterminatedParsingconditional behavior