Tree shaking - #893
Conversation
|
Preview: https://chatbot-pr-chatbot-893.surge.sh A11y report: https://chatbot-pr-chatbot-893-a11y.surge.sh |
885fb52 to
b1c8118
Compare
Shrunk barrel import size by excluding modals that use Code Editor. Added sideEffects so tree-shaking works a little better as well. Markdown processing is now lazy-loaded. i modified: packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/BotMessage.tsx
b1c8118 to
83582fe
Compare
|
|
||
| ## Migration: root barrel changes | ||
|
|
||
| The following modules are **not** re-exported from the root barrel (`@patternfly/chatbot`). They were removed so Monaco and internal utilities stay out of default bundles. Update existing root imports to subpath entry points: |
There was a problem hiding this comment.
this warrants a breaking change release, major version bump
943c155 to
346c0db
Compare
|
Good work, LGTM! |
nicolethoen
left a comment
There was a problem hiding this comment.
I think this looks good to me. And I don't see a problem with releasing this as a major version bump. It'd just have to be communicated clearly to @dlabaj.
We can also write up release highlights emphasizing how much this new version of chatbot improves bundle sizes. We have other packages (like react-charts) which are on a different major version than PF core pkgs.
32dddb0 to
62101c3
Compare
|
I'm backing out the tree-shaking utility since I don't want to maintain it long-term, but leaving it in a separate commit so we can always grab it again if needed. |
|
🎉 This PR is included in version 6.8.0-prerelease.9 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR adds some scenarios to check our tree shaking. We don't have to merge them. They are all in one folder so they're easy to remove.
There are two similar scenarios that check different import styles on Toggle, and one for a basic ChatBot with an input bar and message. I did not add any scenarios for conversation history, etc. or other more complex layouts.
Toggle does pull in a couple of weird icons, but those are due to the way PatternFly exports the Button component.
We seem to be tree-shaking fine for dynamic imports.
I hadn't realized previously that the way we have the Message component, etc. set up make them so huge.
Pulling in Message pulls in DeepThinking, MarkdownContent, Message, ResponseActions, SourcesCard, SourcesCardBase, ToolCall, ToolResponse, etc. This PR adds some lazy loading on Markdown so it's only loaded if Markdown is being used, but we'd have to rework Messages if we wanted to further reduce the size.
MessageBar has similar problems in that we import everything upfront and then compose the component.
A better approach if we need smaller bundle sizes in future would be to create more lightweight "next" versions that require the user to compose (and therefore import) only what they need rather than relying on a logic-heavy Message component.
For example:
This is out of scope for now.
To make barrel imports smaller, we made the Markdown processing lazy-loaded so only markdown users need the heavy dependencies. After talking to Joachim, we also moved some larger components out. These can still be imported with dynamic imports.
Fixes #878.