Skip to content

fix(app): submit on Magic Keyboard Enter in the iPadOS PWA composer - #1099

Merged
SawyerHood merged 2 commits into
get-bb:mainfrom
salemsayed:bb/fix-ipad-pwa-composer-on-upstream-thr_6vtsdfa5qk
Aug 8, 2026
Merged

SawyerHood merged 2 commits into
get-bb:mainfrom
salemsayed:bb/fix-ipad-pwa-composer-on-upstream-thr_6vtsdfa5qk

Conversation

@salemsayed

Copy link
Copy Markdown
Contributor

Problem

In the installed iPad PWA, there is no way to send a prompt from a Magic Keyboard. Pressing Enter in the composer always inserts a newline, and the only way to submit is to tap the send button.

The composer gates Enter-to-submit on pointer coarseness alone:

const canSubmitWithEnterKey = !isPointerCoarse;

An iPad reports a coarse pointer whether or not a hardware keyboard is attached, so the hardware Enter is permanently routed to the newline path. Making this device-wide would break the software keyboard, whose Return must stay a newline.

Two details make the physical key hard to detect on this platform:

  • ProseMirror deliberately defers iOS Enter handling and later replays a synthetic Enter into handleKeyDown, so the software keyboard can finish its own DOM mutation first. That synthetic event no longer carries the physical code.
  • The iPad software keyboard's Return arrives with an empty code, while a Magic Keyboard Enter arrives as code: "Enter" (or "NumpadEnter").

Fix

A custom ProseMirror DOM keydown hook now looks at the original event before ProseMirror's deferral, and only on iPadOS WebKit. When that original event carries a physical Enter/NumpadEnter code, the existing key handler is invoked with isOriginalIPadHardwareEnter, which enables Enter-to-submit for that one event:

const canSubmitWithEnterKey = !isPointerCoarse || isOriginalIPadHardwareEnter;

Device detection combines an Apple WebKit vendor/UA check with either the legacy iPad platform or the modern desktop-like MacIntel platform plus maxTouchPoints > 2, which is what distinguishes current iPadOS from macOS.

Everything else keeps ProseMirror's normal path, including the software keyboard's Return, which still inserts a newline.

Steer/queue mapping is unchanged

No submit routing changed. canSubmitWithEnterKey simply moved from a component-level constant to a per-event value inside the key handler.

  • steerActiveThreadOnEnter off (default): Enter queues a follow-up, Command+Enter steers.
  • steerActiveThreadOnEnter on: Enter steers, Command+Enter queues.
  • Shift+Enter inserts a newline; in zen mode unmodified Enter inserts a newline too.
  • On iPadOS, a Magic Keyboard Enter/Command+Enter now reaches exactly these existing paths instead of being swallowed.

FollowUpPromptBox.test.tsx consolidates the two overlapping shortcut tests into one parameterized case that asserts both settings, including the scroll-to-bottom behavior that differs between queue and steer.

Android and desktop safeguards

The interception is scoped as narrowly as possible, and both non-iPad coarse-pointer cases are covered by tests:

  • Android (Pixel Tablet, Google Inc. vendor, Linux armv8l) reports code: "Enter" from its software keyboard. It fails the Apple WebKit check, is never intercepted, and keeps Return as a newline.
  • Windows touch hybrids (Win32, maxTouchPoints: 10) likewise fail the vendor check and are untouched.
  • Fine-pointer desktop is entirely unaffected — the hook is a no-op there, and Enter-to-submit continues to run through the existing !isPointerCoarse path.

IME and typeahead

Composition is excluded on several fronts, so confirming a candidate never submits:

  • view.composing, event.isComposing, and event.keyCode === 229 all bail out.
  • The hook mirrors ProseMirror's own Safari compositionend → keydown safeguard with a 500 ms window. Because this DOM hook runs before ProseMirror's keydown handler, skipping that safeguard would submit an IME candidate confirmation.
  • An event suppressed by that window is recorded in a WeakSet, so if it later arrives through the normal handler it is still refused rather than double-processed.

Typeahead is unaffected: with an open command or mention menu, a Magic Keyboard Enter applies the highlighted suggestion (/ → /review , with the mention resource attached) and does not submit, matching the fine-pointer behavior.

