# Message Component

Chat messages for Rails: bubbles, avatars, grouped messages, reply quotes, attachments, reactions, delivery status, typing indicators, AI assistant replies and a complete conversation thread. Static layouts are plain HTML and Tailwind CSS. One dependency-free Stimulus controller adds the interactive parts: a WhatsApp-style actions menu, reactions, replies, a composer and a thread that works with Turbo Streams. Free component.

## Features

- Incoming and outgoing bubbles whose tail corner points at the sender; grouped messages square their inner corners and keep the tail and avatar on the last bubble (`Message::Component.position_in_group`)
- Avatars with an initials fallback, author line, time, and sending / delivered / read / failed states with a retry action
- Reply quotes inside the bubble with a straight accent bar, linking back to the original message
- Attachments inside the bubble (images, file cards, link previews) and rich HTML content
- Actions menu: hover toolbar on desktop, press and hold on touch screens (with haptics on Android), Shift+F10 or the context menu key on keyboards. On desktop the menu is a light popover: the emoji row appears above the bubble and the actions below it, the page keeps scrolling and the menu follows its message. On touch screens the pressed bubble is lifted above a dimmed page, like WhatsApp and iMessage
- Reactions: quick emoji row, pills that count, toggle and disappear at zero
- Reply, Copy and your own actions (edit, delete, pin…) through events
- Bubble variants: `:solid`, `:muted`, `:tinted`, `:outline`, `:ghost` (no bubble, for AI replies) and `:destructive`
- Thread that never moves the reader against their intent: follows new and streamed messages only while you are at the bottom and not selecting text or using the keyboard, keeps your place when older messages, images or code blocks change the layout (Safari included), anchors new AI turns near the top, opens at the unread marker, and shows a jump button with a "New messages" state
- Keeps the typing indicator last and animates messages appended by Turbo Streams
- `data-slot` styling hooks on every part, plus `data-direction`, `data-position` and `data-variant` on the row
- Composer: grows as you type, Enter to send (a new line on touch keyboards), Escape to cancel a reply, optimistic append or a normal form submit to Rails
- Events for everything (`message:react`, `message:reply`, `message:sent`, `message:received`…) so you can persist to your server
- Screen reader labels for each sender, `role="log"` thread, `aria-pressed` reactions, focus restored after the menu closes
- Reduced-motion aware, dark mode, works in all evergreen browsers (the menu uses the Popover API: Safari 17+, Firefox 125+, Chrome 114+)

## Implementation Options

| Option | Best for | Files |
|--------|----------|-------|
| ViewComponent | Ruby API: corners, avatar gutter, labels and data attributes worked out for you | `app/components/message/` |
| Shared partial | Apps without ViewComponent: the same options and markup as locals | `app/views/shared/components/message/` |
| Plain ERB | Full markup control; copy one of the showcase examples | `app/views/components/message/` |

Static messages need no JavaScript. Actions, reactions, toggles and threads need `app/javascript/controllers/message_controller.js`.

## Installation

1. Copy `message_controller.js` to `app/javascript/controllers/`. With importmap and `eagerLoadControllersFrom` / `pin_all_from` it registers itself as `message`.
2. For the ViewComponent, copy `app/components/message/` (needs the `view_component` gem, 4.x).
3. For the partials, copy `app/views/shared/components/message/`.
4. Tailwind CSS v4.1+ (uses the `pointer-coarse:` variant).
5. Optional: the AI assistant example copies with the [clipboard controller](/docs/clipboard) and its `data-clipboard-source-value` option.

## ViewComponent

### Basic Usage

```erb
<div class="flex flex-col gap-0.5">
  <% @messages.each_with_index do |message, index| %>
    <%= render Message::Component.new(
      id: message.id,
      direction: message.user == current_user ? :outgoing : :incoming,
      position: Message::Component.position_in_group(@messages, index, &:user_id),
      author: message.user.name,
      avatar: message.user.avatar_url,
      text: message.body,
      time: message.created_at) %>
  <% end %>
</div>
```

Put messages in a `flex flex-col gap-0.5` container: grouped messages sit close together and each new sender adds its own top margin.

### Interactive Messages

