fix(modifiers): fail closed when modifiers-napi is the public stub#47
Merged
Conversation
modifiers-napi@0.0.1 on public npm is a reservation stub with no
exports. The previous isModifierPressed destructured
isModifierPressed: nativeIsModifierPressed from require('modifiers-napi')
and called it unconditionally. When the stub is the resolved package,
nativeIsModifierPressed is undefined and the call throws
'nativeIsModifierPressed is not a function' on every Enter keystroke
at useTextInput.ts:263, which gates on env.terminal === 'Apple_Terminal'
to work around Apple Terminal not supporting custom Shift+Enter
keybindings. The throw bubbles up through the Ink input dispatch and
blocks the Enter submit pipeline, so Terminal.app users cannot submit
prompts interactively.
Guard the destructure: if the export is not a function, report the
modifier as not pressed. This disables best-effort Shift+Enter newline
detection on Apple Terminal (a nicety) while restoring Enter submit.
Returning false is the safe fallback since the path only ever asked
whether Shift was held. The prewarm path is already wrapped in
try/catch and is unaffected.
Adds src/utils/modifiers.test.ts with two cases:
- darwin + stub (no isModifierPressed export): returns false instead
of throwing. This is the regression that blocked Enter on Apple
Terminal.
- non-darwin: returns false without consulting the stub.
Refs: #44
|
It's working for me |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
modifiers-napi@0.0.1on public npm is a reservation stub with no exports.isModifierPressedpreviously destructuredisModifierPressedfromrequire('modifiers-napi')and called it unconditionally — when the stub resolves, the function isundefinedand the call throwsTypeError: nativeIsModifierPressed is not a functionon every Enter keystroke.The only call site (
src/hooks/useTextInput.ts:263inhandleEnter) is gated onenv.terminal === 'Apple_Terminal'as a workaround for Apple Terminal not supporting custom Shift+Enter keybindings. The throw bubbles up through the Ink input dispatch and blocks the Enter submit pipeline, so Terminal.app users cannot submit prompts interactively. Every other terminal (iTerm2, Ghostty, Kitty, VSCode) takes a different branch and is unaffected.Fix
Guard the destructure. If the export is not a function, fail closed: report the modifier as not pressed. This disables best-effort Shift+Enter newline detection on Apple Terminal (a nicety) while restoring Enter submit. Returning
falseis the safe fallback — the path only ever asked whether Shift was held.prewarmModifiersis already wrapped in try/catch and is unaffected.Tests
src/utils/modifiers.test.tsadds two cases:isModifierPressedexport): returnsfalseinstead of throwing. This is the exact regression that blocked Enter on Apple Terminal.falsewithout ever consulting the stub.Verified locally:
bun test src/utils/modifiers.test.ts→ 2 pass, 0 fail. Package smoke (bun run test:package-smoke) builds clean on this branch.What this doesn't claim
TERM_PROGRAM=Apple_Terminal— that requires macOS Terminal.app. The unit test proves the guard path runs and returnsfalserather than throwing the TypeError; reporter (@RasputinKaiser) can verify the interactive Enter submit.Closes #44.
Follow-up
The deeper pattern —
modifiers-napibeing a reservation stub in the OSS dependency tree — is the same class of stub problem tracked in #42 (native image processor). A realmodifiers-napiN-API binding toCGEventSourceFlagsStatewould close the gap permanently and re-enable the Apple Terminal Shift+Enter newline detection. That belongs with #42, not this fix.