Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Clear channel composer instantly and show optimistic kickoff in feed - #3350

Merged
trunk-io[bot] merged 1 commit into
mainfrom
posthog-code/channel-composer-instant-clear
Jul 14, 2026
Merged

Clear channel composer instantly and show optimistic kickoff in feed#3350
trunk-io[bot] merged 1 commit into
mainfrom
posthog-code/channel-composer-instant-clear

Conversation

@raquelmsmith

Copy link
Copy Markdown
Member

Problem

In a Bluebird channel, submitting a task had a visible lag: the composer only cleared and the card only appeared after the task-creation round trip (and its feed invalidate/refetch) resolved. Because the input still showed the typed prompt, it looked like the keystroke hadn't registered, so people pressed enter twice.

Why: Raquel reported hitting enter twice because the input didn't clear and the message didn't show up in the channel messages immediately — the ask was to clear the input right away, surface the message in the feed instantly, and show a loading state while the task actually "takes" rather than leaving text sitting in the box.

Changes

  • The channel composer now clears the instant a submit is accepted, snapshotting the editor content and passing it to handleSubmit as an override so clearing early can't race the content read.
  • An optimistic "Starting…" kickoff row (the user's message + a spinner card) is posted to the feed immediately, then swapped for the real card once the task is created.
  • On creation, the real task is spliced straight into the feed cache instead of waiting on the invalidate refetch/poll.
  • On failure, the optimistic row is pulled and the prompt is handed back to the composer so the user can retry.

Scoped to the channel feed surface (WebsiteChannelHome / ChannelHomeComposer / ChannelFeedView).

How did you test this?

  • pnpm --filter @posthog/ui typecheck — passes.
  • biome check on the changed files — passes.
  • Not yet exercised in the running app; please pull down and try submitting in a channel.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

@trunk-io

trunk-io Bot commented Jul 10, 2026

Copy link
Copy Markdown

😎 Merged directly without going through the merge queue, as the queue was empty and the PR was up to date with the target branch - details.

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 66321bf.

@raquelmsmith
raquelmsmith marked this pull request as ready for review July 10, 2026 19:56
@raquelmsmith raquelmsmith added the Stamphog This will request an autostamp by stamphog on small changes label Jul 10, 2026
@raquelmsmith

Copy link
Copy Markdown
Member Author

tested locally, it works

@greptile-apps

greptile-apps Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "Scroll the channel feed to the bottom on..." | Re-trigger Greptile

// optimistic card and give the prompt back so the user can retry.
onPendingEnd(id);
pendingIdRef.current = null;
editor.setContent(prompt);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Structured Prompt Content Is Lost

When task creation fails after a prompt with mention or file chips, this restores only the flattened contentToPlainText string. The retry prompt keeps the visible @label text but loses the chip ids and metadata, so the next submit no longer sends the same structured references.

Comment on lines +146 to +148
if (pendingIdRef.current) {
onPendingEnd(pendingIdRef.current);
pendingIdRef.current = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Shared Pending Id Races

A rapid overlapping submit can overwrite the single pendingIdRef before the first task finishes. When the first create callback runs, it removes the newer optimistic row instead of its own, leaving the earlier Starting… row stuck in the feed.

Comment on lines +111 to +114
queryClient.setQueryData<Task[]>(
channelFeedQueryKey(backendChannel?.id),
(old) => insertTaskDedup(old, task) ?? old,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Empty Feed Cache Drops Task

When the channel feed query has not populated yet, old is undefined and insertTaskDedup(old, task) also returns undefined. The pending row is removed on success, but the real task is not inserted into the cache, so the feed falls back to waiting for the refetch instead of showing the created card immediately.

github-actions[bot]
github-actions Bot previously approved these changes Jul 10, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean optimistic UI addition in the UI layer only — no data model, API contract, or infra changes. Key correctness invariants verified: handleSubmit returns Promise<boolean> (failure check is sound), insertTaskDedup handles undefined cache correctly, and error path restores editor content.

@github-actions
github-actions Bot dismissed their stale review July 10, 2026 20:09

New commits pushed (delta classified non_trivial_delta) — stamphog approval dismissed; re-review running automatically.

github-actions[bot]
github-actions Bot previously approved these changes Jul 10, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purely additive optimistic-UI change in the feed layer — no API contracts, data models, or infra touched. All three bot comments are addressed in the current diff: the empty-cache case uses a ternary guard before calling insertTaskDedup, failure recovery restores the full structured content object, and the pending-ID tracking uses a FIFO array rather than a single ref.

raquelmsmith added a commit that referenced this pull request Jul 13, 2026
…croll (rebased on main)

Resolved version of PR #3350 rebased onto current main. Reconciles the
optimistic-clear / pending-kickoff / self-post-scroll feature with main's
newly-added canvas-mode generation in the channel composer (both now coexist),
and drops two prompt/origin helper functions that main's feed presentation
superseded.

Squashed single commit so it can be force-applied onto the PR branch:
  git push --force origin posthog-code/channel-composer-instant-clear-merged:posthog-code/channel-composer-instant-clear

Generated-By: PostHog Code
Task-Id: 20f9fe72-9b7b-44bb-9fde-75f94be4b6ee
@raquelmsmith
raquelmsmith force-pushed the posthog-code/channel-composer-instant-clear branch from 5d19790 to 687ec71 Compare July 13, 2026 19:53
@github-actions
github-actions Bot dismissed their stale review July 13, 2026 19:53

New commits pushed (delta classified non_linear_history) — stamphog approval dismissed; re-review running automatically.

github-actions[bot]
github-actions Bot previously approved these changes Jul 13, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean optimistic-UI addition; all three bot concerns (content loss on failure, pending-ID race, empty-cache drop) are demonstrably addressed in the current diff. No data models, API contracts, or infra touched.

@raquelmsmith
raquelmsmith enabled auto-merge (squash) July 13, 2026 20:09
@raquelmsmith
raquelmsmith disabled auto-merge July 13, 2026 20:47

Copy link
Copy Markdown
Member Author

/trunk merge

1 similar comment

Copy link
Copy Markdown
Member Author

/trunk merge

…croll (rebased on main)

Re-resolved version of PR #3350 on top of current main. Reconciles the
optimistic-clear / pending-kickoff / self-post-scroll feature with main's newly
added Slack-style channel intro + system feed messages: the feed now interleaves
tasks and system rows by timestamp (main) while still appending optimistic
"Starting…" pending rows and following the user's own posts to the bottom
(this PR). WebsiteChannelHome keeps both the pending state and main's
context.md onboarding dialog.

Single squashed commit so it can be force-applied onto the PR branch.

Generated-By: PostHog Code
Task-Id: 20f9fe72-9b7b-44bb-9fde-75f94be4b6ee
@raquelmsmith
raquelmsmith force-pushed the posthog-code/channel-composer-instant-clear branch from 687ec71 to 66321bf Compare July 14, 2026 17:36
@github-actions
github-actions Bot dismissed their stale review July 14, 2026 17:36

New commits pushed (delta classified non_linear_history) — stamphog approval dismissed; re-review running automatically.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three previously flagged bot concerns are addressed in the current diff: empty-cache seeding uses a ternary guard, failure recovery restores the full structured content snapshot, and pending IDs use a FIFO array. No data models, API contracts, or infra are touched.

@trunk-io
trunk-io Bot merged commit 309e0e6 into main Jul 14, 2026
27 checks passed
@trunk-io
trunk-io Bot deleted the posthog-code/channel-composer-instant-clear branch July 14, 2026 17:46

Copy link
Copy Markdown
Member Author

/trunk merge

@trunk-io

trunk-io Bot commented Jul 14, 2026

Copy link
Copy Markdown

An error occurred while submitting your PR to the queue: This PR is already merged

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant