Skip to content

chore(core): useTouchLayer runs a touch layer only under a coarse pointer - #8518

Closed
vjeux wants to merge 50 commits into
meta:mainfrom
vjeux:uikit/touch-support-module
Closed

vjeux wants to merge 50 commits into
meta:mainfrom
vjeux:uikit/touch-support-module

Conversation

@vjeux

@vjeux vjeux commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review only this PR's change: vjeux/astryx@aaf573b...c03f33e

Why

Components that grow touch behavior need one place that decides when it may run: only for a touch presentation, under a coarse primary pointer and after hydration (spec:AST-094 FR13), so people on a mouse or trackpad keep exactly what they have today (spec:AST-017 FR59). Without it, each component reads the pointer itself, and one slip attaches touch listeners under a fine pointer or during hydration.

What led to it

This began as TouchSupport.install(), a module apps installed to gather the touch code. In review the design changed: there is no install step, and components import the touch code they use directly. What remains is the lifecycle their touch glue shares: an internal hook, useTouchLayer, and the pointer registry behind it. The open review asks the coarse-only rule to cite FR13 and FR59 instead of FR19, which since FR43 lets gestures attach for every pointer; an offer in the comments makes that change.

Options and tradeoffs

  • Each component reads (pointer: coarse) itself: no shared code, but every component repeats the hydration and pointer-change handling.
  • An install step that registers a touch module (the first design): one switch for apps, but an extra setup call and a bundling contract to keep.
  • One internal hook over a shared registry (this pull request): the rule lives in one place, and the pointer is followed once, only while a layer is mounted.

Why this choice

It keeps fine-pointer behavior unchanged by construction, which FR59 asks of touch work, and it applies FR13's rule for when a touch presentation runs. Nothing uses the hook yet, so nothing a consumer sees or bundles changes; components adopt it as their touch presentations land.

How to check it

  1. Run pnpm exec vitest run --project ui packages/core/src/touch-support: 11 tests pass. They cover:
    • a fine pointer: nothing is set up and no input listener is attached;
    • a coarse pointer: setup runs once with the element and cleans up on unmount;
    • the pointer turning coarse after the first render (setup, no remount) and fine again (cleanup);
    • a new element: the old one cleans up before the new one sets up;
    • a hidden Activity revealed after the pointer turned fine: nothing is set up;
    • one pointer listener for any number of layers, removed after the last;
    • StrictMode keeping one layer attached, and nothing running on the server.
  2. To see the guard bite, make isTouchLayerActive return true: 5 of the 11 fail, the fine-pointer test among them.

Evidence

  • The three files: touch-support/useTouchLayer.ts, touch-support/touchSupportRegistry.ts, touch-support/useTouchLayer.test.tsx.

vjeux added 10 commits October 25, 2026 16:38
A build that defines __ASTRYX_TOUCH__ as false presents every component the pointer way and leaves out each touch layer imported through the guard touchLayers.ts documents. Without the define nothing changes. The browser support guide covers the build settings, device routing and the Next.js caveat.
…aved draft

The section's last sentence ended on "saves", which matches "saved" in the main searcher's "toast notice for a saved draft" query. The section took the 20th result from a shorter doc and grew that answer past the lexical ranker's, which the main searcher's byte check rejects. The sentence now ends on "is worth"; a guard test pins that the guide is found for its own topic and not for that query.
…ind it through one internal hook