```erb
<div data-controller="message" class="flex flex-col gap-0.5">
  <%= render Message::Component.new(id: 41, author: "Olivia Martin", text: "Keep the free plan?",
        reactions: [{ emoji: "👍", count: 3, pressed: true }], actions: true) %>

  <%= render Message::Component.new(id: 42, direction: :outgoing, text: "Keep it.",
        reply_to: { id: 41, author: "Olivia Martin", text: "Keep the free plan?" },
        status: :delivered, actions: %i[react menu]) %>

  <%# Once per controller: the menu and the template for new reaction pills %>
  <%= render Message::Component::MenuComponent.new(actions: [:reply, :copy, { name: "delete", label: "Delete", destructive: true }]) %>
</div>
```

### Attachments and Rich Content

```erb
<%= render Message::Component.new(direction: :outgoing, text: "Cover photo for the brochure") do |message| %>
  <% message.with_attachment do %>
    <img src="…" alt="…" width="640" height="480" class="aspect-[4/3] w-full object-cover">
  <% end %>
<% end %>

<%= render Message::Component.new(author: "Priya Shah") do %>
  The refund is <strong>approved</strong>.
<% end %>
```

### Component Options

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `text` | String | `nil` | Plain text, escaped, line breaks kept. Use a block instead for rich HTML |
| `direction` | Symbol | `:incoming` | `:incoming` (start side) or `:outgoing` (end side, the current user) |
| `tail` | Symbol | `:corner` | `:corner` (tightened corner), `:curved` (iMessage-style hook on the last bubble), `:wedge` (pointed tail with a rounded tip on the last bubble) or `:none`. Outline bubbles fall back to `:corner`, ghost bubbles have none |
| `variant` | Symbol | by direction | `:solid` (outgoing default), `:muted` (incoming default), `:tinted`, `:outline`, `:ghost` (no bubble, full width, actions always visible underneath) or `:destructive` |
| `position` | Symbol | `:single` | `:single`, `:first`, `:middle` or `:last` in a run from the same sender |
| `id` | String/Integer | `nil` | Sets `id="message-<id>"` and `data-message-id` (passed to every event) |
| `author` | String | `nil` | Sender name. Shown above incoming `:single` / `:first` messages, read by screen readers, used by Reply |
| `avatar` | String | `nil` | Avatar URL. With `avatar` or `initials` the row keeps an avatar gutter; the image shows on `:single` / `:last` |
| `initials` | String | from `author` | Fallback when there is no image |
| `show_author` | Boolean | auto | Force the author line on or off |
| `time` | Time/String | `nil` | In the author line, or in the footer next to the status |
| `status` | Symbol | `nil` | `:sending`, `:delivered`, `:read` or `:failed` (Try again dispatches `message:action` with `name: "retry"`) |
| `reply_to` | Hash | `nil` | `{ author:, text:, id: }` (links to `#message-<id>`) or `{ author:, text:, href: }` |
| `reactions` | Array | `[]` | `[{ emoji: "👍", count: 3, pressed: true, label: "…" }]` |
| `actions` | Boolean/Array | `false` | Hover toolbar and press-and-hold menu. `true` = `[:react, :reply]`; also `:menu` (More button) |
| `anchor` | Boolean | `false` | When appended to a thread, scroll this message near the top (the prompt that starts an AI turn) |
| `classes` | String | `nil` | Extra classes for the row |
| `bubble_classes` | String | `nil` | Extra classes for the bubble |
| `html` | Hash | `{}` | Extra attributes for the row |

`Message::Component.position_in_group(messages, index) { |m| m.user_id }` returns the position from the sender of the neighbouring messages.

### MenuComponent

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `reactions` | Array/false | 👍 ❤️ 😂 😮 🙏 | `[["🔥", "Fire"], …]` emoji and accessible label pairs. `false` hides the emoji row, e.g. for AI replies |
| `actions` | Array | `[:reply, :copy]` | `:reply`, `:copy`, or `{ name:, label:, destructive: }` for `message:action` |
| `label` | String | `"Message actions"` | Accessible name of the menu |

### TypingComponent

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `name` | String | `nil` | Read by screen readers: "Olivia is typing" |
| `avatar` | String | `nil` | Avatar next to the bubble |
| `gutter` | Boolean | `false` | Empty avatar-width gutter to line up with messages that have avatars |
| `hidden` | Boolean | `false` | Start hidden; use inside a thread with `showTyping()` / `hideTyping()` |

## Shared Partial

Same options and markup as the ViewComponent. Rich content and attachments are passed as HTML from `capture`:

