Skip to content

fix(use): reject invalid mounted-input selectors and identify handler errors - #304

Merged
hyfdev merged 1 commit into
mainfrom
codex/use-input-validation-final
Sep 7, 2026
Merged

hyfdev merged 1 commit into
mainfrom
codex/use-input-validation-final

Conversation

@hyfdev

@hyfdev hyfdev commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

An invalid <UseInputWhileMounted type="mouse"> can acquire raw input and silently discard every event. The component now validates the selector before subscribing and checks reactive changes when input arrives; Runtime reports invalid updates and releases input ownership.

type: "text" → "mouse"
next input: TypeError → raw mode released

Handler errors identify the public composable the caller used. A shared internal resolver preserves direct handlers and resolves refs only on matching events across all four input composables.

Validation: regression tests fail against main for invalid initial/reactive selectors and the unfiltered handler diagnostic, and pass with the fix. The input suites pass 42 tests; vp run check passes formatting, lint, type checks, builds, and all package/system tests.

Implemented and reviewed with AI assistance. Split from #286.

@hyfdev
hyfdev force-pushed the codex/use-input-validation-final branch from 55d8ba5 to dd2d582 Compare September 7, 2026 14:57
@hyfdev
hyfdev marked this pull request as ready for review September 7, 2026 15:02
Copilot AI lite review requested due to automatic review settings September 7, 2026 15:02
@hyfdev
hyfdev merged commit 7e4e113 into main Sep 7, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are cohesive, match the stated failure mode, and are backed by targeted regression tests covering both invalid selectors and corrected handler diagnostics.

Pull request overview

This PR hardens @vue-tui/use input APIs against invalid selectors that could otherwise keep managed input/raw mode active while silently discarding events, and improves diagnostics by ensuring handler type errors name the public composable/component the caller used.

Changes:

  • Add a shared resolveHandlerSource() helper so all input composables report handler errors under their own API name, while still resolving handler refs at event time.
  • Validate <UseInputWhileMounted>’s type prop both before subscribing and at event time so invalid reactive updates fail via Runtime’s fatal input handling and release raw mode.
  • Extend regression tests for invalid initial/reactive selectors and for error-message attribution.
File summaries
File Description
packages/use/tests/input-while-mounted/use-input-while-mounted.test.tsx Updates option-shape error wording and adds regression coverage for selector-vs-handler error ordering and unfiltered handler diagnostics.
packages/use/tests/input-while-mounted/component.test.tsx Adds component-level coverage for rejecting invalid type props and for invalid reactive type updates releasing raw mode.
packages/use/src/input/use-text-input.ts Switches handler validation/resolution to the shared resolver to improve diagnostics consistency.
packages/use/src/input/use-key-input.ts Switches handler validation/resolution to the shared resolver to improve diagnostics consistency.
packages/use/src/input/use-paste-input.ts Switches handler validation/resolution to the shared resolver to improve diagnostics consistency.
packages/use/src/input/handler-source.ts Introduces resolveHandlerSource() to preserve direct handlers and resolve refs only when an event is delivered.
packages/use/src/input-while-mounted/use-input-while-mounted.vue Adds pre-subscribe and event-time type validation for the renderless component wrapper.
packages/use/src/input-while-mounted/use-input-while-mounted.ts Adds assertInputType() and refactors useInputWhileMounted() to validate options early and consistently attribute handler errors.
.agents/docs/use-api-design.md Documents the component’s new validation behavior and its interaction with Runtime’s fatal input error handling.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants