Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions apps/mobile/src/components/agents/new-session-screen-body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,23 @@ export function NewSessionScreenBody() {
const [promptSeed, setPromptSeed] = useState<'pending' | 'settled' | 'restore'>('pending');
useEffect(() => {
if (!draftState.settled) {
if (promptSeed !== 'pending') {
// The identity or entity changed, so the input remounts empty: clear
// the route-owned prompt state with it, or Start would submit text the
// user can no longer see.
promptRef.current = '';
setHasPrompt(false);
setPromptSeed('pending');
if (promptSeed === 'pending') {
return;
}
// The identity or entity changed. A `restore` seed is a stored draft the
// input remounts away, so clear the route-owned prompt with it. A
// `settled` seed that still holds text is the user's own typing: the
// remount key stays `empty`, so the input keeps showing that text and
// clearing the route-owned prompt (which Start and the create body read)
// would desync it from the visible field. Preserve it instead — the
// persist effect below then saves the pre-identity prompt under the
// settled identity.
if (promptSeed === 'settled' && promptRef.current !== '') {
Comment thread
iscekic marked this conversation as resolved.
Outdated
return;
}
promptRef.current = '';
setHasPrompt(false);
setPromptSeed('pending');
return;
}
if (promptSeed !== 'pending') {
Expand Down Expand Up @@ -563,6 +572,21 @@ export function NewSessionScreenBody() {
}
}

// The composer mounts before `user.getMe` resolves, so a prompt typed in that
// window has no account to write under and `handlePromptChange` skips the
// save. Persist the current prompt once the identity arrives (and if it
// changes), so text typed before the query settled survives a background or
// kill rather than waiting for the next keystroke.
useEffect(() => {
Comment thread
iscekic marked this conversation as resolved.
if (isCloneEntry || !userId) {
return;
}
const text = promptRef.current;
if (text.trim().length > 0) {
saveDraft(userId, NEW_SESSION_DRAFT_KEY, text);
}
}, [userId, isCloneEntry, promptRef]);

// Discard confirm: leaving with a non-empty prompt or unsent uploads asks
// first. Discard clears the stored draft and the route-owned prompt ref, then
// releases admitted uploads before the captured navigation action is
Expand Down
5 changes: 4 additions & 1 deletion apps/mobile/src/lib/use-new-session-repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type UseNewSessionReposResult = {
recents: NewSessionRepository[];
groups: RepositoryGroup[];
isRetrying: boolean;
/** True once every provider query has settled and at least one repo is visible. */
/** True once every provider query has settled without error and at least one repo is visible. */
reposSettled: boolean;
openIntegration: (platform: RepositoryPlatform) => void;
refreshReposForceFresh: () => Promise<void>;
Expand Down Expand Up @@ -365,6 +365,9 @@ export function useNewSessionRepos({
!githubQuery.isLoading &&
!gitlabQuery.isLoading &&
!bitbucketQuery.isLoading &&
!githubQuery.isError &&
!gitlabQuery.isError &&
!bitbucketQuery.isError &&
repositories.length > 0;

return {
Expand Down
Loading