@vectorvesper/motion/reactReact · Interaction Priority Engine

InteractionScope

Under frame pressure, background particle fields and ambient animations compete with active touch gestures and drags. InteractionScope prioritizes the user's active viewport region, shedding non-essential background tasks first so active manipulation remains locked at display refresh rate.

The InteractionScope component establishes a spatial execution lease across the FrameConductor. When a user interacts with a scoped region (via touch or pointer press), all frame subscribers rendered within that subtree inherit the active lease automatically.

When the conductor experiences frame budget pressure, non-essential work outside the active scope yields earlier, preserving spare frame time for the direct manipulation interaction. On healthy frames running within budget, execution order is untouched.

The component manages three activation modes: "pointer" (uncontrolled DOM capture listener that activates while a pointer is pressed inside), true (controlled programmatic lease for keyboard-driven cameras or open modal dialogs), and false (disabled).

Interaction Priority & Background Work Shedding

Demo loads on scroll

Quick start

Wrap any interactive component or canvas in an InteractionScope. Child useTick callbacks inherit scope priority automatically.

Pointer press detection uses native DOM capture-phase listeners, functioning reliably even when child components call stopPropagation().

Priority Bands & Shedding Thresholds

How the FrameConductor adjusts subscriber execution order and shedding thresholds when a scope is active.

Priority BandDefault ThresholdOutside Active LeaseExecution Behavior
"essential"Never shedNever shedDirect input listeners, core gestures, and physics state integration.
"enhanced"0.70 budget0.45 budgetSecondary transforms and interactive hover effects.
"decorative"0.45 budget0.20 budgetAmbient floating particles, blur passes, and background meshes.
Pointer Capture Phase Architecture

Native pointer down listeners attach in the capture phase. This guarantees activation occurs before child drag libraries intercept or stop event propagation. Drag completion is monitored on the global window, ensuring release triggers correctly even if the cursor leaves the element bounding box mid-drag.

API Reference

Syntax

Establishes a scoped region for interaction priority across all child useTick subscribers.

Parameters

Parameters.fieldTypeDefaultDescription
labelstringundefinedHuman-readable label displayed in DevTools inspectors and performance telemetry.
active"pointer" | boolean"pointer""pointer" activates automatically on pointerdown; true holds active continuously; false disables.
asChildbooleanfalseClones the single child element and attaches event listeners directly without rendering a wrapper div.
classNamestringundefinedCSS class names applied to the container element when asChild is false.
styleCSSPropertiesundefinedInline styles applied to the container element when asChild is false.

useInteractionScope()

useInteractionScope().fieldReturn ValueTypeDescription
scopeIdstring | nullOpaque ID of the nearest enclosing InteractionScope, or null outside providers.

useTick(lane, fn, options?)

useTick(lane, fn, options?).fieldTypeDefaultDescription
priority"essential" | "enhanced" | "decorative""enhanced"Shed order under frame pressure.
hznumberDisplay rateMaximum execution cadence in Hertz. Unexecuted dt is preserved.
labelstring"anonymous"Diagnostic label for DevTools.
backgroundbooleanfalseWhen true, opts out of surrounding scope protection to yield with ambient work.
enabledbooleantrueConditionally attach or detach the subscription.

Scope Lifecycle & Subscription Management

InteractionScope automatically detaches DOM listeners and releases conductor claims on component unmount.

1. Declarative Component ScopeAutomatic Provider Teardown
2. Imperative Conductor ClaimDirect Lifecycle Control

Lifecycle & Invariant Guarantees

  • Zero impact on healthy frames: On pages operating within the display frame budget, InteractionScope introduces zero execution delay or priority alterations.
  • Capture-phase reliability: Pointer listeners attach on the DOM capture phase, guaranteeing activation even when child gestures call stopPropagation.
  • Multi-touch tracking: Pointers are tracked by pointerId, ensuring active priority is retained until the final active finger lifts from the surface.
  • Automatic child inheritance: All useTick calls rendered within the subtree join the scope automatically without requiring manual property passing.

Production Examples

Battle-tested production patterns ready to copy directly into your codebase.

Protect gallery swipe gestures while allowing ambient background animations to yield under load.

When NOT to use this

The page is bottlenecked on heavy GPU fragment shaders.
→ instead Use AdaptiveQuality. InteractionScope reorders JavaScript subscriber execution; it cannot recall draw calls already submitted to the GPU.
There is only one animated element on the page.
→ instead Render directly. Task reordering only applies when there is competing runtime work that can yield.
Coordinating animations driven by external third-party libraries.
→ instead InteractionScope coordinates tasks registered on the FrameConductor. External loops run outside this scheduler.

Rules & Gotchas

  • Render interactive subscribers within the provider: Frame subscribers rendered inside InteractionScope inherit its protection automatically without manual prop wiring.
  • Prioritize direct manipulation gestures: Keep physical drag handlers essential, allowing decorative secondary effects to remain enhanced or decorative so they can yield.
  • Release imperative claims immediately on gesture completion: When manually managing active claims with getConductor().claimScope(), ensure release() is called as soon as interaction finishes.
  • Use asChild to preserve layout integrity: Pass asChild when wrapping items in CSS grid or flex containers to avoid introducing unnecessary wrapper div elements.

Related Motion Components