-
Notifications
You must be signed in to change notification settings - Fork 4k
Reduce entry bundle size - Part 2 #13077
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
✅ 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!
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
📉 Significant wheel size change detectedThe wheel file size has decreased by 0.49% (threshold: 0.25%)
Please verify that this change is expected. |
📈 Frontend coverage change detectedThe frontend unit test (vitest) coverage has increased by 0.0300%
🎉 Great job on improving test coverage! |
240700f to
1765e9f
Compare
c74645b to
d38f456
Compare
📉 Significant bundle size change detected
Please verify that this change is expected. |
f21f5cd to
dd86849
Compare
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.
Pull request overview
This PR reduces the entry bundle size by ~1.6MB (from 5.11MB to 3.51MB) through lazy loading of syntax highlighting dependencies and creating lighter alternatives for error dialogs. The key optimization is deferring the loading of react-syntax-highlighter, refractor, and highlight.js until they're actually needed.
Key Changes:
- Lazy loaded
StreamlitSyntaxHighlighterinStreamlitMarkdownwith Suspense fallback - Created
StreamlitErrorCodeBlockas a minimal alternative without syntax highlighting - Created
DialogErrorMessagecomponent that parses markdown links and plain URLs without full markdown rendering - Refactored error handling to use
ErrorDetailstype with separatemessageandcodeBlockfields
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
frontend/lib/src/index.ts |
Updated export from StreamlitSyntaxHighlighter to StreamlitErrorCodeBlock |
frontend/lib/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.tsx |
Implemented lazy loading for StreamlitSyntaxHighlighter with Suspense and Skeleton fallback |
frontend/lib/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.test.tsx |
Updated tests to handle async lazy loading with findBy queries |
frontend/lib/src/components/shared/StreamlitMarkdown/Heading.test.tsx |
Updated tests to wait for lazy-loaded content |
frontend/lib/src/components/elements/CodeBlock/StreamlitErrorCodeBlock.tsx |
New minimal code block component without syntax highlighting for error displays |
frontend/lib/src/components/elements/CodeBlock/StreamlitErrorCodeBlock.test.tsx |
Comprehensive test coverage for the new error code block component |
frontend/connection/src/types.ts |
Added ErrorDetails interface to structure error messages with optional code blocks |
frontend/connection/src/WebsocketConnection.tsx |
Updated to use ErrorDetails instead of plain string error messages |
frontend/connection/src/WebsocketConnection.test.tsx |
Updated all tests to use new ErrorDetails structure |
frontend/connection/src/StaticConnection.tsx |
Updated error handling to use ErrorDetails |
frontend/connection/src/DoInitPings.tsx |
Refactored error messages to separate human-readable text from code blocks |
frontend/connection/src/ConnectionManager.ts |
Updated connection error handling to use ErrorDetails |
frontend/app/src/components/StreamlitDialog/styled-components.ts |
Added StyledErrorText component with conditional spacing |
frontend/app/src/components/StreamlitDialog/StreamlitDialog.tsx |
Replaced StreamlitSyntaxHighlighter with StreamlitErrorCodeBlock in compile error dialog |
frontend/app/src/components/StreamlitDialog/DialogErrorMessage.tsx |
New component for rendering error messages with link parsing, without full markdown |
frontend/app/src/components/StreamlitDialog/DialogErrorMessage.test.tsx |
Comprehensive test coverage for link parsing and error display |
frontend/app/src/App.tsx |
Updated error handling to use ErrorDetails and DialogErrorMessage |
frontend/app/src/App.test.tsx |
Updated all tests to use new ErrorDetails structure |
frontend/app/src/components/StreamlitDialog/DialogErrorMessage.tsx
Outdated
Show resolved
Hide resolved
frontend/app/src/components/StreamlitDialog/DialogErrorMessage.tsx
Outdated
Show resolved
Hide resolved
1468883 to
9458342
Compare
dd86849 to
a1e1e47
Compare
| * Parse message text and convert markdown links [text](url) and plain URLs | ||
| * into clickable anchor tags. | ||
| */ | ||
| function parseLinks(text: string): ReactNode[] { |
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.
question: do you have an example case where we render markdown links via the dialog? E.g. do we actually need to support any type of advanced rendering here?
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.
We use the link markdown here for retryWhenIsForbidden for CORS documentation, and the ForwardMessageCache errors also use [report this bug](url) so thought it made sense to support this pattern
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.
ok, I think it might be good to generate some dedicated parameterized unit test cases for parseLinks as well.
lukasmasuch
left a comment
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.
LGTM 👍
| * Parse message text and convert markdown links [text](url) and plain URLs | ||
| * into clickable anchor tags. | ||
| */ | ||
| function parseLinks(text: string): ReactNode[] { |
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.
ok, I think it might be good to generate some dedicated parameterized unit test cases for parseLinks as well.
501dccb to
2623e74
Compare

Describe your changes
Attempt to improve initial load time by reducing dependencies included in entry bundle.
StreamlitSyntaxHighlighterinStreamlitMarkdownStreamlitSyntaxHighlighterwith more minimalStreamlitErrorCodeBlockinScriptCompileErrorDialogStreamlitMarkdownin Warning/Connection error dialogs with newDialogErrorMessageBefore:



After:



Dependencies removed from entry:
highlight.js/librefractorreact-syntax-highlighterreact-syntax-highlighteris a syntax highlighting lib which usesrefractor&highlight.js.Bundle Analysis:
Before (left): 5.11 MB & After (right): 3.51 MB