@astryxdesign/core/touch-support exports TouchSupport: install() (idempotent, a no-op on the server, adds no listeners) and isInstalled(), nothing else. The module (main's gesture core; the animator joins it) sits in one module-level registry that components read only through the internal useTouchSupport hook, null on the server and until installed. Lint keeps the internals to Core and Lab, and the exports map holds only the public entry. A bundle test pins that core's root, hooks and utils entries and a component reading the hook carry none of the module, and that an install carries it. Replaces this branch's __ASTRYX_TOUCH__ define, resolver change and guide section, which the install makes unnecessary.
CI-Rerun: one RTL story navigation timed out in pr-rtl (core 2/3) of run 40273227303; it does not reproduce at this tree.
…ere a coarse pointer is present

install() registers the module now where some input is a coarse pointer (any-pointer: coarse), and otherwise waits on that query's change event, registering once a coarse pointer appears (a tablet attached to a laptop), so a page used only with a mouse registers nothing. isInstalled() reports whether install() ran. The doc comment says layout and presence motion works without it. Tests cover a fine-pointer page and one that gains a coarse pointer later.
…sture core

Core's root, hooks and utils entries are checked to carry none of the touch module (touch-support/touchModule.ts) until an app installs TouchSupport: an entry that imports the module, directly or through TouchSupport, still fails. Whether an entry carries the gesture core itself is a separate check, held until components have moved onto the module, so this check does not fail a component that still imports a recognizer directly. Glue on useTouchSupport is still checked to carry neither the module nor the gesture core.
…d shared tables; useTouchLayer runs a one-element layer

touchModule gains the pan recognizer and velocity tracker, the spring, decay, projection and rubber-band math, the motion roles, and the shared UIKit tables, so a component's touch glue takes every primitive it needs off the installed module. useTouchLayer(ref, setup) runs a one-element layer's setup once the module is installed and the element is mounted, re-runs it only when either changes, and cleans up on unmount; resetTouchSupportForTests() forgets an install, and the install-ran flag moves into the registry so it does too. The bundle test checks that glue on either hook carries none of the gesture core or motion math, and that the install entry carries all of it.
…n a story without it

Storybook's preview installs TouchSupport before any story renders, as an app's client entry does, unless the URL global touchSupport:off turns it off. The interaction harness's openStory takes OpenStoryOptions {touchSupport: false} to set it, building the globals as key:value pairs, so a browser spec can check a component's plain behavior.
@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 28, 2026 4:12pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟡 Reviewed (for maintainers only) Oct 28, 2026, 4:25 PM UTC

CI-Rerun: Vercel's deployment of 1a0c61d failed on Vercel's side; that head changed only a test file, and the branches pushed in the same second deployed.
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

Gzip figures measure each package's entry file, not the code an import pulls in.

Package Entry (ESM) Entry gzip before Entry gzip after Delta
@astryxdesign/core 4.9KB 1.2KB 1.2KB 0B
Package stylesheet Gzip before Gzip after Delta
@astryxdesign/core 35.4KB 35.4KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 26, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approval waits on an engineering owner's spec decision: the public @astryxdesign/core/touch-support entry and its page-level touch module follow architecture:react-component-runtime INV13, which is not on main yet and is only proposed in #8464. An engineering owner can settle it by landing INV13 or by commenting /approve-spec <full head SHA> on this pull request (the author may do so too if they are an engineering owner), and that decision should say whether install() may still ship the module's code to mouse-only pages. Whatever the decision, please address:

  • The changeset and TouchSupport's doc say people using only a mouse pay nothing, but the static touchModule import ships about 13.2 KB gzip with every page that imports TouchSupport.
  • resetTouchSupportForTests() leaves an earlier fine-pointer install's media-query listener attached, so a later coarse pointer registers the module while isInstalled() is false.
  • useTouchLayer does not follow an element that a child swaps without the host re-rendering.

[Automated review]

Comment thread .changeset/touch-support.md Outdated
'@astryxdesign/core': patch
---

[feat] `@astryxdesign/core/touch-support` exports `TouchSupport`, the one install for the global touch and gesture module. Call `TouchSupport.install()` once in your client entry, before you render or hydrate. It registers the module only where some input is a coarse pointer, or once one appears, so people using only a mouse pay nothing. It can be called more than once, does nothing on the server, and `TouchSupport.isInstalled()` reports whether it ran. A page that never installs it carries none of the module and keeps every component's current behavior. Components take their touch behavior from the module in their own releases.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This says people using only a mouse pay nothing, but touch-support/index.ts imports touchModule statically, so every page that imports TouchSupport ships the whole module (about 13.2 KB gzip with the size report's esbuild options) whatever its pointer; only registration waits for a coarse pointer. Wording that says what holds would avoid misleading app authors, for example that it registers nothing for people using only a mouse while the module's code still ships with the entry that imports it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reworded through #8465's doc fix, merged here in ce1641a: the module's code ships with the entry that imports it, and only registration waits for a coarse pointer.