Performance

  • isIPadOSWebKit() is computed once per mount via useMemo. The value is stable for the lifetime of the page, so no additional media-query or event listener is registered.
  • The keydown hook returns after a few boolean checks for every non-iPad platform and every non-Enter key, so no per-keystroke cost is added anywhere else.
  • The composition guard is an O(1) timestamp comparison plus a WeakSet lookup. Keying the set on the event object means entries are collected along with the event, so it cannot grow unbounded.
  • canSubmitWithEnterKey left the useCallback dependency list and was replaced by isPointerCoarse, so handler identity churns no more often than before.
  • Assigning handleEditorKeyDownRef moved from useEffect to useLayoutEffect, so the ref is current before any keydown can be dispatched after a commit and a stale handler cannot fire in the same frame.

Documentation

Per the repository's rule that a user-facing behavior change updates its discoverable surfaces in the same change, the Enter behavior is now described in:

  • docs/configuration.md
  • the built-in bb-cli skill (SKILL.md and references/app-settings.md)
  • the bb guide template bb-guide-customization.md and its generated counterpart

Each now states the typeahead exception, Shift+Enter and zen-mode newlines, the coarse-pointer software-keyboard path, and the iPadOS Magic Keyboard behavior.

Validation

  • Tests: 317 files and 2,384 app tests passed.
  • Typecheck: app and templates passed.
  • Lint: app passed, with existing warnings only.
  • Diff check: passed.
  • Device verification: confirmed on a physical iPad running the installed PWA — a Magic Keyboard Enter submits, and the software keyboard's Return still inserts a newline.

New coverage in PromptBoxInternal.test.tsx spans fine-pointer Enter, Magic Keyboard Enter, software-keyboard Enter, Android, a Windows touch hybrid, Shift+Enter, Command+Enter, IME composition, the post-compositionend window, zen mode, and typeahead application.

🤖 Generated with Claude Code

@salemsayed
salemsayed force-pushed the bb/fix-ipad-pwa-composer-on-upstream-thr_6vtsdfa5qk branch from 2203295 to 2481c02 Compare August 7, 2026 22:35
@SawyerHood

Copy link
Copy Markdown
Collaborator

🚨 SLOP COP 🚨 · review

I am SlopCop. I am now reviewing this pull request under the security, code quality, performance, architecture, and end-to-end guidelines.

The composer gated Enter-to-submit on a coarse pointer, so an iPad always
took the newline path even with a Magic Keyboard attached. In the iPad PWA
there was then no way to send a prompt from the hardware keyboard.

On iPadOS WebKit only, a ProseMirror DOM keydown hook now inspects the
original event's physical code. A Magic Keyboard Enter reports
code="Enter"/"NumpadEnter" and submits; the software keyboard's Return
reports an empty code and still inserts a newline. Other platforms,
including Android and coarse-pointer Windows hybrids, stay entirely on
ProseMirror's normal path.

The steer/queue mapping is unchanged: Enter and Command+Enter keep their
existing roles under steerActiveThreadOnEnter, Shift+Enter and zen-mode
Enter stay newlines, and an open typeahead menu still consumes Enter to
apply its suggestion.

IME composition is excluded via view.composing, event.isComposing and
keyCode 229, plus ProseMirror's Safari compositionend -> keydown window,
so confirming a candidate never submits.

Docs, the bb-cli skill, and the bb guide template describe the resulting
Enter behavior.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
platformMock.mockRestore();
vendorMock.mockRestore();
userAgentMock.mockRestore();
};

@SawyerHood SawyerHood Aug 8, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚨 slopcop/review — These tests do not activate ProseMirror's iOS branch.

ProseMirror reads navigator once during module load. This helper changes it after the TipTap import. Thus, browser.ios and browser.safari stay false in this suite. The tests cover this custom hook, but not ProseMirror's 200 ms replay. Please set the iPad identity before module import. Then add a test that confirms one submission after the replay timeout.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed in dfbdbf5, which adds PromptBoxInternal.ipados.test.tsx. It claims the iPad identity in a vi.hoisted block, before any import, so ProseMirror's browser.safari and browser.ios are genuinely on. Two tests: a Magic Keyboard Enter submits exactly once with no replayed second submit after the 200 ms window, and a software Return (code: "") becomes a newline only after that replay. Both fail if the hoisted block is removed.

One correction for the record: the synthetic replay does still carry code: "Enter" — ProseMirror's keyEvent sets event.key = event.code = key (prosemirror-view/dist/index.js:137). The hook is needed because ProseMirror's iOS branch swallows the original event and never passes it to handleKeyDown, not because the replay loses the physical code.

(event: KeyboardEvent, isOriginalIPadHardwareEnter?: boolean) => boolean
>(() => false);
const compositionEndedAtRef = useRef(Number.NEGATIVE_INFINITY);
const postCompositionKeyDownEventsRef = useRef(

@SawyerHood SawyerHood Aug 8, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚨 slopcop/review — This expression creates a new WeakSet during every render.

React keeps only the first value that useRef receives. The composer renders after each controlled value change. Thus, each edit also creates a discarded WeakSet. Please use a lazy ref initializer, or initialize a nullable ref once.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed in dfbdbf5. useRef now receives null, and a usePostCompositionKeyDownEvents hook fills it once with ??=, so no WeakSet is built and discarded per render.

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

ELI5: This change lets an iPad Magic Keyboard send a prompt with Enter. The screen keyboard Return key still adds a new line.

I found two items.

  1. The new tests change the iPad identity after ProseMirror loads. ProseMirror reads that identity only once. Thus, the tests do not cover its iOS replay path. This path is the main reason for the change. I left an inline comment with a test fix.
  2. useRef(new WeakSet()) creates a discarded WeakSet during every render. I left an inline comment with a lazy initialization fix.

The security review found no issue. The change adds no server, network, authentication, storage, or protocol surface.

The architecture search found no other iPad helper or rich composer to reuse. The change does copy a small composition check and ProseMirror's 500 ms guard. I do not see a larger refactor requirement.

Validation passed for head 2481c025cd0c6be1263eefc9ca50a1cc473cd474:

  • The app type check passed through Turbo.
  • All 321 app test files passed. All 2,425 app tests passed.
  • The browser check used an iPad identity and a coarse pointer. Shift+Enter added a new line. Hardware Enter reached the submit shortcut and prevented the browser default.
  • The browser check used Chromium. It did not reproduce the WebKit engine or ProseMirror's true iOS module-load state.

I used a comment-only review. I did not approve the pull request or request changes.

ProseMirror reads navigator once, while its module loads, to set browser.safari
and browser.ios. The existing suite mocks navigator per test, which lands too
late, so those flags stay false and the iOS Enter path never runs.

This suite claims the iPad identity in a hoisted block, before any import. It
covers the Magic Keyboard Enter submitting exactly once with no replayed second
submit, and the software Return becoming a newline through the 200 ms replay.
Both tests fail if the hoisted identity is removed.

The compositionend guard and the lazy WeakSet ref are folded into the previous
commit, because they conflicted with its rebase onto main.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/fix-ipad-pwa-composer-on-upstream-thr_6vtsdfa5qk branch from 2481c02 to dfbdbf5 Compare August 8, 2026 14:21
@SawyerHood
SawyerHood merged commit 23ab126 into get-bb:main Aug 8, 2026
10 checks passed
amadad pushed a commit to amadad/bb that referenced this pull request Aug 14, 2026
…et-bb#1099)

## Problem

In the installed iPad PWA, there is no way to send a prompt from a Magic
Keyboard. Pressing Enter in the composer always inserts a newline, and
the only way to submit is to tap the send button.

The composer gates Enter-to-submit on pointer coarseness alone:

```ts
const canSubmitWithEnterKey = !isPointerCoarse;
```

An iPad reports a coarse pointer whether or not a hardware keyboard is
attached, so the hardware Enter is permanently routed to the newline
path. Making this device-wide would break the software keyboard, whose
Return must stay a newline.

Two details make the physical key hard to detect on this platform:

- ProseMirror deliberately defers iOS Enter handling and later replays a
**synthetic** Enter into `handleKeyDown`, so the software keyboard can
finish its own DOM mutation first. That synthetic event no longer
carries the physical `code`.
- The iPad software keyboard's Return arrives with an empty `code`,
while a Magic Keyboard Enter arrives as `code: "Enter"` (or
`"NumpadEnter"`).

## Fix

A custom ProseMirror DOM `keydown` hook now looks at the **original**
event before ProseMirror's deferral, and only on iPadOS WebKit. When
that original event carries a physical `Enter`/`NumpadEnter` code, the
existing key handler is invoked with `isOriginalIPadHardwareEnter`,
which enables Enter-to-submit for that one event:

```ts
const canSubmitWithEnterKey = !isPointerCoarse || isOriginalIPadHardwareEnter;
```

Device detection combines an Apple WebKit vendor/UA check with either
the legacy `iPad` platform or the modern desktop-like `MacIntel`
platform plus `maxTouchPoints > 2`, which is what distinguishes current
iPadOS from macOS.

Everything else keeps ProseMirror's normal path, including the software
keyboard's Return, which still inserts a newline.

## Steer/queue mapping is unchanged

No submit routing changed. `canSubmitWithEnterKey` simply moved from a
component-level constant to a per-event value inside the key handler.

- `steerActiveThreadOnEnter` off (default): Enter queues a follow-up,
Command+Enter steers.
- `steerActiveThreadOnEnter` on: Enter steers, Command+Enter queues.
- Shift+Enter inserts a newline; in zen mode unmodified Enter inserts a
newline too.
- On iPadOS, a Magic Keyboard Enter/Command+Enter now reaches exactly
these existing paths instead of being swallowed.

`FollowUpPromptBox.test.tsx` consolidates the two overlapping shortcut
tests into one parameterized case that asserts both settings, including
the scroll-to-bottom behavior that differs between queue and steer.

## Android and desktop safeguards

The interception is scoped as narrowly as possible, and both non-iPad
coarse-pointer cases are covered by tests:

- **Android** (Pixel Tablet, `Google Inc.` vendor, `Linux armv8l`)
reports `code: "Enter"` from its software keyboard. It fails the Apple
WebKit check, is never intercepted, and keeps Return as a newline.
- **Windows touch hybrids** (`Win32`, `maxTouchPoints: 10`) likewise
fail the vendor check and are untouched.
- **Fine-pointer desktop** is entirely unaffected — the hook is a no-op
there, and Enter-to-submit continues to run through the existing
`!isPointerCoarse` path.

## IME and typeahead

Composition is excluded on several fronts, so confirming a candidate
never submits:

- `view.composing`, `event.isComposing`, and `event.keyCode === 229` all
bail out.
- The hook mirrors ProseMirror's own Safari `compositionend` → `keydown`
safeguard with a 500 ms window. Because this DOM hook runs *before*
ProseMirror's keydown handler, skipping that safeguard would submit an
IME candidate confirmation.
- An event suppressed by that window is recorded in a `WeakSet`, so if
it later arrives through the normal handler it is still refused rather
than double-processed.

Typeahead is unaffected: with an open command or mention menu, a Magic
Keyboard Enter applies the highlighted suggestion (`/` → `/review `,
with the mention resource attached) and does **not** submit, matching
the fine-pointer behavior.

## Performance

- `isIPadOSWebKit()` is computed once per mount via `useMemo`. The value
is stable for the lifetime of the page, so no additional media-query or
event listener is registered.
- The keydown hook returns after a few boolean checks for every non-iPad
platform and every non-Enter key, so no per-keystroke cost is added
anywhere else.
- The composition guard is an O(1) timestamp comparison plus a `WeakSet`
lookup. Keying the set on the event object means entries are collected
along with the event, so it cannot grow unbounded.
- `canSubmitWithEnterKey` left the `useCallback` dependency list and was
replaced by `isPointerCoarse`, so handler identity churns no more often
than before.
- Assigning `handleEditorKeyDownRef` moved from `useEffect` to
`useLayoutEffect`, so the ref is current before any keydown can be
dispatched after a commit and a stale handler cannot fire in the same
frame.

## Documentation

Per the repository's rule that a user-facing behavior change updates its
discoverable surfaces in the same change, the Enter behavior is now
described in:

- `docs/configuration.md`
- the built-in `bb-cli` skill (`SKILL.md` and
`references/app-settings.md`)
- the bb guide template `bb-guide-customization.md` and its generated
counterpart

Each now states the typeahead exception, Shift+Enter and zen-mode
newlines, the coarse-pointer software-keyboard path, and the iPadOS
Magic Keyboard behavior.

## Validation

- **Tests:** 317 files and 2,384 app tests passed.
- **Typecheck:** app and templates passed.
- **Lint:** app passed, with existing warnings only.
- **Diff check:** passed.
- **Device verification:** confirmed on a physical iPad running the
installed PWA — a Magic Keyboard Enter submits, and the software
keyboard's Return still inserts a newline.

New coverage in `PromptBoxInternal.test.tsx` spans fine-pointer Enter,
Magic Keyboard Enter, software-keyboard Enter, Android, a Windows touch
hybrid, Shift+Enter, Command+Enter, IME composition, the
post-`compositionend` window, zen mode, and typeahead application.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Sawyer Hood <[email protected]>
@salemsayed
salemsayed deleted the bb/fix-ipad-pwa-composer-on-upstream-thr_6vtsdfa5qk branch October 1, 2026 10:42
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