Skip to content

fix(chat): keep composer drafts across hydration - #8892

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/composer-hydration-drafts
Oct 10, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
fix/composer-hydration-drafts

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Composer adopts text typed into the server-rendered textarea before hydration. React dropped those input events, so state stayed empty and the next render wiped the text. This is what made e2e (mobile) intermittently fail draft scroll boundaries on WebKit (The long draft must have a scrollable editor / The draft must overflow its editor): the fill landed before the composer hydrated and the draft disappeared
  • A saved draft is restored after hydration instead of in the initial render. Reading localStorage during hydration mismatched the server HTML, so every reload with a saved new-chat draft raised a hydration error and regenerated the composer
  • One shared useHydrated hook replaces three private copies (composer, organization home, landing theme toggle)
  • Mobile E2E: the draft scroll check waits for the draft to overflow its editor instead of measuring once, and a new check saves a draft, reloads, and requires it back with no hydration error

Type of Change

  • Bug fix

Testing

  • use-prompt-editor.test.tsx: new jsdom test hydrates server HTML with text typed before hydration (red before the fix)
  • Mobile E2E (WebKit desktop) against next dev: 20 consecutive runs, 0 failed checks; before the fix 7/20 failed with the reload hydration error. The new reload check fails on the pre-fix composer. Full suite (Chromium + WebKit, all viewports) 186/186
  • bun run lint, bun run type-check, bun run check:audits, bun run test, block registry check

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

- Adopt text typed into the server-rendered composer before hydration; the dropped input event left state empty and the next render wiped the text
- Restore a saved draft after hydration instead of in the initial render, which mismatched the server HTML and regenerated the composer on every reload with a draft
- Share one useHydrated hook across the composer, organization home, and theme toggle
- Mobile E2E: wait for the draft to overflow its editor instead of measuring once, and check a saved draft returns after a reload without a hydration error
@vercel

vercel Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 10, 2026 2:56pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues remain.

Summary

The composer keeps text entered before hydration and restores saved drafts without changing the server’s first render.

  • Text typed before hydration stays in the composer.
  • Saved drafts return after hydration without replacing new typing.
  • The composer, organization home, and theme toggle share one hydration check.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Hydrate composer] --> B{Text entered before hydration?}
  B -->|Yes| C[Keep entered text and caret]
  B -->|No| D[Restore saved draft as a seed]
  D --> E[Restore skill references when skills load]
Loading

Reviews (3) · Last reviewed commit: "fix(chat): keep the caret where the user..." · Reviewed by Greptile

Comment thread apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

All reported issues were addressed across 7 files

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 4815ce9 into staging Oct 10, 2026
48 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/composer-hydration-drafts branch October 10, 2026 19:36

This branch was previously deployed

1 inactive deployment
Preview — b2194926 Deployed Oct 10, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant