Repository navigation
feat(core): add a width prop to ChatMessageBubble so ghost bubbles align custom in-message content with the text column - #3879
Conversation
… with the bubble text column
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsChat (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. Chat - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
|
Thanks for this, and apologies for the slow response — the diagnosis here is solid and the misalignment you documented (76px vs 60px within one message) is a real bug worth fixing. Before adding a new exported subcomponent, though, I'd like to try the existing surface.
So of the three things the new component does, ghost already does two — with the same density mapping, derived from the same place. The one genuine gap is width: That points at a prop on the bubble rather than a new component. Something like One counter-argument I want to put on the record, because it's the strongest case for a separate element and the PR doesn't currently make it: a ghost bubble still emits Could you try the bubble-prop version and see how it feels at the call sites in the |
|
Correction to my comment above — ignore the Layout and container components take a So the shape I'd like on <ChatMessageBubble variant="ghost" width="100%">
<ClickableCard label="Open report" onClick={openReport}>…</ClickableCard>
</ChatMessageBubble>
Two reasons to prefer this over a boolean: it matches what a consumer already knows from every other sizing-capable component, and it isn't limited to the one case — Everything else in my comment stands: I'd rather extend the existing bubble than add |
…geBubble (meta#2574) Per review: ghost bubbles already own the text-column inset contract, so extend the bubble instead of adding a second component that mirrors its padding. width follows the Card/Center SizeValue convention (number = px, string = as-is) and replaces the max(80%, 280px) cap only when set.
|
@jiunshinn is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
|
Thanks for the thorough review — you were right on the merits, and the PR is reworked to the bubble-prop approach (58fa96d).
One honest residual of ghost-as-wrapper, for the record only: @rubyycheung heads-up — the PR changed substantially since your approval (the |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks for the update! This looks good!
Resolves the only conflict: main moved the CLI templates tree to packages/cli/assets/templates/, so this branch's new ChatMessageBubble custom-content block lands there. Its doc.mjs type import now points at @astryxdesign/cli/authoring — packages/core/src/docs-types was deleted in the same move.
ac64959 to
a0ea9cb
Compare
|
Merged Heads up @jiunshinn — I force-pushed over your merge commit Same resolution otherwise, plus one fix: Verified locally on the merged tree: |
Summary
Custom content placed inside a
ChatMessage(an artifact card, attachment chips, inline citations, a standaloneChatMessageMetadata) cannot align to the bubble's text column. Within one assistant message the left edges differ (issue repro, ai-chat template's artifact composition, 1280px viewport):The only workaround is hardcoding
marginInlineStart: --spacing-4on the custom content, which mirrors the bubble's private padding and silently breaks if that padding changes or when density changes. A second facet from the issue thread: custom children also can't opt into the full message-column width — the children wrapper aligns items to the sender side, so custom content shrinks to fit.Fixes #2574
Chosen API (updated after review):
widthprop onChatMessageBubblewidth?: SizeValuefollows the existing sizing convention (Card,Center,Button,AlertDialog, …): numbers are pixels, strings pass through, implemented as a dynamic StyleX style likeCard'sdynamicStyles.sizing.maxWidth: max(80%, 280px)cap onstyles.content; when unset, nothing changes for existing bubbles.width={420}for a fixed-width artifact bubble is equally expressible — the reason aSizeValuebeats anisFullWidthboolean.chat-message-bubble, and sincevariantis reflected in the theme props a theme can always scope rules to[data-variant="filled"]. So I'm not claiming that contract violation; the separate component isn't justified.Trying it at the ai-chat template call sites
The template's artifact message previously rendered a raw
ArtifactCardplus a standaloneChatMessageMetadata, both flush at the message edge next to inset ghost text. Reworked:It feels right at the call site: the card's left edge lands on the text column, the standalone timestamp collapses into the existing
metadataslot idiom ("metadata on the last bubble"), and the card's hardcodedmarginBlockStartworkaround style was deleted outright. The card keeps its ownmaxWidth={360}; the bubble just stops imposing the message-level cap. No bubble typography or--radius-chatleakage mattered in practice — the wrapper is transparent and non-clipping, and the card sets its own type.Change
packages/core/src/Chat/ChatMessageBubble.tsx—width?: SizeValueprop +dynamicStyles.sizing; replaces the width cap only when set.packages/core/src/Chat/ChatMessage.tsx—childrenJSDoc points at the ghost +widthidiom.ChatMessageBubble.doc.mjs/Chat.doc.mjs/ChatMessage.doc.mjs— docs, Zh, and dense variants updated to the ghost +widthguidance.apps/storybook/stories/Chat.stories.tsx—Custom Contentstory now uses a ghostwidth="100%"bubble with the metadata slot.packages/cli/templates/blocks/components/ChatMessageBubble/ChatMessageBubbleCustomContent.*— block example (replaces theChatMessageContentblock).packages/cli/templates/pages/ai-chat/page.tsx— artifact message adopts the new idiom; hardcoded margin workaround removed.ChatMessageContent(component, tests, doc, block, exports) — removed.@astryxdesign/corepatch changeset ([feat]) rewritten for thewidthprop.Test plan
Coverage moved into the existing colocated
ChatMessageBubble.test.tsx(+4 tests). StyleX emits one atomic class per declaration, so class-identity pins the alignment contract:paddingInlineclass.max(80%, 280px);width="100%"resolvesmaxWidth: noneand passes the string through;width={420}renders420px.Results: Chat suite 10 files / 131 tests green; CLI template + component doc tests 85 green;
pnpm -F @astryxdesign/core typecheckclean; core build green; CLItypecheck:template-docsclean;sync:exports --checkclean;check:changesetsvalid;astryx component ChatMessageBubble --denserenders thewidthprop and the new block. Storybook typecheck has only the pre-existing unbuilt-theme-package module errors; none inChat.stories.tsx.