* keep their plain behavior and stay fully usable, and a tap still acts as
* a click.
* - Layout and presence motion works without it.
* - People using only a mouse pay nothing: `install()` registers the module

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same claim as the changeset: the static import {touchModule} from './touchModule' on line 14 puts the module in any bundle that imports TouchSupport, so mouse-only visitors download it; only registration is skipped.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The doc says so now (ce1641a): the module's code ships with this entry, so a page that imports it sends that code to every visitor, one using only a mouse included.

* Forgets the install, as on a fresh page, and tells every reader. For tests
* only; it is not on `TouchSupport`.
*/
export function resetTouchSupportForTests(): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This clears ran and the module, but an earlier install() on a fine-pointer page keeps its (any-pointer: coarse) change listener (index.ts lines 66-72). If a coarse pointer appears after the reset, the module registers while isInstalled() is false. Keeping the pending listener where the reset can remove it, plus a fine-pointer reset test, would give the fresh page the doc promises.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 8b0ca63: the registry keeps the waiting registration's cancel, and the reset calls it. A new test installs on a fine-pointer page, resets, then adds a coarse pointer: no listener is left, nothing registers, and isInstalled() stays false. It fails without the fix.

// After every render: attach, detach, or move to a new element. Comparing
// the module and the element keeps a re-render from setting up again.
useIsomorphicLayoutEffect(() => {
const element = ref.current;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ref.current is read only after the host renders, so if the ref sits on an element a child swaps through its own state, the new element never gets the layer and the detached one keeps it until unmount. Either document that the ref must be on an element the host renders, or return a callback ref that owns attach and replacement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Documented in 8b0ca63: the ref goes on an element its own component renders, and an element a child replaces through its own state needs the hook in that child.

vjeux added 3 commits October 26, 2026 06:08
The module holds the gesture core and no component uses it yet; the module's code ships with the entry, so a page that imports it sends that code to every visitor, and only registration waits for a coarse pointer. The doc no longer promises an animator, components' touch behavior or Reduce Motion handling, which arrive in later releases.
…ng for a coarse pointer; useTouchLayer says where its ref goes

An install on a fine-pointer page waits with one (any-pointer: coarse) change listener. The reset left it attached, so a coarse pointer appearing after a reset registered the module while isInstalled() read false. The registry now keeps that registration's cancel, and the reset calls it. useTouchLayer follows its ref's element after each render of its own component, so its doc says the ref must be on an element that component renders. TouchSupport's doc names the motion functions the module now carries.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approval waits on an engineering owner's spec decision: the public @astryxdesign/core/touch-support entry and its page-level touch module follow architecture:react-component-runtime INV13, which is not on main yet and is only proposed in #8464, and making component touch behavior wait for an app's install departs from spec:AST-094's "without an opt-in" until that proposal is adopted. An engineering owner can settle it by landing INV13 or by commenting /approve-spec <full head SHA> on this pull request (the author may do so too if they are an engineering owner), and that decision should say whether install() may keep shipping the module's code to mouse-only pages, because the draft says such a page "loads nothing" and asks the docs to promise mouse-only visitors "pay nothing", while this branch documents the opposite. The earlier points about the changeset wording, the test reset and useTouchLayer's ref are addressed, and no other code change is needed.

[Automated review]

@cixzhang

Copy link
Copy Markdown
Contributor

Posted by Cindy's agent on her behalf.

Thanks, vjeux. Cindy has simplified the touch model: there's no install step. The gesture and touch code is a set of reusable internal modules that components import directly, and the bundler keeps one copy per page. That replaces TouchSupport.install().

  • No public touch-support entry, and no install() or isInstalled(). An internal test reset is still fine.
  • Under a mouse or another fine pointer, nothing attaches listeners (spec:AST-094 FR19 and FR24 are unchanged).
  • Lab components reach the same modules through Core's internal subpaths (@astryxdesign/core/internal/touch and similar).

What this means per PR:

If these stay idle, we'll make the changes after about 30 minutes, keeping your authorship on the commits.

…ntry

@astryxdesign/core/internal/touch exports useTouchSupport and the touch module's type, so a Lab component reaches the module the way a Core component does. Like every internal entry, it is undocumented, outside the public API, and allowed by lint only in Core and Lab, which now refuses @astryxdesign/core/internal/* elsewhere in place of the old touch-support/* ban. sync-exports lists it with the other file subpaths. A component that reads the module through it still carries none of the gesture core.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approval waits on an engineering owner’s spec decision: the new @astryxdesign/core/internal/touch entry exports a gesture and motion module that spec:AST-017 FR21 on main says is never exported and that architecture:public-component-api INV12 treats as public once reachable, and the bundle test rules out the lazy import() that architecture:component-style-authoring INV6 and spec:AST-080 DEC-4 still allow. #8464, which updates those records, has an engineering owner’s approval on its head but is not merged yet, so an engineering owner can settle this by landing #8464 or by commenting /approve-spec <full head SHA> on this pull request (the author may do so too if they are an engineering owner). Whatever the decision, one fix is needed in touchSupportRegistry.ts: readPointer() caches the (pointer: coarse) answer even when no layer is subscribed, so a layer first rendered inside a hidden <Activity> keeps a stale answer and can attach under a fine primary pointer (spec:AST-094 FR19); reading the query’s live matches instead of a cached boolean, with a test for that case, fixes it.

[Automated review]

Comment on lines +44 to +53
function readPointer(): boolean {
if (isCoarse === null) {
query =
typeof window === 'undefined' || typeof window.matchMedia !== 'function'
? null
: window.matchMedia(TOUCH_QUERY);
isCoarse = query?.matches ?? false;
}
return isCoarse;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

readPointer() caches isCoarse on any read, but only subscribeTouchModule adds the change listener. A render whose effects never run, such as a layer inside a hidden <Activity>, leaves an answer nothing updates: if the pointer turns fine before the layer shows, it sets up with the module under a fine primary pointer (spec:AST-094 FR19) and stays attached until the pointer changes again, and the coarse case gets no setup. Since the snapshot is only ever the frozen module or null, reading the query live removes the stale path:

function readPointer(): boolean {
  query ??=
    typeof window === 'undefined' || typeof window.matchMedia !== 'function'
      ? null
      : window.matchMedia(TOUCH_QUERY);
  return query?.matches ?? false;
}

A hidden-<Activity> case in useTouchLayer.test.tsx would pin it.

useSyncExternalStore reads the snapshot on renders no commit follows (a
layer first rendered in a hidden Activity), before anything subscribes.
The registry kept that answer, so after the pointer changed a layer could
attach under a fine primary pointer (spec:AST-094 FR19). A read with no
subscriber now asks the media query afresh and keeps nothing; the first
subscriber reads and follows it. The new test fails on the previous head.

Co-authored-by: Christopher Chedeau <[email protected]>

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approval waits on an engineering owner's spec decision: the new @astryxdesign/core/internal/touch entry exports a gesture and motion module that spec:AST-017 FR21 on main says is never exported and that architecture:public-component-api INV12 treats as public once reachable, and the bundle test rules out the lazy import() that architecture:component-style-authoring INV6 and spec:AST-080 DEC-4 still allow. #8464 updates those records but is not merged, so an engineering owner can settle this by landing #8464 or by commenting /approve-spec <full head SHA> on this pull request (the author may do so too if they are an engineering owner). The registry change fixes the earlier stale-pointer problem and no other code change is required; re-reading the pointer in useTouchLayer's attach effect would also remove one setup and cleanup that can still run when a hidden <Activity> is shown under a fine pointer.

[Automated review]

Comment on lines +7 to +8
* banding) and the motion roles; no UIKit table, since a component imports
* only the rows it uses (architecture:component-style-authoring INV6)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The module lists no UIKit table itself, but its members read UIKit rows, and because touchModule is one frozen object an adopter carries all of them: an internal/touch import holds 425 B of motion/uikit/gestures.ts (the tap, long-press, pan and velocity rows) and 219 B of motion/uikit/scroll.ts, where a tap recognizer imported directly holds 179 B of gesture rows and no scroll table. So "a component imports only the rows it uses" holds for direct imports, not for a component that adopts this module (architecture:component-style-authoring INV6's table-rows sentence).

Comment on lines +68 to +79
useIsomorphicLayoutEffect(() => {
const element = ref.current;
const attached = attachedRef.current;
if (attached?.touch === touch && attached.element === element) {
return;
}
attached?.cleanup();
attachedRef.current =
touch !== null && element !== null
? {touch, element, cleanup: setupRef.current(touch, element)}
: null;
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One case still runs the layer under a fine pointer: a layer first rendered inside a hidden <Activity> while the pointer was coarse, shown after it turned fine without re-rendering, gets one setup and one cleanup during the reveal, because this effect uses the hidden render's snapshot until React's post-subscribe check re-renders. Nothing stays attached. Re-reading the answer here removes it, and the existing tests still pass:

const live = touch === null ? null : getTouchModule(); // the pointer now, not at render

then use live in place of touch for the comparison and the setup.

cixzhang and others added 3 commits October 26, 2026 15:27
The attach effect used the render's snapshot, so a layer rendered in a
hidden Activity under a coarse pointer and shown after the pointer turned
fine ran one setup and cleanup during the reveal (spec:AST-094 FR19). The
effect now reads the pointer itself. A reveal test covers the case (jsdom
does not reproduce the stale snapshot, so it passes before and after).

Co-authored-by: Christopher Chedeau <[email protected]>
…ith no gathering object

architecture:component-style-authoring INV6 (UIKit tables ship only the
rows a component uses) and the maintainer's direction that internal
modules are imported statically, each with one job, with no grab-bag
object: a frozen touchModule made every adopter carry every member it held,
and the rows they read. internal/touch now re-exports the gesture core's
primitives by name, so a bundler keeps one copy per page and only what a
component uses; touch-support/touchModule.ts goes. The entry test moves to
internal/touch.test.ts and checks the named re-exports, no gathering object
and no listeners on load; the bundle test imports GestureArena by name.

Co-authored-by: Christopher Chedeau <[email protected]>
… useTouchLayer

Rebuilt on meta#8465's direction (architecture:component-style-authoring INV6;
each module one job, imported statically): there is no touchModule object,
so this PR drops its gathering too and keeps only useTouchLayer and its
registry. A layer's setup gets the element alone and imports the touch
modules it uses itself; the registry answers whether a layer runs now
(isTouchLayerActive: the primary pointer is coarse), with
resetTouchSupportForTests kept as the internal test reset. The pointer
read, the Activity re-read and the fine-pointer tests are unchanged.

Co-authored-by: Christopher Chedeau <[email protected]>
@cixzhang cixzhang changed the title chore(core): the touch module gathers the shared touch primitives; useTouchLayer runs a layer under a coarse pointer chore(core): useTouchLayer runs a touch layer only under a coarse pointer Oct 26, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approval waits on an engineering owner's spec decision: the new @astryxdesign/core/internal/touch entry exports Core's gesture core, which spec:AST-017 FR21 on main says is never exported and architecture:public-component-api INV12 treats as public once reachable, and the bundle test bans the lazy import() that architecture:component-style-authoring INV6 and spec:AST-080 DEC-4 still allow. #8464 updates those records and carries an engineering owner's approval for its own head but is not merged, so an engineering owner can settle this by landing #8464 or by commenting /approve-spec <full head SHA> on this pull request (the author, an engineering owner, may do so too). useTouchLayer itself needs no change; one suggested test fix: the hidden-<Activity> test in useTouchLayer.test.tsx still passes with the attach-time pointer re-read removed, because its rerender renders Layer again, and revealing a memoized Layer through parent state makes it catch that.

[Automated review]

);
turn(false);
await act(async () => {
view.rerender(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This passes even with the attach-time re-read at useTouchLayer.ts:70 removed (const live = isActive;): this rerender renders Layer again, and that render already reads the fine pointer. The re-read matters when the reveal does not render the layer again. Revealing a memoized layer through parent state covers that case, passes on this head and fails without the re-read (memo and useState join the react import):

const turn = primaryPointer(true);
const {setup, Layer} = recorder();
// Memoized, so the reveal shows the hidden render without rendering again.
const Hidden = memo(Layer);
let show: (visible: boolean) => void = () => {};
function Host() {
  const [visible, setVisible] = useState(false);
  show = setVisible;
  return (
    <Activity mode={visible ? 'visible' : 'hidden'}>
      <Hidden />
    </Activity>
  );
}
render(<Host />);
turn(false);
await act(async () => {
  show(true);
});
expect(setup).not.toHaveBeenCalled();

… the layer again

The reveal test rerendered the layer, and that render already read the
fine pointer, so it passed without the attach-time re-read. A memoized
layer revealed through its parent's state shows the hidden render as it
was; the test now fails when the effect uses the render's answer.

Co-authored-by: Christopher Chedeau <[email protected]>

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes requested for one test gap: the code matches the current spec now that INV13 has landed with #8464, but no test fails if the touch-layer registry keeps its media-query listener after the last layer unmounts, if one layer's unmount stops the others following the pointer, or if a moved layer sets up its new element before cleaning up the old one, which architecture:component-test-sufficiency INV2 and INV6 require tests to catch for cleanup and lifetime. A two-layer test that counts the stubbed media-query listeners and turns the pointer after the first unmount, plus one that records setup and cleanup order, would close it. Optionally, adding internal to no-core-internal-import's source-path pattern would also report a relative import of packages/core/src/internal/touch from outside Core and Lab, which currently lints clean. The description still describes the earlier TouchSupport.install() shape and could be refreshed before merge.

[Automated review]

Comment on lines +89 to +95
listeners.delete(listener);
if (listeners.size === 0) {
// Unfollowed, the read would go stale: the next layer reads afresh.
query?.removeEventListener('change', onChange);
query = null;
isCoarse = null;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No test fails if this block stops removing the media-query listener after the last layer, or runs on every unsubscribe instead of only the last: useTouchLayer.test.tsx stays green with either edit. A two-layer test that counts the stubbed listeners (one while both are mounted, zero after the last unmount) and turns the pointer coarse after the first unmount would catch both, as architecture:component-test-sufficiency INV2 and INV6 ask for cleanup and lifetime.

Comment on lines +76 to +78
attached?.cleanup();
attachedRef.current =
element !== null ? {element, cleanup: setupRef.current(element)} : null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This cleanup-before-setup order is what architecture:react-component-runtime INV6 requires, but the element-move test only counts calls, so setting up the new element before cleaning up the old one still passes. Recording the calls in order (['setup DIV', 'cleanup DIV', 'setup SPAN']) would pin it.

// their own: by package path, or by a path into Core's source.
const DEEP = [
/^@astryxdesign\/core\/(?:gestures|motion)(?:\/|$)/,
/(?:^|\/)core\/src\/(?:gestures|motion|touch-support)(?:\/|$)/,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This covers source paths into gestures, motion and touch-support but not core/src/internal, so ../../../packages/core/src/internal/touch imported from a story lints clean although it re-exports the same GestureArena. Adding internal to the alternation, with one invalid case, would close that route (not blocking: the @astryxdesign/core/internal/* subpath itself is reported).

…rder

architecture:component-test-sufficiency INV2 and INV6: two layers share
one media-query listener, the second keeps following the pointer after the
first unmounts, and the listener goes after the last; a moved layer cleans
the old element up before it sets the new one up (react-component-runtime
INV6). Each test fails when its behavior is broken (always or never
unfollowing; setting up before cleaning up).

Co-authored-by: Christopher Chedeau <[email protected]>
cixzhang added a commit that referenced this pull request Oct 27, 2026
…internal

From CodeBunny on #8518: a path into Core's source covered gestures, motion
and touch-support but not internal, so '../../packages/core/src/internal/touch'
from a story linted clean while re-exporting the same gesture core. The
source-path pattern adds internal, with an invalid case (and a valid
'core/src/internals' that must not match); the message, header and README
say so.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks ready to merge: with #8464 on main, the useTouchLayer hook, the @astryxdesign/core/internal/touch entry and its lint fence match the current touch-runtime and internal-subpath specs, and the new two-layer and ordering tests now catch the lifecycle regressions raised on the previous revision. Two optional follow-ups: adding internal to the source-path pattern in no-core-internal-import.js would also report a relative import of packages/core/src/internal/touch from outside Core and Lab, which currently lints clean, and the description below its update line still describes the earlier TouchSupport.install() design and could be refreshed.

[Automated review]

@vjeux

vjeux commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

An offer for what the review left after your e19b389:

  • Your e19b389 closes the test gap. I broke each of the three behaviors the review names (the listener kept after the last layer, unfollowing on every unsubscribe, the new element set up before the old one is cleaned up), and each fails its test.
  • The optional lint item: vjeux/astryx@e19b389...325c9fe makes no-core-internal-import report a relative path into core/src/internal as the internal subpath it is the source of, with one invalid case and a lookalike valid one. Full lint passes.
  • The description still describes install(). A refreshed one for this head is below.

Whether to take either is your call.

Refreshed description

Review only this PR's change: vjeux/astryx@3ca280f...e19b389

Depends on #8465 (merged in): internal/touch re-exports the gesture core by name.

Maintainer impact

A component's touch glue gets one lifecycle: useTouchLayer(ref, setup) runs the layer's setup with its element only while the primary pointer is coarse, and cleans it up when the pointer turns fine or the element goes. Under a fine pointer and on the server the component keeps its plain behavior and attaches no input listener (spec:AST-094 FR19). No component uses it yet.

Intended invariant

architecture:react-component-runtime INV13: touch behavior comes from one shared set of internal modules, imported statically, with no install call and no public installed check; tests reset them through an internal hook; under a fine primary pointer no touch listener is registered. INV6: a moved layer cleans the old element up before it sets the new one up.

Change

  • touchSupportRegistry.ts (internal): whether the primary pointer is coarse, read live; one shared media-query listener while any layer is mounted, removed after the last; false on the server; resetTouchSupportForTests().
  • useTouchLayer.ts (internal): runs setup(element) in a layout effect while the pointer is coarse and the element is mounted, and again only when that answer or the element changes; a new setup function alone does not run it again.

Evidence

  • Success, useTouchLayer.test.tsx (11 cases): fine and coarse pointers; a pointer that turns; a layer mounted after the last one left; a hidden Activity revealed after the pointer turned fine; a moved element, cleaned up before the new one is set up; two layers sharing one listener, the second still following after the first unmounts, the listener gone after the last; StrictMode; the server.
  • Mutations each fail a test: keeping the listener after the last layer, unfollowing on every unsubscribe, setting the new element up before cleaning the old one up.
  • Unchanged behavior: no component reads the registry yet.

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • useTouchLayer.test.tsx: 11 pass; each mutation above fails it.
  • CI=true pnpm lint: 0 errors.

@cixzhang cixzhang closed this Oct 28, 2026
@cixzhang cixzhang reopened this Oct 28, 2026
@cixzhang

Copy link
Copy Markdown
Contributor

Posted by Cindy's agent on her behalf: closed and reopened only to restart this PR's CI on the current workflow after tonight's queue-wide cancel; nothing in the PR changed.

# Conflicts:
#	eslint.config.js
#	internal/eslint-plugin-astryx/README.md
#	internal/eslint-plugin-astryx/no-core-internal-import.js
#	internal/eslint-plugin-astryx/no-core-internal-import.test.mjs
#	packages/core/package.json
#	scripts/sync-exports.js

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes requested: useTouchLayer still follows the touch rule that kept recognizers off fine pointers, and the pull request needs a Changeset. Since spec:AST-094 FR43 landed, FR19 reads "Recognizers attach for every pointer, with FR43's exceptions" and architecture:react-component-runtime INV13 says the gesture host attaches "with no touch-only query", so please either scope the hook to coarse-only jobs (FR13 touch presentations, spec:AST-017 FR59) and cite those claims instead of FR19, or drop the (pointer: coarse) gate, updating the fine-pointer test either way. Please also add a Changeset naming @astryxdesign/core, since the required lint check fails changeset coverage for touchSupportRegistry.ts and useTouchLayer.ts, and refresh the description, which still documents the removed TouchSupport.install() design.

[Automated review]

useIsomorphicLayoutEffect(() => {
// The pointer now, not at render: a layer rendered hidden (an Activity)
// under a coarse pointer and shown after it turned fine sets nothing up.
const live = isActive && isTouchLayerActive();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This gate keeps every layer off under a fine primary pointer, and the header (lines 20-22) cites spec:AST-094 FR19 for that. On main, FR19 now reads "Recognizers attach for every pointer, with FR43's exceptions", and architecture:react-component-runtime INV13 says the gesture host attaches "with no touch-only query". Either scope the hook to coarse-only jobs (FR13 touch presentations, spec:AST-017 FR59) and cite those claims, or drop the gate; the fine-pointer case at useTouchLayer.test.tsx:79 changes with it.

* Nothing is installed: components import the touch modules statically, and
* this only says whether a touch layer runs now. Under a fine primary pointer
* the answer is false, so a component keeps its plain behavior and attaches
* no input listener (`spec:AST-094` FR19). The media query is read when first

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same citation as in useTouchLayer.ts: FR19 no longer says a fine pointer attaches no input listener; since FR43 it says recognizers attach for every pointer. Cite the claim that keeps this answer coarse-only (FR13 for touch presentations), or let the layer run for every pointer.

@vjeux

vjeux commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

An offer for this review, as one commit on your head c03f33e (a fast-forward, so the branch can take it as is): vjeux/astryx@c03f33e...0b15f2f

  • useTouchLayer.ts and touchSupportRegistry.ts cite FR13 (a touch presentation applies under a coarse primary pointer, after hydration) and spec:AST-017 FR59 (touch work leaves fine-pointer behavior alone) instead of FR19, which since FR43 attaches recognizers for every pointer; the coarse gate stays, since it is what the hook is for.
  • The fine-pointer test keeps its assertions, and its name now cites those two claims.
  • An [internal] changeset names @astryxdesign/core: the changeset-coverage check fails on c03f33e and passes on this commit.

@vjeux
vjeux marked this pull request as draft October 29, 2026 22:37
@vjeux

vjeux commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Closing as requested: later decisions replaced this pull request. The branch stays.

@vjeux vjeux closed this Oct 30, 2026

This branch was successfully deployed

1 active deployment
Preview — c03f33e4 Deployed Oct 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants