MessageContent max width should respect parent's
#274
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
I have a relatively small chat container that is has a width of 420px. when a message contains a code block that has somewhat long code lines, this causes the entire chat ui to overflow horizontally, showing a scrollbar at the bottom of the chat ui to show the entire code block as shown in this video and causing a bad UX:

Fix
a message is rendered inside these components, which seems how it is supposed to be done as per the docs:
streamdown code block styling has an
overflow-x-auto, telling it to show a scrollbar when its content is causing the width to be larger than the container's. the problem is that the container in this case,MessageContent, has aw-fitclass, which dictates that the width can't be smaller than its content width (code block in this case), and larger than its parent width,Message, which since it hasflexclass, it means thatMessagechildren flex items have a defaultmax-width: auto, which scales as much as the content needs, in this case as much as code block needs. the solution is to guardMessageContentby overriding the default and specifically telling it its max width can't be more than 100% of its parent. its parent has a (now)max-w-[95%], which means it will be 95% of whatever the parent ofMessageis. in my case, it is 420px.why the
max-w-[95%]change? after my changes, messages actually started to take 80% of the width (unlike before) and it caused it to look dissimilar to how it used to look before my changes. so I think a default of 95% achieves the intended result here.with this change, the scrollbar shows inside the code block as it should be if the contents of the block overflows the parent's available width, like this:
