Skip to content

Conversation

@leeroybrun
Copy link

Context / Problem

  • On web builds, the /new modal uses nested routes (/new/pick/path, /new/pick/machine) to select machine/path.
  • Selecting a new path (or machine) and pressing Apply would sometimes not update the /new modal — it would snap back to the original value.

Root cause

  • The picker screens were communicating back to /new via module-level mutable callbacks exported from the /new route module.
  • On web, modal navigation and route transitions can cause screens/modules to be unmounted/remounted or re-instantiated in ways that break this “global callback bridge”, so the picker’s “Apply” effectively became a no-op for the active /new instance.

Fix 1: Replace callback bridge with navigation params

  • Removed the module-global callback mechanism.
  • Pickers now pass the selection back using React Navigation params (CommonActions.setParams) targeting the previous route.
  • /new listens to the returned params via useLocalSearchParams() and updates selectedMachineId / selectedPath accordingly.
  • This approach survives remounts and is consistent with navigation semantics (no hidden cross-module state).

Fix 2: Persist the /new draft locally (lightweight, no UI changes)

  • Added a minimal MMKV-backed “new session draft” stored under new-session-draft-v1.
  • The draft includes: input text, selected machine/path, agent type, permission mode, session type, and updatedAt.
  • /new initializes from this draft when opened, auto-saves changes with a small debounce, and clears the draft after successful session creation.
  • This makes the flow resilient to navigation/remounts and also preserves user input if the modal is closed/reopened.

Files touched

  • sources/app/(app)/new/index.tsx: remove callback bridge, apply param-driven updates, load/save/clear new-session draft.
  • sources/app/(app)/new/pick/machine.tsx: set previous route params instead of calling callbacks.
  • sources/app/(app)/new/pick/path.tsx: set previous route params instead of calling callbacks.
  • sources/sync/persistence.ts: add MMKV helpers + types for new-session draft.

How to test

  • Web:
    • Open http://localhost:3005/new
    • Type a prompt, change path via picker, hit Apply → /new updates to the selected path.
    • Navigate away and back / close and reopen /new → prompt + selections are restored.
    • Create session → draft is cleared.
Implements draft persistence for the new session flow, allowing user selections (input, machine, path, agent, permission mode, session type) to survive remounts and navigation. Removes temporary callback-based state passing and replaces it with navigation params and MMKV storage. Adds utility functions for saving, loading, and clearing the draft in persistence.ts.
@leeroybrun leeroybrun changed the title Fix /new modal path picker not applying on web + persist “new session” draft state locally Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant