---
title: "Recipe: a chat thread"
description: "A transcript open at its newest message, over Messages' composer."
modificationDate: "2026-11-30"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: a chat thread

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/chat-thread: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

A transcript at its newest message over a composer.

```prompt Add a chat thread
Add a chat thread to the Exact app in this folder: a transcript that opens at its newest message, over a composer like Messages'. Use https://github.com/expo/exact/blob/main/docs/recipes/chat-thread.md as the source for each step. The Exact checkout has the same page at docs/recipes/chat-thread.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. If I did not say where the messages come from and who is in the thread, propose it from the app and ask me before you write code. Use the recipe's local `loadThread` and `sendMessage` sources in app.ts until I give you a server.
3. In app.contract, add a `resource` for the thread, a `mutation` for a sent message that `refreshes` the thread `then` scrolls to the end, and a `draft` state. Draw the transcript as a `list` with `virtualized=true`, `scroll-start="end"`, `scrollFollowEnd=true` and `keyboardDismissMode="interactive"`, so a drag that reaches the keyboard pulls it down as in Messages, and give each message `overflow-wrap="anywhere"`.
4. Draw the composer below it: a `textarea` with `field-sizing="content"` and a Send button that is disabled while the draft is empty or a send is pending, with `retainFocus=true`. Give the screen `interactive-widget="resizes-content"`, so the composer stays over the keyboard.
5. Post trims the draft, sends it, clears it and keeps focus in the composer.
6. Add a test in app.test.contract that types a message, taps Send, runs `clock data`, and expects the composer to be empty and the message in the transcript.
7. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 8) and report it; do not keep trying.
8. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
9. Tell me where the thread is and where its messages come from, what the tests and verify reported, and the launch command for each target platform.
```

```contract
routes nav
  home "/"

shape Message
  id: string
  body: string
  mine: bool

shape Reply
  error: string

component Chat
  state draft = ""
  resource thread = loadThread() as shape Message[] else empty()
  mutation sent as shape Reply refreshes thread then toEnd
  derive lastId = match thread.at(-1) { case some(m) => m.id, case none => "" }
  action edit(v: string)
    draft = v
  action post
    if draft.trim() != "" and not pending(sent)
      send sent = sendMessage(draft.trim())
      draft = ""
    focus("composer")
  action toEnd
    scrollIntoView("transcript", lastId, block="end")
  view
    main navigationKey=`${top(nav).id}` interactive-widget="resizes-content" width="100%" height="100%"
      for e in stack(nav) key=e.id
        column navigationKey=`${e.id}` navigationScroll="transcript" position="absolute" inset=0
          header
            h2 "Ada"
          list id="transcript" appearance="none" virtualized=true scroll-start="end" scrollFollowEnd=true flex=1 min-height=0 keyboardDismissMode="interactive"
            for m in thread key=m.id
              row justify-content=(m.mine ? "flex-end" : "flex-start") padding="3px 12px"
                text m.body padding="8px 12px" border-radius=18 max-width="75%" white-space="pre-wrap" overflow-wrap="break-word"
                  background-color=(m.mine ? "AccentColor" : "-exact-fill") color=(m.mine ? "AccentColorText" : "-exact-label")
                  testId=`message-${m.id}`
          row align-items="flex-end" margin="6px 12px" padding="0 4px 0 12px" border-radius=20
            border="1px solid -exact-separator"
            textarea id="composer" value=draft input=edit rows=1 field-sizing="content" max-height=140
              placeholder="Message" aria-label="Message" testId="composer" flex=1 min-width=0 padding="12px 0"
              border="none" background-color="transparent"
            button press=post disabled=(draft.trim() == "" or pending(sent)) buttonStyle="filled" margin="4px 0"
              retainFocus=true aria-label="Send" testId="send"
              image "symbol:send"
```

```ts
import type { Answer, Result, Sources } from './app.contract.d.ts';

export const grants = '';

const messages: Result<'loadThread'> = [];
const sources: Sources = {
  loadThread: () => messages,
  sendMessage: ([body]) => (messages.push({ id: String(messages.length + 1), body, mine: true }), { error: '' }),
};
export const answer: Answer = (source, args, store, storage, native) => sources[source](args, store, storage, native);
```

```contract-test
test "a send lands"
  type "composer" "Yes, at noon"
  tap "send"
  clock data
  expect text "composer" == ""
  expect text "message-1" == "Yes, at noon"
```

- `interactive-widget` keeps the composer on the keys; Send keeps them up.
- `scrollFollowEnd` keeps the newest message in view for a reader at the end. [Paging](https://exact.expo.dev/recipes/long-lists.md).
- `pre-wrap` keeps line breaks; `break-word` wraps URLs. Name group senders.
