Skip to content

fix(meshcore): keep focus on the CLI command line after sending (#3752)#3761

Merged
Yeraze merged 1 commit into
mainfrom
fix/cli-console-refocus-3752
Jun 25, 2026
Merged

fix(meshcore): keep focus on the CLI command line after sending (#3752)#3761
Yeraze merged 1 commit into
mainfrom
fix/cli-console-refocus-3752

Conversation

@Yeraze

@Yeraze Yeraze commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #3752. In the MeshCore Remote Administration console, sending a command moved keyboard focus off the "Type a command…" input, forcing the operator to click back into the field before every command (and risking an accidental navigation that drops the admin session).

Cause: the command input is disabled while a command is in flight, which blurs it; focus wasn't restored when the input re-enabled.

Fix: capture the input via a ref and refocus it once the send completes. A small flag set at the start of runAndLog (and cleared in the effect) ensures we only refocus after an actual send — not on mount or on unrelated sending/disabled transitions.

Because the change lives in the shared CliConsoleBody primitive and routes through the single runAndLog choke point, it covers:

  • the form Send button,
  • the quick-action buttons,
  • the danger-confirm path,

for both the Remote and Local MeshCore consoles.

Tests

  • CliConsoleBody.test.tsx — after a command is sent, asserts focus returns to the input and the field is cleared, ready for the next command.
  • Full suite: 7559 passed, 0 failed.

Closes #3752

🤖 Generated with Claude Code

The command input is disabled while a command is in flight, which drops
keyboard focus and doesn't restore it when the input re-enables — so an
operator had to click back into the field before every command. Capture the
input ref and refocus it once the send completes (guarded by a flag so it
doesn't grab focus on mount or unrelated transitions). Routed through
runAndLog, so it covers the form Send, quick-action buttons, and the
danger-confirm path, for both the Remote and Local MeshCore consoles.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SJPe6J5vKrcbwzt6vCdtrt
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown

Claude finished @Yeraze's task —— View job


PR Review: fix(meshcore): keep focus on the CLI command line after sending

Tasks:

  • Read changed files
  • Review code quality and best practices
  • Check for potential bugs
  • Evaluate test coverage
  • Post final review

Summary

This is a clean, well-scoped fix. The approach is idiomatic React and the implementation is correct. Here's a detailed breakdown:

Code Quality

CliConsoleBody.tsx — The implementation is solid:

  • commandInputRef (line 154) + refocusAfterSendRef (line 155) follow the existing pattern of refs in this component.
  • Setting refocusAfterSendRef.current = true at the start of runAndLog (line 209) before setSending(true) is correct — it ensures the flag is always set before the effect can fire.
  • The useEffect at lines 241–246 is correctly guarded: it fires only when sending transitions to false AND the flag is set, so it won't steal focus on initial mount or on unrelated disabled transitions. This addresses the comment in the PR description precisely.
  • commandInputRef.current?.focus() at line 244 respects the disabled prop — no focus is attempted if the console is already locked (e.g., remote console logged-out state). That's a nice edge case handled correctly.

One minor observation: The refocusAfterSendRef flag is reset to false inside the effect (line 243) — but if disabled is true at the time sending clears, focus is skipped and the flag is cleared anyway. This means if the console becomes disabled during a send (a session expiry race), focus won't be restored when disabled later goes back to false. This is likely an acceptable trade-off (it's an unusual edge case and the fix is for the common path), but worth noting.

Test Coverage

CliConsoleBody.test.tsx — Good regression test:

  • The vi.mock('react-i18next', ...) mock is correct and follows the project pattern.
  • The test covers the primary path: typing a command → clicking Send → asserting document.activeElement === input.
  • The expect(input.value).toBe('') assertion at line 40 validates the field-clear behavior, which is a secondary but important UX check.

Coverage gaps (optional, non-blocking):

  1. The test doesn't cover the quick-action or danger-confirm paths. Those are covered by the description ("routes through the single runAndLog choke point"), but explicit tests for those paths would increase confidence.
  2. No test for the disabled guard in the focus effect (i.e., that focus is NOT restored when disabled=true at the time sending clears). This is a minor omission.

Performance

No concerns. Using useRef + a boolean flag avoids any unnecessary renders. The useEffect dependency array ([sending, disabled]) is minimal and correct.

Security

No concerns.

Verdict

LGTM. The fix is minimal, correct, and well-tested for the primary regression path. The edge case around disabled flipping during a send is unlikely in practice and the trade-off is reasonable.


@Yeraze Yeraze merged commit 6b4731f into main Jun 25, 2026
19 checks passed
@Yeraze Yeraze deleted the fix/cli-console-refocus-3752 branch June 25, 2026 18:19
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.

[FEAT] MeshCore: Remote Administration Console: Leave focus on command line

1 participant