Repository navigation
Conversation
Pasting a large single-line payload (a minified JS bundle is the case that surfaced this) froze the composer for tens of seconds, and every keystroke afterwards stayed expensive. The work was spread across five synchronous paths, all of which scaled with the size of the whole document: - Markdown parsing rescanned the full text per delimiter candidate and per emitted run, which is quadratic on delimiter-dense input. Marker/mention lookups now use a sorted range index and monotonic sweeps. - The typeahead trigger scan rebuilt all text before the caret on every doc and selection update; it now scans a bounded window. - The controlled-value sync key JSON-stringified the whole prompt twice per keystroke; it now compares structurally, normally on pointer identity. - Draft storage serialized the full draft on every write even though the write itself was already debounced; serialization moved to the persist boundary. - Decoration rebuilds serialized the document and ran every rule over the full text per edit; above 100k positions they now map through the edit and rebuild on a throttled timer. - ThreadDetailView subscribed the whole thread view to draft state, so the timeline re-rendered per keystroke; it now uses the non-subscribing accessor it already had available. Co-authored-by: Jacob Miller <[email protected]>
Co-authored-by: Jacob Miller <[email protected]>
ThreadDetailView remains a static import in SplitThreadArea: a React.lazy boundary there made the first thread open of a session take 469 ms instead of 242 ms (the Suspense retry mounts the pane at transition priority), and prefetching the chunk recovered only ~7 ms. Document that measurement on the import so it is not re-lazied without a new measured reason. Also add the 1 MB paste before/after clip under perf-clips/ so it renders in the pull request. Co-authored-by: Jacob Miller <[email protected]>
Side-by-side recording of the first thread open on the production build: lazy thread pane (as proposed in #1) versus the static import kept by this branch. Real timescale slowed 8x; the counter freezes at each side's painted time (399 ms lazy, 126 ms static on the recording machine). Co-authored-by: Jacob Miller <[email protected]>
jjcm
marked this pull request as ready for review
August 18, 2026 21:09
## User-facing problem On iPhone, submitting a follow-up can feel like the button ignored the first tap: 1. The user taps Submit. 2. The keyboard closes and the composer shrinks. 3. The message remains unsent. 4. The user has to tap Submit again. This is especially confusing because it resembles network lag, even though the first submission never actually committed. ## What this changes The submit button now checks which DOM element the browser actually considers focused instead of relying on TipTap's event-derived focus flag. During the brief iOS focus transition where those states can disagree, bb keeps the editor and keyboard stable long enough for the first tap to produce its click. After submission commits, the existing keyboard dismissal and compact-composer behavior continue normally. The change is intentionally narrow: genuine focus outside the editor behaves as before, and desktop submission behavior is unchanged. ## Verification - Added a regression test that models stale TipTap focus while the contenteditable still owns native focus. - All 98 PromptBoxInternal tests pass. - Turbo app typecheck passes. - Prettier and git diff checks pass. > AGENT GENERATED: by GPT-5
…te-and-thread-open-perf-cf7d # Conflicts: # apps/app/src/hooks/usePromptDraftStorage.test.tsx # apps/app/src/hooks/usePromptDraftStorage.ts # apps/app/src/views/thread-detail/ThreadDetailView.tsx Co-authored-by: Jacob Miller <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Combines the product keepers from #4 and #3 into one reviewable PR. A 1 MB paste into the composer now paints in ~0.5 s instead of ~2.5 s, and the first thread open of a session stays at ~242 ms instead of regressing to ~469 ms behind a lazy boundary.
1 MB paste, before/after (mp4):
First thread open, before/after (mp4) — production build, real timescale slowed 8×, counter freezes at each side's painted time (399 ms lazy vs 126 ms static on the recording machine; medians over 5 runs were 405 ms vs 146 ms):
Changes
prompt-editor-serialization.ts): parsing a large single-line paste was superlinear; it is now linear, taking the isolated parse from 2362 ms to 11.9 ms on a 1 MB minified-JS paste. This is the headline paste win.find-active-trigger.ts): the@//trigger scan looks at the last 256 characters before the caret instead of rescanning the whole text on every keystroke.PromptBoxInternal.tsx): the controlled-value sync compares text and mention ranges structurally instead ofJSON.stringifying the entire prompt twice per keystroke.usePromptDraftStorage.ts): the localStorage draft serializes on the existing 250 ms flush, not on every keystroke.prompt-decoration-extension.ts): above 100k positions the decoration rebuild is deferred. Tradeoff: decorations can lag typing by up to ~200 ms on very large drafts.ThreadDetailView.tsx): it reads the draft only when a quote is added, so the whole thread view (timeline included) no longer re-renders on every composer keystroke.SplitThreadArea.tsx): Fix composer jank when a large minified-JS blob is pasted #1 proposed aReact.lazyboundary here; measurement showed it makes the first thread open 469 ms instead of 242 ms (the Suspense retry mounts the pane at transition priority — prefetching the chunk recovers only ~7 ms). This PR keeps the static import and pins the measurement in a comment. Tradeoff: the thread view (~899 KB raw) ships in the workspace route chunk instead of a click-time round trip.Notes
getClientRectson a huge text node) and is not addressed in this PR.