```erb
<div data-controller="message" class="flex flex-col gap-0.5">
  <%= render "shared/components/message/message",
    id: 41, author: "Olivia Martin", text: "Keep the free plan?",
    reactions: [{ emoji: "👍", count: 3, pressed: true }], actions: true %>

  <% photo = capture do %><img src="…" alt="…" class="w-full"><% end %>
  <%= render "shared/components/message/message", direction: :outgoing, text: "Cover photo", attachment: photo %>

  <%= render "shared/components/message/message_menu", actions: [:reply, :copy] %>
</div>

<%= render "shared/components/message/message_typing", name: "Olivia", hidden: true %>
```

Locals: the ViewComponent options, plus `body:` (HTML used when `text` is blank) and `attachment:` (HTML). Invalid values raise `ArgumentError`.

## Plain ERB

The showcase examples in `app/views/components/message/` are self-contained. A minimal pair:

```erb
<div class="flex justify-start">
  <p class="max-w-[80%] rounded-2xl rounded-bl-md bg-neutral-100 px-3.5 py-2 text-sm text-neutral-900 dark:bg-neutral-800 dark:text-neutral-100">Morning!</p>
</div>
<div class="flex justify-end">
  <p class="max-w-[80%] rounded-2xl rounded-br-md bg-neutral-900 px-3.5 py-2 text-sm text-white dark:bg-white dark:text-neutral-900">Hi!</p>
</div>
```

Corner rule: the corner on the sender's side is `-md`. Single and first bubbles square the bottom corner (`rounded-bl-md` / `rounded-br-md`), middle and last bubbles square both (`rounded-l-md` / `rounded-r-md`), so the tail always ends up on the last bubble, next to the avatar.

## Stimulus Controller

### Markup Conventions

| Attribute | On | Description |
|-----------|----|-------------|
| `data-message-target="item"` | Message row | One message. Add `data-message-id` and `data-message-author` for events and replies |
| `data-message-outgoing` | Message row | Sent by the current user: aligns the menu, always scrolls into view, doesn't clear the typing indicator |
| `data-message-anchor` | Message row | When appended, scrolls near the top with a peek of the previous message; the reply grows below it |
| `data-message-start` | Any row in the list | The thread opens here (unread marker, last user message) instead of at the bottom |
| `data-message-target="bubble"` | Bubble | Press and hold opens the menu. Add `pointer-coarse:select-none pointer-coarse:[-webkit-touch-callout:none]` |
| `data-message-slot="text"` | Inside the bubble | The text Copy and Reply use |
| `data-message-slot="status"` | Footer | Removed from older messages when a new one is sent |

### Values

| Value | Type | Default | Description |
|-------|------|---------|-------------|
| `optimistic` | Boolean | `true` | `true` appends the sent message in the browser. `false` lets the form submit to Rails and clears the composer on a successful Turbo submit |
| `sendOnTouchEnter` | Boolean | `false` | Enter sends on touch keyboards too (by default it inserts a new line there) |
| `longPressDelay` | Number | `450` | Milliseconds to press and hold a bubble |
| `stickThreshold` | Number | `96` | Pixels from the bottom that still count as "at the bottom" |
| `anchorPeek` | Number | `48` | Pixels of the previous message kept in view above an anchored turn or the start row |
| `maxInputHeight` | Number | `144` | Pixels the composer grows to before it scrolls |
| `copiedLabel` | String | `"Message copied"` | Announced to screen readers after Copy |

### Targets

| Target | Description |
|--------|-------------|
| `list` | Scrollable thread. Messages added to it by any means (Turbo Streams included) are animated and followed |
| `jump` | Hidden button shown while away from the bottom; gets `data-unread` when messages arrive meanwhile. `data-action="message#jumpToBottom"` |
| `typing` | Hidden typing indicator, kept as the last child of the list |
| `item`, `bubble` | A message row and its bubble |
| `reactions` | Pill container of a message. Add `data-message-hide-when-empty` |
| `reactionTemplate` | `<template>` for a new pill. Slots: `emoji`, `count` |
| `menu`, `menuPanel`, `menuPreview` | The shared `popover="auto"` element, its positioned panel, and where the pressed bubble is lifted (or a spacer the size of the bubble in "menu" mode) |
| `input`, `submit` | Composer textarea and send button |
| `outgoingTemplate` | `<template>` for a sent message. Slots: `text`, `time`, `status`, `quote` (`quote-author`, `quote-text`) |
| `replyPreview`, `replyInput` | "Replying to" bar (slots `reply-author`, `reply-text`) and the hidden field for the replied message id |

### Actions

| Action | Description |
|--------|-------------|
| `message#openReactions` | Toolbar button: the emoji row above the bubble. Clicking it again closes it |
| `message#openMenu` | Toolbar button: reactions above the bubble, actions below it. Clicking it again closes it |
| `message#react` | Adds, increments or removes a reaction. `data-message-emoji-param="👍"` |
| `message#reply` | Fills the reply preview and focuses the composer |
| `message#cancelReply` | Clears the reply |
| `message#copy` | Copies the message text |
| `message#act` | Custom action: `data-message-name-param="delete"` |
| `message#toggle` | Flips `aria-pressed`; buttons sharing `data-message-group` are exclusive. Optional `data-message-value` |
| `message#send` | On the form's `submit` event |
| `message#composerKeydown` | On the textarea's `keydown` event: Enter, Shift+Enter, Escape |
| `message#resize` | On the textarea's `input` event |
| `message#jumpToBottom` | Scrolls to the newest message |
| `message#expand` | Show more / show less: point `aria-controls` at the text; toggles `aria-expanded` and `data-expanded` (style with `line-clamp-6 data-expanded:line-clamp-none`) |

Public methods for outlets or Action Cable: `showTyping()`, `hideTyping()`, `scrollToBottom()`, `anchorTo(element)`, `append(template, text)`, `openMenu(item, mode)` (mode: `"reactions"`, `"menu"` or `"full"`), `closeMenu()`.

### Events

| Event | Detail | When |
|-------|--------|------|
| `message:react` | `emoji, pressed, count, id, element` | A reaction was added, toggled or removed |
| `message:reply` | `id, author, text, href, element` | Reply was chosen. Cancelable: `preventDefault()` to handle it yourself |
| `message:copy` | `text, id, element` | Text was copied |
| `message:action` | `name, id, element` | A custom menu action or Try again (`name: "retry"`) |
| `message:toggle` | `pressed, group, value, id, element` | A toggle button changed |
| `message:sent` | `text, element, replyTo` | The composer sent a message (optimistic mode) |
| `message:received` | `element, id` | A message from someone else was appended to the list |

### Keyboard and Touch

| Input | Result |
|-------|--------|
| Hover a message | Shows the toolbar (desktop) |
| Press and hold a bubble | Opens the menu (touch). Moving more than 10px cancels, so scrolling is unaffected |
| Tab to a toolbar button | Shows the toolbar |
| Shift+F10 / context menu key | Opens the menu of the focused message |
| Arrow keys, Home, End | Move between menu buttons |
| Escape | Closes the menu; in the composer, cancels a reply |
| Enter / Shift+Enter | Send / new line (new line on touch keyboards) |

## Turbo Streams

Render the composer as a real form, turn off the optimistic append, and broadcast new messages to the list:

```erb
<%# app/views/conversations/show.html.erb %>
<%= turbo_stream_from @conversation %>
<section data-controller="message" data-message-optimistic-value="false">
  <div id="messages" data-message-target="list" role="log" aria-label="Messages" tabindex="0" class="flex flex-1 flex-col gap-0.5 overflow-y-auto">
    <%= render @conversation.messages %>
    <%= render Message::Component::TypingComponent.new(name: @other_user.first_name, hidden: true) %>
  </div>
  <%= form_with model: [@conversation, Message.new], data: { action: "submit->message#send" } do |form| %>
    <%= form.hidden_field :reply_to_id, data: { message_target: "replyInput" } %>
    <%= form.text_area :body, rows: 1, data: { message_target: "input", action: "input->message#resize keydown->message#composerKeydown" } %>
    <button type="submit" data-message-target="submit">Send</button>
  <% end %>
  <%= render Message::Component::MenuComponent.new %>
</section>
```

```ruby
# app/models/message.rb
after_create_commit -> { broadcast_append_to conversation, target: "messages" }
```

The controller keeps the typing indicator last, animates the new message, scrolls only if the reader is at the bottom (or shows the jump button), and clears the composer once the submit succeeds. Mark the current user's messages with `direction: :outgoing` in the partial (`message.user == Current.user`).

## Scroll Behavior

The thread never moves the reader against their intent:

- It follows new messages, and replies that grow while streaming, only while the reader is at the bottom and is not selecting text or moving through the thread with the keyboard.
- Otherwise it keeps the message being read in place when anything changes above or inside the view (older messages prepended, images, code blocks, re-rendered rows). It sets `overflow-anchor: none` on the list and does this itself, so Safari behaves like Chrome and Firefox.
- A row appended with `data-message-anchor` (`anchor: true`) scrolls near the top, keeping `anchorPeek` pixels of the previous message; the reply grows into the screen below it. Temporary bottom padding gives the anchor room until the reply fills the view.
- The thread opens at a row with `data-message-start`, otherwise at the bottom.
- The jump button shows whenever the reader is away from the bottom, with `data-unread` when messages arrived meanwhile.

Stream AI replies by replacing the reply's row (`broadcast_replace_to`, or `turbo_stream.replace`): replacements are never animated and only followed while the reader is at the bottom.

## Styling Hooks

Every part has a `data-slot`; the row also has `data-direction`, `data-position` and `data-variant`. Restyle from the outside without copying the component:

```erb
<div class="**:data-[slot=message-bubble]:rounded-3xl **:data-[direction=outgoing]:**:data-[slot=message-bubble]:bg-red-600">
  …messages…
</div>
```

| `data-slot` | Part |
|-------------|------|
| `message` | Row (`data-direction`, `data-position`, `data-variant`, `data-tail`) |
| `message-header` | Author and time |
| `message-avatar` | Avatar image or initials |
| `message-content` | Bubble wrapper with the toolbar |
| `message-bubble` | Bubble surface |
| `message-quote` | Reply quote |
| `message-attachment` | Attachment |
| `message-text` | Text |
| `message-tail` | SVG tail (curved and wedge styles) |
| `message-actions` | Toolbar, or the action row of ghost messages |
| `message-reactions` | Reaction pills |
| `message-footer` | Status and time |

Reaction pills have a `ring-3 ring-white dark:ring-neutral-900` cut-out; change the ring to the color behind your thread.

## Saving Reactions and Actions

```js
document.addEventListener("message:react", ({ detail }) => {
  fetch(`/messages/${detail.id}/reactions`, {
    method: detail.pressed ? "POST" : "DELETE",
    headers: { "Content-Type": "application/json", "X-CSRF-Token": document.querySelector("meta[name=csrf-token]").content },
    body: JSON.stringify({ emoji: detail.emoji }),
  });
});

document.addEventListener("message:action", ({ detail }) => {
  if (detail.name === "delete") detail.element.remove(); // then DELETE /messages/:id
});
```

## Accessibility

- Every bubble has a visually hidden sender label ("Olivia Martin:", "You:") and avatars use `alt=""`, so names are read once.
- The thread is `role="log"`; the typing indicator is `role="status"`; reactions use `aria-pressed`.
- The menu is a `popover="auto"` element with `role="dialog"`: focus moves to the first reaction, arrow keys move between buttons, Escape or a click outside closes it, and after Escape or an action focus returns to the button that opened it.
- On touch screens the toolbar is visually hidden but stays in the accessibility tree, so screen reader users reach React and Reply by swiping.
- All animations stop under `prefers-reduced-motion`.

## Browser Support

Evergreen browsers. The menu uses the Popover API (Safari 17+, Firefox 125+, Chrome 114+). Haptics (`navigator.vibrate`) only run on Android; iOS ignores them. Copy needs a secure context (https or localhost).

## Troubleshooting

- **Press and hold selects text on iOS**: add `pointer-coarse:select-none pointer-coarse:[-webkit-touch-callout:none]` to the bubble (the ViewComponent does it when `actions` is set).
- **The menu does nothing**: render one `MenuComponent` (or the `message_menu` partial) inside the same `data-controller="message"` element.
- **The page won't scroll while the pointer is over the thread**: remove `overscroll-contain` from the list. In Chrome it stops wheel scrolling from reaching the page even when the list has nothing to scroll. Add it only when the thread fills the whole screen.
- **New reactions don't appear**: the menu renders the `reactionTemplate`; each message needs a `reactions` container (rendered when `actions` or `reactions` are set).
- **Streamed messages appear below the typing indicator**: the indicator needs `data-message-target="typing"` and must live inside the list.
- **Turbo-streamed own messages clear the typing indicator**: add `data-message-outgoing` (`direction: :outgoing`).

---

## AI Instructions

### Choose An Implementation

- **ViewComponent**: Default when the app has `view_component`. Corners, avatar gutter, labels and controller attributes are computed from `direction`, `position` and `actions`.
- **Shared partial**: Use when the app has no ViewComponent. Same options; pass rich content as `body:` and attachments as `attachment:` from `capture`.
- **Plain ERB**: Use for markup neither covers; copy the closest file from `app/views/components/message/`.

### Quick Reference

- **Vanilla examples**: `app/views/components/message/`
- **Shared partial files**: `app/views/shared/components/message/`
- **Shared partials**: `render "shared/components/message/message", text:, direction:, …`, `"shared/components/message/message_menu"`, `"shared/components/message/message_typing"`
- **ViewComponent**: `render Message::Component.new(text:, direction:, position:, author:, avatar:, actions:)`
- **Menu**: `render Message::Component::MenuComponent.new` (once per controller)
- **Typing**: `render Message::Component::TypingComponent.new(name:, hidden: true)`
- **ViewComponent files**: `app/components/message/`
- **Stimulus controller**: `app/javascript/controllers/message_controller.js` (identifier `message`)

### Implementation Checklist

- Wrap messages in `flex flex-col gap-0.5`; compute `position` with `Message::Component.position_in_group` so tails and avatars land on the last bubble of each run.
- Use `direction: :outgoing` for the current user's messages, `:incoming` for everyone else.
- Pass `id` for every persisted message so events, replies and quote links work.
- For interactive messages, put `data-controller="message"` on the thread (or list) and render exactly one `MenuComponent` inside it.
- For threads: the list gets `data-message-target="list"`, `role="log"`, `aria-label`, `tabindex="0"`, an `id` for Turbo Streams, and the typing indicator as its last child.
- For a Rails backend, set `data-message-optimistic-value="false"`, use `form_with`, and broadcast with `broadcast_append_to … target: "messages"`.
- Persist reactions, toggles and custom actions from the `message:*` events.
- Keep the textarea at `text-base sm:text-sm` so iOS doesn't zoom on focus.

### Common Patterns

- Support inbox / DM: avatars on incoming messages, statuses on the last outgoing one.
- Group chat: `author` on every incoming message, `position_in_group` keyed by user id, typing text "Marcus and Priya are typing…".
- AI chat: `variant: :ghost` for assistant replies, `anchor: true` on the user's prompt, stream the reply with `broadcast_replace_to`, status lines with the Marker component (`role="status"`), `message#toggle` thumbs with `data-message-group="feedback"`, copy with the clipboard controller's `data-clipboard-source-value`.
- Comment thread: `reply_to` quotes, `actions: [:reply]`.
- Long messages: clamp the text and add a `message#expand` button (example 13).
- Attachments: scrolling photo rows (focusable, labelled `role="group"`), uploads with `role="progressbar"`, failures that state the reason, and cards whose title link covers the card while actions stay clickable (example 14).
- Suggested replies and notification bubbles: render them as real `<button>` / `<a>` elements (example 12).
- Tail styles: corner, curved, wedge or none (example 16). Curved and wedge tails are SVGs filled with the bubble color via `text-*`.
- Messaging details: time and read receipt inside the bubble, edited, deleted, emoji-only and link previews (example 17).
- The actions menu never locks or dims the page on desktop: it follows its message while the page or thread scrolls and closes once the message leaves the view. Only press and hold on touch screens dims the page, and that overlay closes on scroll.

### Common Mistakes

- Do not hand-pick corner classes per message; use `position` (or the corner rule) so tails point at the sender.
- Do not mix tail styles in one app; pick one `tail:` and pass it everywhere (a small helper or a default in your partial).
- Do not override bubble colors with `bubble_classes` when a `variant` fits; for app-wide restyling use the `data-slot` hooks.
- Do not scroll the thread yourself after streaming updates; the controller follows or holds position based on what the reader is doing.
- Do not render a menu per message; one per controller.
- Do not put `border-l` on a rounded quote; use the straight absolute bar inside an `overflow-hidden` quote.
- Do not show hover-only actions without the press-and-hold menu; touch users can't hover.
- Do not call `scrollToBottom()` after every Turbo append; the controller already follows new messages only when the reader is at the bottom.
- Do not use `p` for rich message bodies with block elements; pass a block (rendered in a `div`).
- Do not invent options (`side:`, `variant:`, `tail:`); unknown values raise `ArgumentError`.
- Do not duplicate long text in `data-clipboard-text`; point `data-clipboard-source-value` at the element.