Repository navigation
refactor(mobile): extract settings, diagnostics and editor-document screens from their routes - #19675
Conversation
88c57dc to
b06d2b5
Compare
…om their routes Peel the settings menu, about, notifications, chat-UI and browser-settings bodies out of their expo-router route files into props-driven components under mobile/src/settings, leaving each route as a thin mount. No visual change. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Move the voice-settings body onto a VoiceSettingsOperations prop, lift the troubleshoot diagnostic run into a hook behind a presentational view, and put the network-diagnostics body behind a device-operations prop. The routes keep the native bindings (host client acquisition, log store subscription) and mount the screens. No visual change. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…tions prop Take the direct Linking.openURL out of SmartWorkspaceSourceField and thread an openExternalUrl prop from the modal controller, so a second route tree can mount the create sheet with its own opener. No visual change. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
… presentation Split the editor document into a body module and a standalone script module so a host that is not this WebView can serve the same program, and move the message handling into a controller hook behind a transport. MobileRichMarkdownEditor stays the only presentation and supplies the injectJavaScript transport. A snapshot of main's document pins the built HTML byte for byte. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The extracted screen waited for the desktop to confirm before the enable switch moved and greyed it while saving. Flip the value on tap, reconcile with the confirmed reply, and refresh on rejection, matching main. The switch, the dictation-mode segments and the model list carry no save-time disabled state, also matching main. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Review found four screens gained state base never had. Notifications no longer gates its switch on a load flag or a save flag, so the control is live from first paint and survives a failed read, and its re-entrancy guard is gone to match base and the voice fix. Browser settings applies the tapped mode optimistically, starts unbusy and carries no disabled row. The voice route drops a remount key that wiped screen state when a second host's null client matched the find. Network diagnostics gates on the host object again, not on its name or endpoint being non-empty. The About link failure keeps its message but reads as an error, not a second version line. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…ture The checked-in HTML capture failed the repo formatter, and reformatting it would defeat the byte-identity check. A sha256 plus byte length pins the same bytes without a file the formatter wants to rewrite. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
There was a problem hiding this comment.
ℹ️ No critical issues — one minor accessibility nit inline, plus a scope note below.
Reviewed changes
- Screen extraction — the bodies of
settings,about,notifications,native-chat-settings,browser-settings,voice-settings, andtroubleshootmoved into props-driven components undermobile/src/, leaving eachmobile/app/*.tsxroute as a thin mount. - Connection diagnostics — the network-diagnostics route keeps its native host-selection wiring and delegates to
ConnectionDiagnosticsScreen, backed by a newDiagnosticsDeviceOperationsabstraction (native-diagnostics-operations.ts). - Rich markdown editor split — the editor document's script is separated from its WebView presentation via a
useMobileRichMarkdownEditorControllerhook, pinned byte-for-byte by a sha256 digest test. - Workspace creation —
NewWorktreeModal/NewWorktreeFormSheet/SmartWorkspaceSourceFieldnow takeonOpenExternalUrlas a prop instead of importingLinking. - Accessibility & error surfacing — the extracted controls gain
accessibilityRole/accessibilityLabel/testIDattributes, and rejected external-link/storage reads now surface an error line instead of being unhandled rejections.
I traced each extracted screen against its removed base implementation and the wiring is faithful — the notification toggle flow (save(value && granted)), the diagnostic copy/send semantics, the voice optimistic flip with the request-epoch fence, and the host picker ordering all match. No behavioral regressions found.
ℹ️ Extracted screens still depend on expo-router
The stated motivation for this refactor is that these components get mounted from a second route tree, but a few of them still reach into router context directly: notification-settings-screen.tsx and pending-credential-cleanup-card.tsx call useFocusEffect unconditionally, and browser-settings-screen.tsx / native-chat-settings-screen.tsx / mobile-settings-menu.tsx fall back to useRouter(). The useRouter sites already have an onBack prop escape hatch, but the two useFocusEffect sites have no equivalent. Worth confirming the second tree supplies a navigation context there, or threading focus/callback props through now rather than after the second tree lands.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| <Pressable | ||
| key={mode.value} | ||
| accessibilityRole="radio" | ||
| aria-checked={active} |
There was a problem hiding this comment.
Use accessibilityState={{ checked: active }} instead of aria-checked here: every other radio/checkbox control in mobile/ conveys selected state via accessibilityState (e.g. PRCommentsSection, MobileNativeChatSessionOptionRows), and aria-checked appears nowhere else in the codebase. It also reads inconsistently next to the sibling accessibilityRole="radio".
…inner Both were disclosed additions over base with no test that failed when they were removed: dropping the fence check, dropping the epoch increments, or starting the loading flag at false all left the suite green. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
scope, available, loadLinkMode, availability and linksAvailable were
extension points for a future route tree that no caller passes, and their
defaults made every branch behind them unreachable. Removing them leaves
the rendered tree unchanged except for a disabled={false} that base never
set at all.
children stays: app/settings.tsx passes the pending-credential-cleanup
card through it.
Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…d load The extraction replaced base's setLoading(true)-on-setup-null Effect with a one-shot initial flag, so once a read failed the flag stayed false and a re-entry left the stale error card up while the retry was already on the wire. Base showed the spinner again. Set the flag from the read that clears it rather than resurrecting base's derived-state Effect. DictationSetupPollController serialises reads, so no in-flight read can clear a newer one's flag. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The spinner fix sets the flag from refresh, which masked the initial-value mutation in the sibling test: by the time it asserts, a read has already raised the flag. Mounting unfocused runs no read, so only useState(true) decides that paint — which is the frame base flashed the error card in. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
dc42394 to
2e13465
Compare
📝 WalkthroughWalkthroughThe change extracts mobile settings, troubleshooting, diagnostics, and editor logic into shared components and hooks. Settings routes now provide native navigation and operation adapters. Diagnostics screens support report generation, copying, submission, and cancellable checks. The rich Markdown editor uses shared contracts, a controller hook, and composed WebView script fragments. External URL callbacks now flow from host overlays through worktree modal components. Tests cover generated editor HTML and settings state behavior. Priority: ⬇️ Low Merge Risk: 🔵 Low · up to This refactor moves several mobile settings and diagnostics screens into shared components without changing the intended behavior. Two edge cases remain where a screen can briefly display a setting value that disagrees with what was saved, and some new diagnostics controls do not announce their role or expanded/disabled state to screen readers. These are small, contained issues that can be fixed quickly or followed up after merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the scope, behavior changes, exclusions, and verification results. It does not follow the required template because it omits the ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, AI Disclosure, Review, boundary, Notes, and Checklist sections. Resolution Update the description to include all required template sections. Add an ELI5 summary, explicit What Changed and Why sections, a Linked Issue entry with
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
mobile/src/diagnostics/troubleshoot-view.tsx (1)
136-139: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd accessibility metadata to the accordion headers.
The accordion header is a disclosure control. It exposes no role and no expanded state to screen readers, so assistive technology announces only the title text. Add
accessibilityRole="button"andaccessibilityState={{ expanded: expandedId === section.id }}.The connection-log
Pressableat Lines 100-105 has the same gap foraccessibilityRole. The back button at Lines 60-64 already sets both attributes, so this keeps the new component internally consistent.Keep the label text in English. Based on learnings, mobile accessibility labels stay in English until a shared i18n layer exists.
♿ Proposed accessibility metadata
<Pressable + accessibilityRole="button" + accessibilityState={{ expanded: expandedId === section.id }} style={({ pressed }) => [styles.accordionHeader, pressed && styles.rowPressed]} onPress={() => toggleSection(section.id)} >Source: Learnings
mobile/src/diagnostics/connection-diagnostics-view.tsx (1)
62-62: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd accessibility metadata to the copy and send controls.
The back control declares
accessibilityRoleandaccessibilityLabelat Lines 44-45. The copy control at Line 62 and the send control at Lines 82-86 declare neither. The send control also setsdisabledwithoutaccessibilityState, so assistive technology does not announce the disabled state while a submission is in flight.♿ Proposed fix for the action controls
- <Pressable style={styles.copyButton} onPress={() => void copyDiagnostics()}> + <Pressable + accessibilityRole="button" + accessibilityLabel="Copy report" + style={styles.copyButton} + onPress={() => void copyDiagnostics()} + ><Pressable + accessibilityRole="button" + accessibilityLabel="Send diagnostics to Orca" + accessibilityState={{ disabled: submissionState === 'sending' }} style={styles.sendButton} onPress={() => void sendDiagnostics()} disabled={submissionState === 'sending'} >Also applies to: 82-86
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 2f597292-f641-479d-972c-98b346ef0f9e
📒 Files selected for processing (48)
mobile/app/about.tsxmobile/app/browser-settings.tsxmobile/app/connection-log.tsxmobile/app/native-chat-settings.tsxmobile/app/notifications.tsxmobile/app/settings.tsxmobile/app/troubleshoot.tsxmobile/app/voice-settings.tsxmobile/src/components/MobileRichMarkdownEditor.tsxmobile/src/components/NewWorktreeFormSheet.tsxmobile/src/components/NewWorktreeModal.tsxmobile/src/components/NewWorktreeModalController.tsxmobile/src/components/SmartWorkspaceSourceField.tsxmobile/src/components/mobile-rich-markdown-editor-contract.tsmobile/src/components/mobile-rich-markdown-editor-document-body.tsmobile/src/components/mobile-rich-markdown-editor-document-suffix.tsmobile/src/components/mobile-rich-markdown-editor-document.test.tsmobile/src/components/mobile-rich-markdown-editor-html.tsmobile/src/components/mobile-rich-markdown-editor-script-primary.tsmobile/src/components/mobile-rich-markdown-editor-script-secondary.tsmobile/src/components/mobile-rich-markdown-editor-script-string.tsmobile/src/components/mobile-rich-markdown-editor-script.tsmobile/src/components/new-worktree-modal-types.tsmobile/src/components/use-mobile-rich-markdown-editor-controller.tsmobile/src/diagnostics/connection-diagnostics-screen-styles.tsmobile/src/diagnostics/connection-diagnostics-screen.tsxmobile/src/diagnostics/connection-diagnostics-view.tsxmobile/src/diagnostics/diagnostics-device-operations.tsmobile/src/diagnostics/native-diagnostics-operations.tsmobile/src/diagnostics/troubleshoot-view.tsxmobile/src/diagnostics/use-troubleshoot-diagnostics.tsmobile/src/host-screen/host-screen-overlays.tsxmobile/src/settings/about-screen.tsxmobile/src/settings/browser-settings-screen.tsxmobile/src/settings/mobile-settings-menu-items.tsmobile/src/settings/mobile-settings-menu.tsxmobile/src/settings/native-chat-settings-screen.tsxmobile/src/settings/native-notification-settings-operations.tsmobile/src/settings/native-voice-settings-operations.tsmobile/src/settings/notification-settings-operations.tsmobile/src/settings/notification-settings-screen.tsxmobile/src/settings/pending-credential-cleanup-card.tsxmobile/src/settings/settings-menu-screen.tsxmobile/src/settings/settings-screen-state.test.tsxmobile/src/settings/voice-settings-operations.tsmobile/src/settings/voice-settings-poller-refresh.test.tsxmobile/src/settings/voice-settings-screen.tsxmobile/src/settings/voice-settings-styles.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| void loadTerminalLinkOpenMode().then( | ||
| (mode) => { | ||
| if (active) { | ||
| setLinkMode(mode) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Do not overwrite a selection with the initial load.
The picker is interactive while loadTerminalLinkOpenMode() is pending. If the user selects a mode first, Line 49 can restore the older persisted mode after the new mode was saved. Ignore the load result after the first user selection.
Proposed fix
-import { useCallback, useEffect, useState } from 'react'
+import { useCallback, useEffect, useRef, useState } from 'react'
+ const didSelectLinkMode = useRef(false)
- if (active) {
+ if (active && !didSelectLinkMode.current) {
setLinkMode(mode)
}
const selectLinkMode = useCallback((mode: MobileTerminalLinkOpenMode) => {
+ didSelectLinkMode.current = true
setError(null)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| setLinkMode(mode) | |
| if (active && !didSelectLinkMode.current) { | |
| setLinkMode(mode) | |
| } |
| const refreshSettings = useCallback(async () => { | ||
| const [enabled, permission] = await Promise.all([ | ||
| operations.preference(), | ||
| operations.permission() | ||
| ]) | ||
| setPushEnabled(enabled.enabled) | ||
| setPermissionState(permission) | ||
| setError(null) | ||
| }, [operations]) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Add a stale-response fence to refreshSettings.
refreshSettings has two triggers: the focus effect and the AppState 'active' listener. Neither trigger checks whether its response is still the latest.
Trigger path: the user taps the switch on. operations.permission(true) shows the OS permission alert, so iOS reports 'inactive' and then 'active' when the alert closes. The listener starts refreshSettings, which reads the preference before togglePush writes it. If that read resolves after togglePush calls setPushEnabled(saved.enabled), the screen shows the stale value while storage holds the new value. The same interleaving also clears a toggle error, because refreshSettings calls setError(null).
The voice screen in this cohort already fences reads with a request epoch. Use the same approach here.
♻️ Proposed fence using a request counter
+ const requestEpoch = useRef(0)
+
const refreshSettings = useCallback(async () => {
+ const epoch = ++requestEpoch.current
const [enabled, permission] = await Promise.all([
operations.preference(),
operations.permission()
])
+ if (epoch !== requestEpoch.current) {
+ return
+ }
setPushEnabled(enabled.enabled)
setPermissionState(permission)
setError(null)
}, [operations])Also bump requestEpoch.current at the start of togglePush, so an in-flight refresh cannot overwrite the toggle result. Import useRef from react.
There was a problem hiding this comment.
ℹ️ No new issues in this incremental delta. The three commits are clean, and the one accessibility nit from the prior review remains open.
Reviewed changes
- Dropped unused capability props — removed
scope,available,loadLinkMode,availability, andlinksAvailablefrom the extracted settings screens. No caller passed them and their defaults made every gated branch unreachable, so the rendered tree is unchanged (only adisabled={false}that base never set). - Re-show the voice spinner on a refocus retry —
refreshnow raisesloadingitself instead of a derived-state effect, so re-entering after a failed load spins rather than leaving a stale error card. Correct becauseDictationSetupPollControllerserialises reads via itsinFlightguard, so no in-flight read can clear a newer one's flag. - Pinned the spinner's first paint — new tests assert the spinner (not the error card) renders before focus lands and that a refocus retry re-shows it; both fail without the underlying behavior change.
I traced the removed capability props to confirm no residual callers remain, and verified the loading flag churn is invisible during normal polling (setup !== null keeps the spinner branch off). The aria-checked consistency nit on the voice mode selector (voice-settings-screen.tsx:239) is still present, so that thread stays open.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Summary
Moves the body of each listed mobile route out of
mobile/app/*.tsxinto a props-driven screen component undermobile/src/, leaving the route as a thin mount. A later PR mounts the same components from a second route tree; route files cannot be imported across trees, components can.The happy path is identical: tap through these eight screens with a healthy connection and nothing looks or behaves differently. There are deliberate behavior changes on the error paths, plus accessibility metadata — all listed below.
Rebased onto
main. This was PR 3 of the split of #13386 and was previously stacked on #19669 (pr1-native-adapters); it no longer depends on it.Routes extracted
Seven are a single mount.
connection-log.tsxkeeps its native host-selection bindings and mounts one screen with the host picker as a prop.Also: the workspace creation modal takes
onOpenExternalUrlas a prop instead of importingLinking, and the rich markdown editor's document builder is split from its WebView presentation. The split is done from main's own bytes; a test pins the rendered document to main's sha256 and byte length (a checked-in HTML capture would be rewritten by the formatter).Deliberately not carried from the branch
useSyncExternalStorewiring and report content are kept.d2d825b670(https images in frames),9e2da765fa(drawer keyboard-lift into an effect) and328617b8e8(browser-settings navigability)..web.tsxvariants and*-presentation.tsxsplits.Behavior changes over base
Nothing on the happy path changes. These do, and each is pinned by a test that fails if the behavior is removed:
connection-log's copied check wascopiedHostId === selectedId, which isnull === nullwhen no host is selected. It is now explicitly guarded.Everything else the branch's screens had added over base (a disabled-until-loaded notifications switch, a non-optimistic browser-settings write, a remount key on the voice route, a double-tap guard) was found in review and removed.
Found and fixed in review
Extracting Voice dropped base's
setLoading(true)-when-setup === nullEffect in favour of a one-shot initial flag, so after a failed read the flag stayed false and re-entering the screen left the stale error card up while the retry was already on the wire. Base re-showed the spinner. Fixed by setting the flag from the read that clears it (DictationSetupPollControllerserialises reads, so no in-flight read can clear a newer one's flag) rather than by restoring the derived-state Effect.Removed in review
Six capability props on the extracted screens —
scope,availableandloadLinkModeon browser settings,scopeon chat settings,availabilityon the settings menu, andlinksAvailableon About — were extension points for the future route tree that no caller passed. Their defaults made every branch behind them unreachable, including two that would have rendered different copy. Stripped ind6b84f7541; the rendered tree is unchanged except for adisabled={false}that base never set at all.Rebase note
The rebase onto
maindropped one commit,b06d2b5623, which registered the voice adapter inmobile/src/transport/screen-rpc-ratchet.test.ts. That file exists only onpr1-native-adapters; main has no equivalent ratchet, so the commit had nothing to apply to. Nothing else from that branch is carried here.Verification
pnpm --dir mobile typecheck,oxlint,oxfmt --checkcleanpnpm --dir mobile test: 523 files, 4267 passed, 3 skippedpnpm tcclean;check:code-quality:changedandcheck:react-doctor:changed: 0 findings across 48 files