This repository was archived by the owner on Nov 4, 2026. It is now read-only.
Repository navigation
fix(mobile): fire a swipe on membership of the declared direction set - #9689
Merged
os-justin merged 1 commit intoSep 18, 2026
Merged
Conversation
… (objectui#7974) `SwipeGestureConfig.direction` is declared `SpecSwipeDirection[]` — a set — and `useSpecGesture` now honours the whole of it: it recognizes the any-direction move past the threshold and fires only when the DETECTED direction is a member of the declared set. It used to fuse `direction[0]` into one direction-specific recognizer, so every element after the first was declared and never honoured, and an empty or absent set silently defaulted to a left swipe. The scalar branch and its `as string` cast are gone, and nothing replaces them (AGENTS.md #0.1): the declared type rejects a scalar and no runtime path re-admits one. The shipped `@example` moves to `direction: ['left']` in the same change, because repairing either half alone leaves the other teaching the wrong contract. The `@example` gate's ledger row is RE-DERIVED rather than deleted — the repair paid off its TS2322 half and left the TS1108 hook-body excerpt its two siblings in this package are declared for. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012EpHzwH4wTy5sd7ibkD2yq
Contributor
✅ Console Performance Budget
The eager closure is every chunk the entry reaches through static imports — what the browser fetches and parses before the app renders. The entry chunk on its own is a small fraction of it. 📦 Bundle Size Report
Size Limits
|
os-justin
marked this pull request as ready for review
September 18, 2026 00:25
os-justin
deleted the
claude/issue-7974-swipe-direction-honours-the-declared-set
branch
September 18, 2026 00:44
akarma-synetal
pushed a commit
to akarma-synetal/objectui
that referenced
this pull request
Sep 28, 2026
… fallback (objectstack-ai#9788) Fixes objectstack-ai#9691 Clause-②: yes `useSpecGesture` builds each `onGesture` fallback payload by spreading the recognizer's runtime context next to a declared `type`. That context carries a `type` of its own — `GestureContext.type`, the direction-fused recognizer vocabulary — so an arm that writes `type` BEFORE the spread has its declared value overwritten by the recognizer's. Three arms carried that order; `type` now goes last at all three, which is the spelling the `swipe` arm already uses. Executed as one change per the triage ruling on the card (comment `5714886682`): 「三处是**同一个书写顺序缺陷**,⛔ 一起改;并顺手加一条断言把「展开在前、`type` 在后」钉住,否则第四处会以同样方式长出来。」 ## The card's table, re-derived on this branch's base The table on the card was measured on PR objectstack-ai#9689's head. Re-derived on `origin/main` at `57c07f002` — every row holds, and the line numbers happen not to have moved: | line | arm | spelling | declared `type` survives? | |---|---|---|---| | 117 | `swipe` | `{ ...ctx, type: 'swipe' }` | yes — spread first | | 124 | `long_press` | `{ type: 'long_press' }` | yes — no `ctx` spread | | 128 | `pinch` | `{ type: 'pinch', ...ctx }` | **no** | | 132 | `double_tap` | `{ type: 'double_tap' }` | yes — no `ctx` spread | | 137 | `pan` / `drag` | `{ type: declared, ...ctx }` | **no** | | 141 | `rotate` | `{ type: 'rotate', ...ctx }` | **no** | ## One arm moves observably; the rest were latent `drag` is the only configuration whose payload changes. It is the one arm where the two vocabularies disagree — `drag` declared, `pan` recognized — so it reported `pan`. `pinch`, `rotate` **and a declared `pan`** name their recognizer identically, so the overwrite replaced each value with itself. The changeset says exactly this rather than claiming three behaviour changes. ## The load-bearing runtime fact, pinned instead of probed The card supported "`ctx` really carries a `type` key at runtime" with a throwaway probe that was then deleted. That fact is now a standing assertion — `useGesture`'s emitted context is asserted to carry the recognizer's own name. It passes on **both** sides of the repair by design and is not a witness; it is there so that removing `GestureContext.type` some day reds the file that depends on it, and the test says so in its own name and message. ## The ordering pin `packages/mobile/src/__tests__/spec-gesture-fallback-type-order.test.tsx`, three kinds of pin, because no one kind covers the defect: 1. **the runtime fact** above; 2. **per-arm behaviour, driven with a DRIFTED recognizer context** — every one of the seven declared gestures is exercised with a context whose `type` has been moved off the declared name (`'tap'`, a real recognizer name that is no spec gesture's declared name). That drift is precisely the condition the card says a rename on either vocabulary creates, so it is how the quiet arms are made to speak. Without it, `pinch` and `rotate` pass identically on defect and fix; 3. **the writing order, read off the hook's source** — every `fallback(...)` payload is brace-matched out of `useSpecGesture.ts` and the spread is required to precede `type`. This is the part that answers the triage's 「否则第四处会以同样方式长出来」: a behavioural pin only guards arms somebody thought to list, this one guards the shape. It carries its own non-vacuity checks — the brace matcher must account for every `fallback(` call it finds, and at least one payload must actually spread — so a scanner that silently stops matching reds instead of going quietly green. The behavioural rows are also a completeness pin: the row set is compared against `SPEC_GESTURE_TYPES`, so a new spec gesture cannot be added with a switch arm and no row. ## Shown RED before the repair The pin was run against the unrepaired hook, then again after the fix was committed, with the mutation and the restore both proved by `git hash-object` against recorded blob hashes rather than by an exit code. | leg | on-disk `useSpecGesture.ts` blob | result | |---|---|---| | without the fix | `489483d9dbb37431c3fc04bb4b7e2ea439f292d0` (the `origin/main` blob) | **6 failed, 35 passed (41)** | | with the fix | `3dde33fc1cc89ed17dc7e60dce9dafa8575ebfd2` (this branch's HEAD blob) | **41 passed (41)** | The six that go red are the whole defect and nothing else — the live instance, the four drifted-context arms, and the shape pin: ``` × a declared `drag` reports 'drag', not the recognizer's 'pan' × pinch × pan × drag × rotate × spreads the recognizer context BEFORE writing `type`, at every site ``` with the two discriminating readings: ``` AssertionError: the DECLARED spec gesture — this is the one arm where the two vocabularies disagree: expected "vi.fn()" to be called with arguments: - "type": "drag" + "type": "pan" ``` ``` AssertionError: `type` goes LAST: ... expected [ … ] to deeply equal [] + [ + "{ type: 'pinch', ...ctx }", + "{ type: declared, ...ctx }", + "{ type: 'rotate', ...ctx }", + ] ``` `swipe`, `long_press` and `double_tap` pass on both sides and are kept anyway: the first is the arm PR objectstack-ai#9689 already repaired and the other two spread nothing, so none of the three can tell the two implementations apart. Said here rather than left for a reader to discover. The suite imports the hook by a RELATIVE source path from inside its own package, so the mutated file is unambiguously the one under test — no `dist` and no vitest alias sits between them. ## The fourth file, and why it is there `packages/mobile/tsconfig.test.json` gains `"types": ["node"]`. The shape pin reads the hook's own source, and this package's test project named no `types`, so `node:fs` did not resolve (`TS2591`). Twenty-five sibling packages already declare it the same way, `packages/types` for the same reason (its re-export guard's `readFileSync`). Naming `types` switches off automatic `@types/*` inclusion, so the list is deliberately complete: these suites import no ambient matcher package. `tsc -p packages/mobile/tsconfig.test.json --listFiles` confirms the new test really is a program input rather than silently excluded. ## Adjacent, deliberately untouched `SPEC_GESTURE_TYPE_MAP.swipe` is still `'swipe-left'` as a declared placeholder. Changing an exported map's VALUE is a published-surface change no card has ruled on, and this branch does not touch those lines. ## Verification Run at `f38da33`. | check | result | |---|---| | `pnpm exec vitest run packages/mobile/` | exit 0 — 5 files, 41 tests passed | | `pnpm --filter @object-ui/mobile type-check` | exit 0 (`tsc --noEmit` + `tsc -p tsconfig.test.json`) | | `pnpm --filter '@object-ui/mobile^...' build` | exit 0 | | filtered build for the doc gates (35 tasks) | exit 0 | | `node scripts/check-changeset-presence.mjs` | exit 0 — 2 published source files, 1 changeset | | `node scripts/check-changeset-no-major.mjs` / `-overwrite.mjs` / `-claims.mjs` | exit 0 | | `node scripts/check-pending-changeset-literals.mjs` | exit 0 | | `node scripts/check-vi-mock-specifiers.mjs` / `-inherit.mjs` / `-override-shape.mjs` | exit 0 | | `node scripts/check-test-path-roots.mjs` | exit 0 | | `node scripts/check-control-bytes.mjs` | exit 0 | | `node scripts/check-new-cross-file-line-citations.mjs` | exit 0 — 0 new citations | | `node scripts/check-doc-example-types.mjs` / `-snippet-types.mjs` / `check-readme-exports.mjs` | exit 0 (on the built tree) | | `node scripts/check-type-check-coverage.mjs` · `check-published-tsconfig-tooling-exclude.mjs` · `check-phantom-dependencies.mjs` · `check-unreferenced-sources.mjs` · `check-doc-fence-languages.mjs` | exit 0 | | `node scripts/check-governed-queue-guard.mjs --test` (4 paths) | NOT GOVERNED | Every exit code was redirected to a file and read from there, never through a pipe. **ESLint is a declared narrowing, not a skip.** `pnpm exec eslint packages/mobile --format json` at `f38da33`: 21 files judged, 0 errors, 18 warnings, none of them in either file this branch writes. The narrowing is safe to make because this repo's flat config extends `tseslint.configs.recommended` with no `parserOptions.project` and no `projectService` — type-aware linting is off, so a file's verdict is a function of its own bytes and the shared config alone, and this branch adds no config, no shared file ESLint reads and no disable directive. It therefore cannot move the verdict of any file it does not touch. The repo-wide `pnpm lint` and the full sharded suite remain CI's. Heavy runs were serialized through the shared verify lock. --- _Generated by [Claude Code](https://claude.ai/code/session_018HrVaotisyhgmot9o2MLRq)_ Co-authored-by: Claude <noreply@anthropic.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Part of #7974
Executes the maintainer ruling of decision batch #70 (issue comment
5565631072, verbatim 「同意」):SwipeGestureConfig.directionstays as declared, and the implementation aligns to it — the swipe fires when the detected direction is a member of the declared set, the scalar branch with itsas stringcast is removed (AGENTS.md #0.1), and the shipped@examplemoves to the array form. Both halves, one change.Half 1 — the
@exampleBefore:
After:
Half 2 — the lenient cast, removed with nothing in its place
Three separate leniencies lived in those four lines: a scalar admitted through a cast that the declared array type rejects;
direction[0], which honours one element of a declared many; and a?? 'swipe-left'default that recognized a direction nobody declared. All three are gone and none is replaced.What replaces them reads the set as a set. Recognition is the any-direction move past the threshold — the recognizer
useGesturealready implements — and the callback fires only when the detected direction is a member ofconfig.swipe.direction:This does not collapse
swipeintopan:panfires for every direction,swipefires for the declared members only. Sharing the recognizer is what lets one configuration honour several directions at once, which a direction-fused recognizer cannot do by construction.Three consequences worth reading as behaviour changes rather than refactors, all of them the ruling applied:
direction: ['left', 'up']used to fire on a left swipe only.swipesub-object now fires for nothing, where it used to fall back to a left-swipe recognizer.onGesturefallback payload now reportstype: 'swipe'— the spec gesture — where it used to report the recognizer's own name. The recognizer'stypetravels inside the context object at runtime, so the previous spread order let it overwrite the declaredtype; with the shared recognizer it would have saidpan.typenow goes last. Pinned.SWIPE_DIRECTION_MAP(direction to recognizer) is deleted with its last caller. TheSPEC_GESTURE_TYPE_MAPentry forswipeis unchanged in value and its comment now says what it is: a placeholder, because no single recognizer name carries "a set of directions". That map's own JSDoc, which routedswipethrough the deleted map, is repaired in the same edit.The precondition: scalar callers = 0, with a firing control
The ruling asked for the count and for a probe demonstrated to find a scalar caller when one exists. Both numbers:
The probe walks 5,354 files under
packages/,apps/andexamples/, matches everyswipe: { ... }literal plus every.swipe.direction =assignment, and classifies the value by shape. The firing control planted one file containingswipe: { direction: 'right', threshold: 80 }, proved it reached disk with agrep -c, and the probe's SCALAR score moved 1 to 2 and named the planted file. The control file was then removed and the worktree proved clean before the count was taken again.The one pre-fix SCALAR was the
@examplethis card repairs — not a call site. So: zero scalar callers, and the zero is a reading of the tree, not of the pattern.The probe's blind spot, closed by hand rather than assumed away: a
SwipeGestureConfigbuilt as a standalone annotated literal is invisible to aswipe:block pattern. A census of everySwipeGestureConfigmention under those three roots returns the interface declaration, two type re-exports, four CHANGELOG paragraphs, and — after this change — the deliberate rejection case in the new test. No annotated literal anywhere else.The membership test
packages/mobile/src/__tests__/spec-gesture-direction-set.test.tsx, five pins, run against the realuseGesturethrough synthetic touch events, because the recognizer choice and the membership filter are two halves of one behaviour and mocking the recognizer pins only the half that lives in the hook:@ts-expect-erroron a scalardirectionThat last one is a type-level pin and it is really checked:
packages/mobile'stsconfig.test.jsonincludes the file (confirmed with--listFiles) and resolves@object-ui/typesthrough the built declaration, not through source. Control run, with the directive stripped:the same code the
@exampleledger row used to declare, now pinned as an expected rejection.Ablation
Fix committed first, then
packages/mobile/src/useSpecGesture.tsrestored to its pre-change blob, both legs verified bygit hash-objectagainst the recorded blob hashes rather than by an exit code.SWIPE_DIRECTION_MAP4, scalar example 1,declaredDirections0SWIPE_DIRECTION_MAP0, scalar example 0,declaredDirections2The four that go red without it:
with the discriminating failure reading:
"does not fire for a direction the set does not declare" passes on both sides and is kept anyway: the pre-fix recognizer refused a non-member for the wrong reason (it was fused to one direction), so that assertion cannot tell the two implementations apart. Said here rather than left for a reader to discover.
The
@examplegate's ledger row is RE-DERIVED, not deletedscripts/check-doc-example-types.mjsalready compiles this block, and its row for it said "Delete this row when that card lands". That instruction is falsified by measurement. The repair pays off the row's TS2322 half; the block still returns outside any function, so TS1108 remains and the block is still a fragment by shape — exactly the row the two other hook-body excerpts in this package carry. Deleting the row would have turned the block into an undeclared failure, which is red for a different reason. The row is nowcodes: [1108],card: null, with the siblings' wording; the gate's own header paragraph, which described the card as open, is rewritten to record what actually happened. The gate agrees:pnpm check:doc-examplesexits 0, "Every covered@examplecompiles, or fails exactly as its ledger row declares."Verification
pnpm exec vitest run packages/mobile/pnpm exec vitest run scripts/__tests__/check-doc-example-types.test.ts--build-filter, 35 tasks)pnpm check:doc-examplespnpm check:doc-snippetspnpm --filter @object-ui/mobile type-checknode scripts/check-changeset-presence.mjsnode scripts/check-new-cross-file-line-citations.mjsnode scripts/check-control-bytes.mjsnode scripts/check-governed-queue-guard.mjs --test(6 paths)eslintover the six changed filesBuild and gates ran serialized through the shared heavy-verify lock; the repo-wide
pnpm lintand the full suite are CI's.Changeset
Followed the gate rather than guessed.
node scripts/check-changeset-presence.mjsscored two published source files of one released package and refused the change without a declaration;.changeset/7974-swipe-direction-honours-declared-set.mddeclares@object-ui/mobile: minor(nevermajor— fixed group) and the gate now exits 0. The body states the two breaking narrowings and records that the caller scan found none to migrate.Scope
The declared type is untouched —
packages/types/src/mobile.tshas no edit in this diff, per the ruling and around live work in that file. No gate for JSDoc@exampleblocks was built: one already exists and this change only re-derives its ledger row. Clause ②:no—^\+exportscores 0 over the diff and no key is added to any published payload.Generated by Claude Code