solid-motion-experiments .agents solid-motion-spec.md
65 kB · 2,444 lines
Markdown
at main

Technical Specification: SolidJS Integration for Motion #

Status note

This specification is broader than the current repository implementation. It remains useful as a forward-looking integration design, but it should not be read as a statement that the repo already ships the full surface described below.

The current prototype proves a much narrower Milestone 0 slice:

  • stable motion.div and motion.create(...) wrappers
  • deterministic pre-mount style resolution
  • single-slot AnimatePresence with retained-child exit completion
  • explicit-invalidation layout probes via layoutDependency

The following names and features discussed later in this document are still aspirational or deferred in the current repo unless another file explicitly says they are implemented:

  • Presence as the primary public component name
  • LayoutGroup
  • MotionConfig
  • the wider gesture, drag, and viewport surface
  • keyed-list presence orchestration
  • the published motion/solid package layout described here

Motion currently documents first-class integrations for React, JavaScript, and Vue, so this spec treats Solid support as a new official framework integration, not as a wrapper around React Motion. Motion’s core JavaScript animate() API already supports DOM/SVG elements, selectors, values, objects, independent transforms, CSS variables, SVG paths, and sequences, which makes it a strong base for a Solid renderer. (Motion) (Motion)

Solid 1 is stable and should be the default production target. Solid 2 support should initially be experimental because Solid ecosystem guidance still notes that some third-party packages may not yet be compatible with newer SolidStart v2 work, and SolidStart maintainers have stated that Solid v2 support is still being worked through rather than fully promised as a settled target. (Solid.js Documentation) (GitHub)


1. Overview #

What the integration is #

The proposed package is a first-class SolidJS renderer and component layer for Motion:

import {
  motion,
  Presence,
  LayoutGroup,
  MotionConfig,
  createMotionValue,
  createSpring,
  createTransform,
  createReducedMotion,
  createAnimationControls,
} from "motion/solid";

It should provide:

  • Declarative animated Solid components such as <motion.div />, <motion.svg />, and <motion.path />.
  • Solid-native primitives such as createMotionValue, createSpring, and createReducedMotion.
  • Gesture props such as whileHover, whileTap, whileFocus, whileDrag, and whileInView, matching Motion’s established model where appropriate. Motion’s React docs currently expose these gesture animation props and event APIs. (Motion)
  • Layout animation support through layout, layoutId, LayoutGroup, layoutScroll, and layoutRoot, aligned with Motion’s existing layout model. (Motion)
  • Presence and exit animation support through a Solid-native Presence component equivalent in purpose to Motion’s AnimatePresence. Motion’s current React AnimatePresence keeps removed elements alive until exit animations complete. (Motion)

Who it is for #

This integration is for:

  • Solid application developers who want high-quality UI animation without switching frameworks.
  • Design systems built on Solid components.
  • SolidStart users building SSR, SSG, streaming, or hybrid applications.
  • Framework and platform teams that need stable animation APIs across Solid 1 and Solid 2.
  • Teams migrating from Framer Motion or Motion for React to Solid.

Why Solid-specific support is valuable #

Solid is not React with a smaller API. Its fine-grained reactivity model updates dependent computations directly rather than re-running component render functions. Solid docs describe this model as updating only the parts of the page that depend on changed data. (Solid.js Documentation)

A Solid-native Motion integration should therefore:

  • Avoid React-style rerender assumptions.
  • Treat props as reactive property reads, not immutable render snapshots.
  • Bind Motion values directly to DOM effects.
  • Use Solid lifecycle primitives for mount, cleanup, effects, refs, and SSR boundaries.
  • Avoid unnecessary component-level recomputation.

Why support for both Solid 1 and Solid 2 matters #

Solid 1 is the production ecosystem today. Solid 2 is the next major ecosystem target and may change scheduling, reactivity internals, JSX transforms, hydration, or routing assumptions. The integration should give Solid 1 users a stable API now while preventing design choices that block Solid 2 adoption later.

The primary compatibility principle is:

Public APIs should be version-neutral; lifecycle, hydration, JSX, and scheduling behavior should be isolated behind adapters.


2. Goals #

Developer experience goals #

  • Provide a familiar Motion API surface where it maps cleanly to Solid.
  • Prefer Solid naming and patterns for primitives: createMotionValue, not only useMotionValue.
  • Support normal Solid JSX:
<motion.button
  class="primary"
  animate={{ scale: pressed() ? 0.96 : 1 }}
  whileHover={{ scale: 1.04 }}
>
  Save
</motion.button>
  • Support reactive props without forcing users into imperative animation setup.
  • Provide clear migration paths for React Motion users.

Performance goals #

  • Avoid rerender-style animation updates.
  • Keep per-frame animation work outside Solid signal updates unless the user explicitly bridges Motion values into Solid state.
  • Use Motion values and Motion’s frame loop for animation updates.
  • Prefer transform and opacity animations where possible, because Motion’s performance guide notes these are generally the cheapest compositor-friendly properties. (Motion)
  • Avoid layout thrashing by batching reads and writes.

API consistency goals with Motion #

Stable equivalents should exist for:

  • motion.* components.
  • initial, animate, exit, transition.
  • variants.
  • whileHover, whileTap, whileFocus, whileDrag, whileInView.
  • drag, dragConstraints, dragElastic, dragMomentum, dragControls.
  • layout, layoutId, LayoutGroup.
  • MotionConfig.
  • Motion values and derived values.
  • Reduced motion configuration.

SolidJS idiom alignment #

The integration should:

  • Use create* naming for Solid primitives.
  • Return Solid accessors where a value is reactive from the Solid perspective.
  • Avoid relying on component rerenders.
  • Use splitProps and mergeProps internally because Solid documents these as preserving reactive property access when partitioning or merging props. (Solid.js Documentation) (Solid.js Documentation)
  • Avoid destructuring reactive props into stale local values.

Cross-version compatibility goals #

  • Solid 1: production-ready support.
  • Solid 2: experimental support behind an adapter or explicit entry point until final APIs stabilize.
  • Shared public API for application code.
  • Version-specific internals for lifecycle, scheduling, hydration, and JSX typing.

3. Non-Goals #

This integration will not:

  • Reimplement Motion’s animation engine.
  • Wrap React Motion internally.
  • Provide a generic animation abstraction independent of Motion.
  • Guarantee support for every private Motion internal API.
  • Provide full drag-and-drop dropzone semantics; Motion’s drag docs explicitly distinguish Motion drag from the browser Drag and Drop API and note native dropzone functionality is not Motion’s current focus. (Motion)
  • Solve all route transition patterns for every router. It should provide primitives that work with Solid Router and SolidStart.
  • Animate server-rendered HTML before hydration.
  • Hide all Solid 2 API churn behind magic runtime detection.
  • Guarantee zero migration effort for code that depends on undocumented Solid internals.

4. Target Users and Use Cases #

Common animation use cases #

  • Fade/slide/scale entrances.
  • Button hover and tap feedback.
  • Expanding accordions.
  • Modal enter/exit animations.
  • Toast notifications.
  • Route/page transitions.
  • Animated lists.
  • SVG path drawing.
  • Scroll-triggered reveals.
  • Responsive layout transitions.

Advanced animation use cases #

  • Shared element transitions with layoutId.
  • Drag interactions with constraints and momentum.
  • Animation sequences via Motion’s animate() runtime.
  • Motion values bound to Solid signals.
  • Derived transforms such as scroll progress to opacity.
  • Animation controls for imperative orchestration.
  • Coordinated child variants.
  • Reduced-motion-aware variants.

SSR considerations #

Solid SSR requires server output and client hydration output to match. Solid’s hydrate docs state that hydrated DOM and JSX output must match server output for hydration to succeed. (Solid.js Documentation)

Therefore:

  • Server rendering should output deterministic static markup and initial styles.
  • Client-only animation startup should happen after mount.
  • Motion should not mutate DOM during server render.
  • Initial animation style must not create hydration mismatches.

Routing considerations #

The integration should work with:

  • Solid Router CSR.
  • Solid Router SSR.
  • SolidStart v1.
  • SolidStart v2.
  • Userland routers that mount/unmount Solid components.

Solid Router supports SSR and can be used with server/client routing modes. (Solid.js Documentation)

Solid 1 versus Solid 2 compatibility expectations #

Solid 1 users should expect:

  • Stable package entry point.
  • Production support.
  • Full test matrix.

Solid 2 users should initially expect:

  • Experimental entry point.
  • Public API compatibility where possible.
  • Clearly labeled gaps.
  • Rapid changes until Solid 2 APIs settle.

5. Compatibility Strategy for Solid 1 and Solid 2 #

Stable recommendation #

Use a shared public API with version-specific adapters:

// Stable public entry for production Solid 1
import { motion } from "motion/solid";

// Explicit experimental entry for Solid 2 during beta/RC
import { motion } from "motion/solid/solid2";

Once Solid 2 is stable and the adapter is proven, motion/solid can support both Solid 1 and Solid 2 through build-time resolution or a unified adapter.

Supported version ranges #

Recommended initial policy:

{
  "peerDependencies": {
    "solid-js": ">=1.8 <2"
  }
}

Experimental Solid 2 policy:

{
  "peerDependencies": {
    "solid-js": ">=2.0.0-beta.0 <3"
  }
}

Future unified policy after Solid 2 stabilization:

{
  "peerDependencies": {
    "solid-js": ">=1.8 <3"
  }
}

Shared public API strategy #

The following should remain stable across Solid 1 and Solid 2:

motion
MotionConfig
Presence
LayoutGroup
createMotionValue
createSpring
createTransform
createMotionValueSignal
createAnimationControls
createReducedMotion
animate
stagger
spring

The following may require version-specific implementation:

Presence
LayoutGroup
motion.create
createScopedAnimate
directive support
SSR initial style injection
hydration-safe mount scheduling

Internal adapter strategy #

Define a small framework adapter interface:

export interface SolidMotionAdapter {
  version: "solid1" | "solid2";

  onClientMount(fn: () => void): void;
  onDispose(fn: () => void): void;

  createTrackedEffect(fn: () => void): void;
  createPostRenderEffect(fn: () => void): void;

  batch(fn: () => void): void;
  untrack<T>(fn: () => T): T;

  createContext<T>(defaultValue?: T): SolidContext<T | undefined>;
  useContext<T>(context: SolidContext<T | undefined>): T | undefined;

  isServer: boolean;
}

Solid 1 adapter maps to:

import {
  createEffect,
  createRenderEffect,
  onCleanup,
  onMount,
  batch,
  untrack,
  createContext,
  useContext,
} from "solid-js";
import { isServer } from "solid-js/web";

Solid 2 adapter should map to equivalent APIs, but must not assume exact names until Solid 2 finalizes.

Conditional exports or package entry points #

Recommended package exports:

{
  "name": "motion",
  "exports": {
    "./solid": {
      "types": "./dist/solid/index.d.ts",
      "import": "./dist/solid/index.mjs"
    },
    "./solid/mini": {
      "types": "./dist/solid/mini.d.ts",
      "import": "./dist/solid/mini.mjs"
    },
    "./solid/solid1": {
      "types": "./dist/solid/solid1.d.ts",
      "import": "./dist/solid/solid1.mjs"
    },
    "./solid/solid2": {
      "types": "./dist/solid/solid2.d.ts",
      "import": "./dist/solid/solid2.mjs"
    }
  }
}

Avoid custom package conditions such as "solid2" as the primary mechanism because bundlers may not consistently resolve them.

Build-time versus runtime compatibility #

Recommended default:

  • Build-time entry points for Solid 1 and Solid 2.
  • Runtime detection only for warnings and diagnostics.
  • No bundling of both adapters into production builds.

Runtime detection risks:

  • Larger bundle size.
  • Incorrect detection in SSR or edge environments.
  • Tree-shaking loss.
  • Accidental dependence on package manager hoisting.

Risks caused by lifecycle, JSX, hydration, or reactivity differences #

Key risk areas:

  • Effect timing and batching.
  • Whether refs are assigned before animation setup.
  • JSX prop getter semantics.
  • Hydration marker and event replay behavior.
  • Owner disposal and cleanup semantics.
  • Context propagation.
  • Router/Suspense interaction.

Solid 1 docs state that onMount runs once on the client after initial render, does not run during server rendering, and refs have been assigned by that time. (Solid.js Documentation) Solid 2 should be assumed compatible only after equivalent lifecycle guarantees are verified.

  • Ship motion/solid for Solid 1 first.
  • Ship motion/solid/solid2 as experimental.
  • Keep examples version-neutral.
  • Keep adapter-specific tests separate.
  • Promote Solid 2 support to stable only after Solid 2 final APIs and hydration semantics are confirmed.

6. Proposed API Design #

6.1 Core primitives #

createMotionValue #

Solid-native wrapper over Motion’s motionValue.

import { createMotionValue } from "motion/solid";

const x = createMotionValue(0);

x.set(100);
console.log(x.get());

Motion values already track state and velocity, expose .get(), .set(), .on(), and are described by Motion as signal-like values optimized by its frame loop. (Motion)

createMotionValueSignal #

Bridge a Motion value into a Solid accessor only when needed:

const x = createMotionValue(0);
const latestX = createMotionValueSignal(x);

createEffect(() => {
  console.log(latestX());
});

Recommended behavior:

function createMotionValueSignal<T>(value: MotionValue<T>): Accessor<T> {
  const [latest, setLatest] = createSignal(value.get());

  const unsubscribe = value.on("change", setLatest);
  onCleanup(unsubscribe);

  return latest;
}

This bridge should be opt-in because updating Solid signals every animation frame can be expensive.

createSpring #

const rawX = createMotionValue(0);
const x = createSpring(rawX, { stiffness: 300, damping: 30 });

createTransform #

const opacity = createTransform(scrollYProgress, [0, 1], [0, 1]);

createReducedMotion #

const prefersReducedMotion = createReducedMotion();

const target = () =>
  prefersReducedMotion()
    ? { opacity: open() ? 1 : 0 }
    : { opacity: open() ? 1 : 0, y: open() ? 0 : 16 };

Motion’s React docs provide useReducedMotion as a hook that returns whether the user’s device has reduced motion enabled and notes that this can be used to replace large transform animations with opacity or disable parallax/autoplay effects. (Motion)

6.2 Component API #

Basic component form #

import { motion } from "motion/solid";

export function Card() {
  return (
    <motion.div
      class="card"
      initial={{ opacity: 0, y: 8 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{ duration: 0.2 }}
    />
  );
}

Supported targets #

<motion.div />
<motion.button />
<motion.a />
<motion.svg />
<motion.path />
<motion.circle />

Dynamic creation #

const MotionDialog = motion.create("dialog");
<MotionDialog
  open={open()}
  initial={{ opacity: 0 }}
  animate={{ opacity: 1 }}
/>

Reactive prop support #

Preferred version-neutral pattern:

<motion.div
  animate={() => ({
    opacity: visible() ? 1 : 0,
    x: visible() ? 0 : -24,
  })}
/>

Also support normal Solid JSX expressions:

<motion.div animate={{ opacity: visible() ? 1 : 0 }} />

Implementation note: internally, always read motion props inside Solid effects or adapter-tracked computations. Never eagerly destructure reactive props into static locals.

6.3 Directive API #

Directive support is useful when users want Motion behavior on an existing element without replacing it with <motion.*>.

import { motionDirective } from "motion/solid/directive";

declare module "solid-js" {
  namespace JSX {
    interface Directives {
      motion: MotionDirectiveOptions;
    }
  }
}

<div
  use:motion={{
    initial: { opacity: 0 },
    animate: () => ({ opacity: visible() ? 1 : 0 }),
  }}
/>

Recommendation:

  • Mark directive API as stable only after the component API is stable.
  • Keep directive implementation as a thin wrapper around createMotionElementState.

6.4 Animation controls #

const controls = createAnimationControls();

controls.start({ x: 100, opacity: 1 });
controls.stop();
controls.set({ x: 0 });
<motion.div animate={controls} />

Controls should be framework-neutral and independent of Solid owner disposal. Components subscribe to controls on mount and unsubscribe on cleanup.

6.5 Gesture support #

<motion.button
  whileHover={{ scale: 1.05 }}
  whileTap={{ scale: 0.96 }}
  whileFocus={{ outlineOffset: 4 }}
  onHoverStart={(event) => console.log("hover")}
  onTap={() => submit()}
/>

Supported gesture props:

whileHover
whileTap
whileFocus
whileDrag
whileInView

onHoverStart
onHoverEnd
onTap
onTapStart
onTapCancel
onPan
onPanStart
onPanEnd
onDrag
onDragStart
onDragEnd

Drag:

<motion.div
  drag="x"
  dragConstraints={{ left: -100, right: 100 }}
  dragElastic={0.2}
  dragMomentum
/>

Motion’s drag API supports pointer dragging, axis control, elastic constraints, momentum, direction locking, and imperative start/stop controls, so Solid should preserve these semantics. (Motion)

6.6 Layout animation support #

<LayoutGroup>
  <motion.div layout />
  <motion.div layoutId="selected-pill" />
</LayoutGroup>

Support:

layout?: boolean | "position" | "size";
layoutId?: string;
layoutDependency?: unknown;
layoutScroll?: boolean;
layoutRoot?: boolean;
layoutAnchor?: { x?: number; y?: number };

Motion’s layout model animates layout changes with a single layout prop and supports layoutId for shared element transitions. (Motion)

Solid-specific implementation must not depend on React rerenders. It should use projection node measurement coordinated by the adapter and scheduled around DOM mutations.

6.7 Presence and exit animation support #

Recommended Solid API name:

import { Presence } from "motion/solid";

<Presence>
  {open() && (
    <motion.div
      presenceKey="modal"
      initial={{ opacity: 0, scale: 0.96 }}
      animate={{ opacity: 1, scale: 1 }}
      exit={{ opacity: 0, scale: 0.96 }}
    />
  )}
</Presence>

Why Presence, not AnimatePresence?

  • Presence is shorter and Solid-native.
  • AnimatePresence can be exported as a compatibility alias.
export { Presence, Presence as AnimatePresence };

Solid-specific guidance:

  • Prefer presenceKey for stable identity.
  • Also accept key if available from JSX, but do not rely on React key semantics.
  • With <For>, default identity should be item reference.
  • With <Show>, recommend presenceKey.

6.8 Variants and orchestration #

const list = {
  visible: {
    opacity: 1,
    transition: { staggerChildren: 0.05 },
  },
  hidden: {
    opacity: 0,
  },
};

const item = {
  visible: { opacity: 1, y: 0 },
  hidden: { opacity: 0, y: 8 },
};

<motion.ul variants={list} initial="hidden" animate="visible">
  <For each={items()}>
    {(itemData) => (
      <motion.li variants={item} presenceKey={itemData.id}>
        {itemData.label}
      </motion.li>
    )}
  </For>
</motion.ul>;

Variant labels should match Motion semantics:

type VariantLabel = string | string[];
type Variants = Record<string, TargetAndTransition | VariantResolver>;

APIs identical across Solid 1 and Solid 2 #

  • motion.*
  • motion.create
  • initial, animate, exit, transition
  • variants
  • while* gesture props
  • drag* props
  • layout* props
  • MotionConfig
  • Presence
  • LayoutGroup
  • createMotionValue
  • createReducedMotion
  • createAnimationControls

APIs that may need compatibility wrappers #

  • Directive APIs.
  • Presence internals.
  • Layout measurement scheduling.
  • SSR initial style serialization.
  • Context implementation.
  • JSX type augmentation.

7. SolidJS Reactivity Model Integration #

Stable recommendations #

Signals #

Signals should drive animation targets, not animation frames:

const [open, setOpen] = createSignal(false);

<motion.div
  animate={() => ({
    opacity: open() ? 1 : 0,
    x: open() ? 0 : -20,
  })}
/>;

Do not update a Solid signal on every animation frame unless the user explicitly asks for a Solid accessor bridge.

Memos #

Use memos for expensive target calculation:

const target = createMemo(() => {
  const isOpen = open();
  const reduced = prefersReducedMotion();

  return reduced
    ? { opacity: isOpen ? 1 : 0 }
    : { opacity: isOpen ? 1 : 0, y: isOpen ? 0 : 24 };
});

<motion.div animate={target} />;

Effects #

Use effects to observe reactive Motion props. Solid’s createEffect automatically tracks signals and reruns when dependencies change. (Solid.js Documentation)

Internal pattern:

adapter.createTrackedEffect(() => {
  const animate = resolveTarget(props.animate);
  visualElement.animate(animate, resolveTransition(props.transition));
});

Cleanup #

Use cleanup for:

  • Stopping active animations.
  • Removing gesture listeners.
  • Removing Motion value subscriptions.
  • Deregistering layout projection nodes.
  • Completing presence removal callbacks.

Solid’s onCleanup runs when the owning component unmounts or when a tracking scope is disposed or re-executes. (Solid.js Documentation)

Refs #

Motion setup requires DOM refs. In Solid 1, onMount is client-only and refs are assigned before it runs. (Solid.js Documentation)

function MotionElement(props: MotionProps<HTMLElement>) {
  let element!: HTMLElement;

  onMount(() => {
    const state = createVisualElement(element, props);
    onCleanup(() => state.destroy());
  });

  return <div ref={element} />;
}

Avoiding unnecessary recomputation #

Internal rules:

  • Do not destructure props eagerly.

  • Use splitProps for motion props vs DOM props.

  • Read only the motion props needed by a given effect.

  • Use separate effects for independent concerns:

    • animation targets
    • gestures
    • layout registration
    • style binding
    • event callbacks
  • Do not route Motion frame updates through Solid unless bridged.

Solid 1 differences #

Solid 1 effects and prop getters are well understood. The Solid 1 adapter should rely on:

  • onMount
  • onCleanup
  • createEffect
  • createRenderEffect
  • batch
  • untrack
  • splitProps
  • mergeProps

Solid 2 assumptions #

Forward-looking assumptions:

  • Solid 2 will preserve equivalent concepts for signals, reactive effects, cleanup, refs, context, and JSX components.
  • Effect timing or batching may change.
  • Hydration and async behavior may change.
  • Adapter must own any assumptions about when DOM is measurable.

Isolation strategy #

All direct imports from solid-js and solid-js/web should live in adapter files:

src/adapters/solid1.ts
src/adapters/solid2.ts
src/adapters/types.ts

Shared runtime code should consume only SolidMotionAdapter.


8. Architecture #

Package structure #

packages/motion-solid/
  src/
    index.ts
    mini.ts
    adapters/
      types.ts
      solid1.ts
      solid2.ts
    components/
      motion.tsx
      Presence.tsx
      LayoutGroup.tsx
      MotionConfig.tsx
    primitives/
      createMotionValue.ts
      createMotionValueSignal.ts
      createSpring.ts
      createTransform.ts
      createReducedMotion.ts
      createAnimationControls.ts
      createScopedAnimate.ts
    dom/
      createVisualElement.ts
      bindMotionProps.ts
      renderStyles.ts
      renderAttrs.ts
      gestures.ts
      layout.ts
      presence.ts
    ssr/
      initialStyles.ts
      serialize.ts
    types/
      jsx.ts
      motion-props.ts
      intrinsic-elements.ts

Runtime responsibilities #

The Solid integration runtime should:

  • Create visual elements from DOM refs.
  • Bind reactive props to Motion animations.
  • Install gesture listeners.
  • Bind Motion values to styles and attributes.
  • Register layout projection nodes.
  • Manage presence state.
  • Clean up everything on owner disposal.

Renderer or adapter layer #

The adapter provides framework lifecycle and reactivity. The renderer provides Motion-specific DOM binding.

function createMotionComponent(tag: string, adapter: SolidMotionAdapter) {
  return function MotionComponent(rawProps: MotionComponentProps) {
    const [motionProps, domProps] = splitMotionProps(rawProps);

    let element!: Element;

    adapter.onClientMount(() => {
      const visual = createVisualElement(element, motionProps);
      bindMotionProps(visual, motionProps, adapter);
      adapter.onDispose(() => visual.destroy());
    });

    return createElement(tag, {
      ...domProps,
      ref: mergeRefs(domProps.ref, (node) => (element = node)),
      style: createInitialStyle(rawProps),
    });
  };
}

DOM binding strategy #

Use Motion’s optimized effects where possible:

  • styleEffect for style-bound Motion values.
  • attrEffect or SVG effect equivalents for SVG attributes.
  • animate() for imperative element animations.
  • Visual element abstraction for declarative prop lifecycle.

Motion’s vanilla APIs include effect utilities and Motion values that can render to DOM outside a framework render loop. (Motion)

Lifecycle management #

Lifecycle phases:

  1. Component setup:

    • Split props.
    • Compute SSR initial style.
    • Return JSX.
  2. Client mount:

    • Resolve DOM element.
    • Create visual element.
    • Register layout/presence.
    • Start initial/animate transition.
  3. Reactive updates:

    • Observe motion prop changes.
    • Start/stop/update animations.
  4. Cleanup:

    • Cancel animations.
    • Remove listeners.
    • Deregister layout node.
    • Resolve presence removal if needed.

Cleanup and memory safety #

Every subscription must return a disposer:

const cleanups: Array<() => void> = [];

cleanups.push(value.on("change", render));
cleanups.push(installHoverGesture(element, handlers));
cleanups.push(layoutTree.register(node));

adapter.onDispose(() => {
  for (const cleanup of cleanups.splice(0)) cleanup();
  visualElement.destroy();
});

Solid 1 adapter responsibilities #

  • Map lifecycle and effects to Solid 1 APIs.
  • Preserve reactive prop reads.
  • Provide SSR isServer.
  • Ensure mount-only code does not run during SSR.
  • Provide context wrappers for config, layout groups, and presence.

Solid 2 adapter responsibilities #

  • Provide equivalent lifecycle/effect semantics.
  • Normalize changed scheduling behavior.
  • Verify hydration timing.
  • Implement compatibility with new JSX/runtime types.
  • Provide warnings for unsupported beta behavior.

Shared Motion runtime responsibilities #

  • Value interpolation.
  • Animation playback.
  • Motion value subscriptions.
  • Gesture recognition.
  • Layout projection.
  • Variant resolution.
  • Transition resolution.
  • Reduced motion policy application.

9. SSR and Hydration #

Expected server behavior #

Server rendering should:

  • Render actual DOM markup.
  • Render initial static styles required to avoid visual flash.
  • Avoid starting animations.
  • Avoid reading browser-only APIs such as window, matchMedia, ResizeObserver, or IntersectionObserver.
  • Avoid registering gesture listeners.

Solid’s isServer export is a constant that allows bundlers to eliminate unreachable server/client branches. (Solid.js Documentation)

import { isServer } from "solid-js/web";

if (!isServer) {
  // browser-only Motion setup
}

Hydration-safe animation behavior #

Default rule:

  • Server and initial client render must match.
  • DOM mutation for animation begins after hydration/mount.
  • initial styles may be serialized into SSR markup.
  • animate should run after mount unless initial={false}.
<motion.div
  initial={{ opacity: 0 }}
  animate={{ opacity: 1 }}
/>

Server output should include opacity: 0. Client hydration sees the same style. After mount, Motion animates to opacity: 1.

<motion.div
  initial={false}
  animate={{ opacity: 1 }}
/>

Server output should include opacity: 1; no entrance animation is run.

Initial animation handling #

Recommended semantics:

Prop state Server style Client startup
initial object + animate initial animate to animate after mount
initial={false} + animate animate no initial animation
no initial, animate object animate no entrance from hidden state
exit only current DOM style used only during removal

Progressive enhancement strategy #

For SSR:

  • HTML should remain usable without JavaScript.
  • Motion should enhance after hydration.
  • Gesture-only affordances should have keyboard equivalents.
  • Critical visibility should not depend on an animation completing.

SolidStart considerations #

SolidStart supports multiple rendering modes including CSR, SSR, async SSR, streaming, and SSG. (Solid.js Documentation)

Guidance:

  • In SolidStart layouts, wrap app with MotionConfig.
  • For route transitions, place Presence around route outlet boundaries.
  • Avoid random IDs for layoutId; use deterministic route or entity IDs.
  • Treat SolidStart v2 as an integration test target because third-party compatibility is still explicitly called out in migration docs. (Solid.js Documentation)

Solid 1 SSR considerations #

Solid 1 adapter should use:

  • isServer for branch elimination.
  • onMount for animation startup.
  • renderToString and hydrate tests to verify matching markup.
  • NoHydration only for explicit escape hatches.

Solid’s NoHydration renders children on the server but leaves the server DOM in place without hydrating that subtree on the client, which makes it inappropriate for interactive motion components except as an intentional non-interactive escape hatch. (Solid.js Documentation)

Solid 2 SSR considerations #

Forward-looking assumptions:

  • Solid 2 may revise SSR and hydration details.
  • The Solid 2 adapter should own hydration-safe mount scheduling.
  • Layout measurement should not run until hydration is complete.
  • Presence should not detach or reorder nodes during hydration.

Avoiding hydration mismatches #

Rules:

  • Do not compute initial style from browser-only state during server render.
  • Do not call Date.now(), Math.random(), or layout measurements for initial style.
  • Do not conditionally render different children based on reduced motion during SSR.
  • For reduced motion, render the same DOM and first style, then adapt animation behavior after mount.
  • Do not start an animation in createEffect if that effect can run before hydration safety is guaranteed.

Solid docs note that effects do not run during SSR and also do not run during initial client hydration, which supports deferring animation setup until after hydration-sensitive work. (Solid.js Documentation)


10. TypeScript Design #

Public types #

export type MotionValue<T = any> = import("motion").MotionValue<T>;

export type MotionTarget = Record<string, any>;

export type MotionTransition = {
  duration?: number;
  delay?: number;
  ease?: string | number[];
  type?: "tween" | "spring" | "inertia";
  stiffness?: number;
  damping?: number;
  mass?: number;
  [key: string]: unknown;
};

export type VariantLabel = string | string[];

export type VariantResolver<Custom = unknown> = (
  custom: Custom,
  context: VariantContext
) => MotionTarget;

export type Variants<Custom = unknown> = Record<
  string,
  MotionTarget | VariantResolver<Custom>
>;

Generic component typing #

type MaybeAccessor<T> = T | (() => T);

type MotionProp<T> = MaybeAccessor<T>;

export interface MotionOwnProps<Custom = unknown> {
  initial?: MotionProp<false | MotionTarget | VariantLabel>;
  animate?: MotionProp<MotionTarget | VariantLabel | AnimationControls>;
  exit?: MotionProp<MotionTarget | VariantLabel>;
  transition?: MotionProp<MotionTransition>;
  variants?: MotionProp<Variants<Custom>>;
  custom?: Custom;

  layout?: boolean | "position" | "size";
  layoutId?: string;
  presenceKey?: string | number;

  whileHover?: MotionTarget | VariantLabel;
  whileTap?: MotionTarget | VariantLabel;
  whileFocus?: MotionTarget | VariantLabel;
  whileDrag?: MotionTarget | VariantLabel;
  whileInView?: MotionTarget | VariantLabel;
}
export type MotionComponentProps<
  Tag extends keyof JSX.IntrinsicElements,
  Custom = unknown,
> =
  Omit<JSX.IntrinsicElements[Tag], keyof MotionOwnProps<Custom> | "style"> &
  MotionOwnProps<Custom> & {
    style?: MotionStyle<Tag>;
  };

Motion style types #

type MotionStyleValue =
  | string
  | number
  | MotionValue<string | number>
  | undefined;

export type MotionStyle<Tag extends keyof JSX.IntrinsicElements> =
  JSX.CSSProperties & {
    x?: MotionStyleValue;
    y?: MotionStyleValue;
    z?: MotionStyleValue;
    scale?: MotionStyleValue;
    scaleX?: MotionStyleValue;
    scaleY?: MotionStyleValue;
    rotate?: MotionStyleValue;
    rotateX?: MotionStyleValue;
    rotateY?: MotionStyleValue;
    rotateZ?: MotionStyleValue;
    opacity?: MotionStyleValue;
    pathLength?: MotionStyleValue;
    pathOffset?: MotionStyleValue;
    pathSpacing?: MotionStyleValue;
  };

Event handler types #

export interface GestureHandlers {
  onHoverStart?: (event: PointerEvent) => void;
  onHoverEnd?: (event: PointerEvent) => void;

  onTap?: (event: PointerEvent, info: TapInfo) => void;
  onTapStart?: (event: PointerEvent, info: TapInfo) => void;
  onTapCancel?: (event: PointerEvent, info: TapInfo) => void;

  onPan?: (event: PointerEvent, info: PanInfo) => void;
  onPanStart?: (event: PointerEvent, info: PanInfo) => void;
  onPanEnd?: (event: PointerEvent, info: PanInfo) => void;

  onDrag?: (event: PointerEvent, info: PanInfo) => void;
  onDragStart?: (event: PointerEvent, info: PanInfo) => void;
  onDragEnd?: (event: PointerEvent, info: PanInfo) => void;

  onAnimationStart?: (definition: AnimationDefinition) => void;
  onAnimationComplete?: (definition: AnimationDefinition) => void;
  onUpdate?: (latest: MotionTarget) => void;
}

Solid JSX compatibility #

Solid 1 typing should target solid-js JSX namespace.

Potential Solid 2 issue:

  • JSX namespace location or intrinsic element typing may change.
  • Provide motion/solid/solid2 type entry if needed.
  • Keep public Motion prop types independent of Solid internals.

Version-specific type entry points #

// Solid 1
import type { MotionComponentProps } from "motion/solid";

// Solid 2 experimental
import type { MotionComponentProps } from "motion/solid/solid2";

Only introduce separate types if required by JSX incompatibilities. The default goal is one shared type surface.


11. Accessibility #

Reduced motion support #

Expose both global and local APIs:

<MotionConfig reducedMotion="user">
  <App />
</MotionConfig>
const prefersReducedMotion = createReducedMotion();

Motion’s accessibility docs recommend respecting reduced motion, replacing large transform animations with opacity transitions, disabling parallax, and using MotionConfig with reducedMotion="user" to automatically disable transform and layout animations while preserving other animations. (Motion)

Recommended Solid semantics:

type ReducedMotionConfig = "user" | "always" | "never";

Focus and interaction considerations #

  • whileFocus must not remove visible focus indicators.
  • Tap interactions must not replace native button semantics.
  • Drag handles must remain keyboard-accessible when drag changes state.
  • Presence exit animations must not trap focus in removed UI.
  • Modals must coordinate exit animations with focus restoration.

Avoiding harmful motion #

Defaults:

  • Do not animate large viewport translations when reduced motion is enabled.
  • Do not autoplay infinite parallax by default.
  • Prefer opacity or color transitions for reduced motion.
  • Provide escape hatches for app-level user preferences.

Accessible defaults for gestures and presence #

  • Hover should not be the only way to reveal critical content.
  • Tap should work with keyboard activation on native interactive elements.
  • Exit animation should mark exiting modal content inert or otherwise prevent interaction once logical close begins.
  • Presence should expose lifecycle callbacks:
<Presence
  onExitStart={() => setModalInteractive(false)}
  onExitComplete={() => restoreFocus()}
/>

12. Performance Considerations #

Bundle size #

Recommendations:

  • motion/solid should import only the required Motion runtime.
  • motion/solid/mini should support a smaller feature set aligned with Motion’s mini animate() entry.
  • Gesture, layout, and presence features should be tree-shakable where possible.
  • Do not bundle Solid 1 and Solid 2 adapters together.

Motion’s animate() docs distinguish mini and hybrid imports, with mini focused on HTML/SVG styles through native browser APIs and hybrid supporting independent transforms, SVG paths, CSS variables, sequences, and more. (Motion)

Tree shaking #

Feature modules:

motion/solid
motion/solid/mini
motion/solid/gestures
motion/solid/layout
motion/solid/presence

The default entry can re-export everything, but internal imports should remain modular.

DOM writes #

  • Batch style writes through Motion’s frame loop.
  • Do not write inline styles redundantly if Motion value has not changed.
  • Avoid Solid effects that write DOM on every frame.
  • Prefer Motion’s DOM effects for Motion values.

Scheduling #

  • Read layout before write.
  • Use Motion frame phases for projection.
  • Use adapter scheduling for Solid effect changes.
  • For Solid 2, validate whether automatic batching changes measurement timing.

Animation batching #

  • Coalesce multiple prop changes in a single Solid batch.
  • Treat a single reactive update as one animation definition update.
  • For variants, resolve parent/child orchestration once per label change.

Memory usage #

  • Motion values should be garbage-collectable after cleanup.
  • Layout projection nodes must unregister.
  • Presence records must be removed after exit completion.
  • Gesture listeners must be removed on disposal.
  • No global registries with strong references to disposed elements.

Fine-grained reactivity considerations #

Good:

<motion.div animate={() => ({ x: x(), opacity: opacity() })} />

Avoid:

createEffect(() => {
  requestAnimationFrame(() => setX(x() + 1));
});

Use Motion values for frame-driven animation:

const x = createMotionValue(0);
animate(x, 100);

Compatibility overhead #

  • Adapter calls should inline well.
  • Version-specific entry points avoid branching.
  • Shared runtime should not use dynamic imports during animation setup.
  • Development warnings should be removed in production builds.

13. Examples #

Basic animated element #

import { motion } from "motion/solid";

export function BasicCard() {
  return (
    <motion.div
      class="card"
      initial={{ opacity: 0, y: 12 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{ duration: 0.25 }}
    >
      Hello Solid Motion
    </motion.div>
  );
}

Signal-driven animation #

import { createSignal } from "solid-js";
import { motion } from "motion/solid";

export function TogglePanel() {
  const [open, setOpen] = createSignal(false);

  return (
    <>
      <button onClick={() => setOpen((v) => !v)}>Toggle</button>

      <motion.section
        animate={() => ({
          opacity: open() ? 1 : 0,
          height: open() ? "auto" : 0,
        })}
        transition={{ duration: 0.2 }}
      >
        Panel content
      </motion.section>
    </>
  );
}

Gesture interaction #

import { motion } from "motion/solid";

export function GestureButton() {
  return (
    <motion.button
      whileHover={{ scale: 1.05 }}
      whileTap={{ scale: 0.96 }}
      whileFocus={{ outlineOffset: 4 }}
      transition={{ type: "spring", stiffness: 500, damping: 30 }}
      onTap={() => console.log("Tapped")}
    >
      Save
    </motion.button>
  );
}

Enter/exit animation #

import { createSignal, Show } from "solid-js";
import { motion, Presence } from "motion/solid";

export function ModalExample() {
  const [open, setOpen] = createSignal(false);

  return (
    <>
      <button onClick={() => setOpen(true)}>Open</button>

      <Presence>
        <Show when={open()}>
          <motion.div
            presenceKey="modal-backdrop"
            class="backdrop"
            initial={{ opacity: 0 }}
            animate={{ opacity: 1 }}
            exit={{ opacity: 0 }}
            onClick={() => setOpen(false)}
          >
            <motion.div
              presenceKey="modal-panel"
              class="modal"
              initial={{ opacity: 0, scale: 0.96 }}
              animate={{ opacity: 1, scale: 1 }}
              exit={{ opacity: 0, scale: 0.96 }}
            >
              Modal content
            </motion.div>
          </motion.div>
        </Show>
      </Presence>
    </>
  );
}

Layout animation #

import { createSignal } from "solid-js";
import { motion, LayoutGroup } from "motion/solid";

export function Tabs() {
  const [selected, setSelected] = createSignal("home");

  const tabs = ["home", "docs", "settings"];

  return (
    <LayoutGroup>
      <nav class="tabs">
        {tabs.map((tab) => (
          <button onClick={() => setSelected(tab)}>
            {tab}
            {selected() === tab && (
              <motion.div
                layoutId="tab-underline"
                class="underline"
                transition={{ type: "spring", stiffness: 500, damping: 40 }}
              />
            )}
          </button>
        ))}
      </nav>
    </LayoutGroup>
  );
}

Animation controls #

import { motion, createAnimationControls } from "motion/solid";

export function ControlledBox() {
  const controls = createAnimationControls();

  async function run() {
    await controls.start({ x: 100, opacity: 1 });
    await controls.start({ rotate: 180 });
    controls.set({ x: 0, rotate: 0 });
  }

  return (
    <>
      <button onClick={run}>Run</button>
      <motion.div
        class="box"
        initial={{ opacity: 0.5 }}
        animate={controls}
      />
    </>
  );
}

Reduced motion handling #

import { motion, createReducedMotion } from "motion/solid";

export function Sidebar(props: { open: boolean }) {
  const reduced = createReducedMotion();

  return (
    <motion.aside
      animate={() =>
        reduced()
          ? { opacity: props.open ? 1 : 0 }
          : { opacity: props.open ? 1 : 0, x: props.open ? 0 : "-100%" }
      }
    />
  );
}

Solid 1 usage #

import { createSignal } from "solid-js";
import { render } from "solid-js/web";
import { motion, MotionConfig } from "motion/solid";

function App() {
  const [count, setCount] = createSignal(0);

  return (
    <MotionConfig reducedMotion="user">
      <motion.button
        animate={() => ({ scale: 1 + count() * 0.05 })}
        onClick={() => setCount((n) => n + 1)}
      >
        Count {count()}
      </motion.button>
    </MotionConfig>
  );
}

render(() => <App />, document.getElementById("root")!);

Solid 2-compatible version-neutral usage pattern #

import { createSignal } from "solid-js";
import { motion } from "motion/solid";

export function VersionNeutral() {
  const [active, setActive] = createSignal(false);

  const target = () => ({
    opacity: active() ? 1 : 0.6,
    y: active() ? 0 : 8,
  });

  return (
    <motion.button
      animate={target}
      whileTap={{ scale: 0.97 }}
      onClick={() => setActive((v) => !v)}
    >
      Toggle
    </motion.button>
  );
}

The important compatibility pattern is to keep animation targets as accessors or reactive JSX expressions, not as static objects computed once outside tracking.


14. Testing Strategy #

Unit tests #

Use Vitest for:

  • Prop splitting.
  • Target resolution.
  • Variant resolution.
  • Transition merging.
  • Motion value creation.
  • Motion value to Solid accessor bridging.
  • Reduced motion store behavior.
  • Adapter lifecycle calls.
  • Cleanup registration.

Integration tests #

Test Solid components in a DOM-like environment for:

  • Mount/unmount lifecycle.
  • Reactive prop updates.
  • Ref assignment.
  • Motion value style binding.
  • Gesture listener registration.
  • Presence delayed removal.
  • Context propagation.

Use jsdom only for non-layout tests because it cannot produce real layout boxes.

Browser tests #

Use Playwright across Chromium, Firefox, and WebKit for:

  • Actual animations.
  • Pointer gestures.
  • Drag constraints.
  • Layout measurement.
  • Shared layout transitions.
  • Scroll-triggered behavior.
  • Reduced motion media emulation.
  • Focus behavior.

SSR and hydration tests #

Test:

  • renderToString output.
  • hydrate with no mismatch warnings.
  • initial serialization.
  • initial={false} serialization.
  • Reduced motion hydration safety.
  • SolidStart v1 SSR.
  • SolidStart v2 SSR.
  • Streaming boundaries where possible.

Solid’s renderToString emits hydration markup and is server-only, while hydrate attaches client behavior to server-rendered DOM. (Solid.js Documentation) (Solid.js Documentation)

Type tests #

Use tsd or expect-type for:

  • HTML intrinsic props.
  • SVG intrinsic props.
  • Motion style props.
  • Gesture handlers.
  • Custom variants.
  • motion.create.
  • Directive typings.
  • Solid 1 JSX namespace.
  • Solid 2 JSX namespace once available.

Performance benchmarks #

Benchmarks:

  • Mount 1,000 static motion elements.
  • Animate 1,000 opacity values.
  • Signal-driven target updates.
  • Motion value style updates at 60/120fps.
  • Layout group of 100 items.
  • Presence removal of 100 items.
  • Bundle size for core, gestures, layout, presence, and mini entry.

Solid 1 test matrix #

  • solid-js@1.8.x
  • latest solid-js@1.x
  • Vite current.
  • SolidStart v1.
  • SolidStart v2 where it still supports Solid 1.
  • CSR and SSR.

Solid 2 test matrix #

  • latest Solid 2 beta.
  • Solid 2 RC when available.
  • SolidStart/Solid Router versions that advertise Solid 2 support.
  • Experimental adapter only.
  • Hydration and scheduling stress tests.

Compatibility regression tests #

Create fixtures:

fixtures/
  solid1-vite-csr/
  solid1-solidstart-ssr/
  solid2-vite-csr/
  solid2-solidstart-ssr/
  migration-react-motion-patterns/

CI should run adapter-specific fixtures separately to prevent false confidence from one Solid version masking another.


15. Migration and Compatibility #

Compatibility with existing Motion APIs #

Keep these familiar:

<motion.div
  initial={{ opacity: 0 }}
  animate={{ opacity: 1 }}
  exit={{ opacity: 0 }}
  transition={{ duration: 0.2 }}
/>

Use Solid-native names for primitives:

createMotionValue
createSpring
createTransform
createReducedMotion

Optional compatibility aliases may exist:

export const useMotionValue = createMotionValue;
export const useReducedMotion = createReducedMotion;

Recommendation: document aliases as migration conveniences, not idiomatic Solid.

Differences from React usage #

React:

const x = useMotionValue(0);
return <motion.div style={{ x }} />;

Solid:

const x = createMotionValue(0);
return <motion.div style={{ x }} />;

React state-driven animation:

<motion.div animate={{ x: open ? 0 : 100 }} />

Solid state-driven animation:

<motion.div animate={() => ({ x: open() ? 0 : 100 })} />

Presence identity:

// React habit
<motion.div key={id} exit={{ opacity: 0 }} />

Solid recommendation:

<motion.div presenceKey={id} exit={{ opacity: 0 }} />

Migration from Framer Motion or Motion for React #

Steps:

  1. Replace imports:
// Before
import { motion, AnimatePresence } from "motion/react";

// After
import { motion, Presence } from "motion/solid";
  1. Rename hooks:
useMotionValue        -> createMotionValue
useReducedMotion     -> createReducedMotion
useAnimationControls -> createAnimationControls
  1. Convert state reads:
// React
animate={{ x: open ? 0 : 100 }}

// Solid
animate={() => ({ x: open() ? 0 : 100 })}
  1. Replace AnimatePresence with Presence or compatibility alias.

  2. Prefer presenceKey in Solid lists and conditionals.

  3. Avoid destructuring Solid props in wrapper components unless using splitProps.

Migration from Solid 1 to Solid 2 #

Application-level guidance:

  • Keep imports from motion/solid unless using experimental Solid 2 before stable support.
  • During beta, use motion/solid/solid2.
  • Use accessor-based targets.
  • Avoid relying on lifecycle timing beyond documented Motion behavior.
  • Avoid direct imports from motion/solid/internal.
  • Run hydration tests after migration.
  • Verify layout animations because scheduling changes are the highest-risk area.

Library-level guidance:

  • Keep public types version-neutral.
  • Use adapter exports for all Solid-specific behavior.
  • Maintain parallel fixtures until Solid 2 is stable.

Handling deprecated or version-specific APIs #

Policy:

  • Version-specific APIs must be explicitly documented.

  • Experimental Solid 2 APIs should use experimental_ prefixes only if they leak publicly.

  • Deprecations require:

    • console warning in development.
    • migration doc.
    • codemod where feasible.
    • one minor release grace period before removal.

16. Open Questions #

16.1 Should the package export Presence or AnimatePresence as the primary name? #

Tradeoff:

  • AnimatePresence matches Motion React.
  • Presence is more Solid-native and less React-branded.

Solid 1 impact:

  • Either name works.
  • Docs can teach Presence.

Solid 2 impact:

  • No known difference.

Recommended default:

export { Presence, Presence as AnimatePresence };

Document Presence as primary.

16.2 Should animation target props accept accessors explicitly? #

Tradeoff:

  • Accessors are Solid-native and unambiguous.
  • Plain objects match Motion React examples.
  • Supporting both increases type complexity.

Solid 1 impact:

  • Supporting accessors avoids stale object pitfalls.
  • Plain JSX expressions can still work through prop getters.

Solid 2 impact:

  • Accessors are likely the safest version-neutral pattern.

Recommended default:

type MotionProp<T> = T | (() => T);

16.3 Should presenceKey be required? #

Tradeoff:

  • Requiring it is explicit and robust.
  • Optional identity is easier for simple cases.
  • React users expect key.

Solid 1 impact:

  • Solid control flow does not behave like React keyed reconciliation.
  • Explicit presenceKey reduces surprises.

Solid 2 impact:

  • Unknown reconciliation/control-flow differences make explicit identity safer.

Recommended default:

  • Optional for single conditional children.
  • Required warning for arrays/lists in development.
  • Prefer presenceKey in docs.

16.4 Should directives be part of MVP? #

Tradeoff:

  • Directives are Solid-native and ergonomic for existing elements.
  • They add typing and lifecycle surface area.
  • Component API covers most needs.

Solid 1 impact:

  • Directive API is feasible.
  • Requires JSX directive type augmentation.

Solid 2 impact:

  • Directive syntax/type behavior may change.

Recommended default:

  • Post-MVP.
  • Prototype internally.
  • Stabilize after Solid 2 JSX direction is known.

16.5 How should layout animation detect fine-grained DOM changes? #

Tradeoff:

  • Hooking only into motion prop changes is simple but misses external layout shifts.
  • MutationObserver/ResizeObserver catches more but adds overhead.
  • Projection-tree frame snapshots are robust but complex.

Solid 1 impact:

  • Fine-grained DOM changes can happen without component rerenders.
  • Measurement must be scheduled independently of component render.

Solid 2 impact:

  • Potential batching/scheduling changes could affect measurement windows.

Recommended default:

  • Use Motion projection tree with frame-based read/write phases.
  • Add layoutDependency for explicit invalidation.
  • Use observers only where necessary.

16.6 Should Solid 2 support live in the same entry point immediately? #

Tradeoff:

  • Same entry is simpler for users.
  • Separate entry avoids accidental unstable production use.
  • Runtime detection can hurt tree-shaking.

Solid 1 impact:

  • Same entry risks regressions.

Solid 2 impact:

  • Separate entry makes experimentation safe.

Recommended default:

  • motion/solid for Solid 1.
  • motion/solid/solid2 experimental.
  • Merge after Solid 2 stable.

16.7 Should Motion values be Solid signals? #

Tradeoff:

  • Solid signals integrate naturally with Solid effects.
  • Per-frame signal updates can be expensive.
  • Motion values already provide optimized frame-loop subscriptions.

Solid 1 impact:

  • Signal-per-frame updates can trigger unnecessary Solid computations.

Solid 2 impact:

  • Scheduling may improve, but frame updates through Solid should still be opt-in.

Recommended default:

  • Motion values remain Motion values.
  • Provide opt-in createMotionValueSignal.

Implementation risks #

  1. Solid 2 API churn Mitigation: isolate in adapter and mark support experimental.

  2. Presence with Solid control flow Mitigation: require presenceKey in complex cases and maintain owner-scoped exiting nodes.

  3. Layout measurement timing Mitigation: frame-based projection snapshots, explicit layoutDependency, browser tests.

  4. Hydration mismatch from initial styles Mitigation: deterministic SSR style serialization and post-mount animation start.

  5. Prop reactivity loss Mitigation: internal splitProps, no eager destructuring, tests for accessor targets.

  6. Bundle size creep Mitigation: modular feature imports and mini entry.

  7. Reduced motion mismatch during SSR Mitigation: do not branch server DOM structure on matchMedia; adapt after mount.


17. Implementation Plan #

Milestone 0: Research and prototypes #

Deliverables:

  • Verify Solid 1 JSX member component support for <motion.div />.
  • Prototype motion.create.
  • Prototype reactive prop observation (animate={() => ...} and related props).
  • Prototype SSR initial style serialization.
  • Prototype presence with <Show> and <For>.
  • Prototype layout projection with Solid fine-grained updates.
  • Create Solid 2 spike branch.

Exit criteria:

  • Timing contract is explicit and used consistently:
    • render-phase (createRenderEffect)
    • post-render (createEffect/onMount, not post-paint)
    • post-paint (frame/RAF boundary)
  • Basic animation intent updates work in Solid 1 CSR without per-frame signal updates.
  • SSR renders deterministic initial style for initial, initial={false}, and animate-only paths.
  • No hydration warnings in a minimal SolidStart app across initial style scenarios.
  • Presence prototype proves owner retention and DOM retention as separate concerns.
  • Layout prototype proves explicit invalidation-first (layoutDependency) timing model.
  • attrEffect alpha risk is documented with a fallback path.
  • Milestone 0 decision log records what graduates to Milestone 1 and what stays experimental.

Milestone 1: MVP core for Solid 1 #

Scope:

  • motion.* HTML elements.
  • motion.* SVG elements.
  • initial, animate, transition.
  • Motion style values.
  • createMotionValue.
  • createMotionValueSignal.
  • createSpring.
  • createTransform.
  • createAnimationControls.
  • MotionConfig.
  • Basic SSR support.

Example MVP import:

import { motion, createMotionValue } from "motion/solid";

Exit criteria:

  • Unit tests pass.
  • Browser animation tests pass.
  • SSR/hydration test passes.
  • Type tests for HTML/SVG pass.

Milestone 2: Gestures for Solid 1 #

Scope:

  • whileHover
  • whileTap
  • whileFocus
  • whileInView
  • gesture event handlers
  • drag basics
  • drag constraints
  • drag controls

Exit criteria:

  • Pointer/touch/keyboard tests pass.
  • Reduced motion does not break gestures.
  • Cleanup tests verify no retained listeners.

Milestone 3: Presence for Solid 1 #

Scope:

  • Presence
  • AnimatePresence alias
  • exit
  • presenceKey
  • nested exiting children
  • onExitComplete
  • <Show> and <For> examples

Exit criteria:

  • Exiting nodes remain until animation completion.
  • Rapid enter/exit interruption works.
  • Removed nodes clean up owners and listeners.

Milestone 4: Layout animation for Solid 1 #

Scope:

  • layout
  • layoutId
  • LayoutGroup
  • layoutScroll
  • layoutRoot
  • layoutDependency
  • shared element transitions

Exit criteria:

  • Browser layout tests pass.
  • List reorder tests pass.
  • Route-like shared element fixture passes.
  • Performance benchmark meets target.

Milestone 5: SSR and SolidStart hardening #

Scope:

  • SolidStart v1 fixture.
  • SolidStart v2 fixture while Solid 1 remains supported.
  • Streaming SSR tests if feasible.
  • Hydration mismatch detection.
  • Documentation for SSR-safe initial animation.

Exit criteria:

  • No hydration mismatch warnings in fixtures.
  • Reduced motion SSR behavior documented.
  • Route transition example works.

Milestone 6: Solid 2 experimental adapter #

Scope:

  • motion/solid/solid2.
  • Adapter implementation.
  • Type compatibility.
  • Core animation tests.
  • SSR smoke tests.
  • Presence smoke tests.
  • Layout spike.

Exit criteria:

  • Core examples compile and run.
  • Known gaps documented.
  • CI matrix marks Solid 2 failures separately from Solid 1.

Milestone 7: Stabilize Solid 2 support #

Scope:

  • Update adapter after Solid 2 RC/stable APIs.
  • Full test matrix.
  • Confirm hydration behavior.
  • Confirm layout measurement timing.
  • Decide whether motion/solid supports both versions.

Exit criteria:

  • Solid 2 no longer experimental.
  • Migration guide published.
  • Version policy updated.

Post-MVP features #

  • Directive API.
  • Reorder equivalent.
  • Scroll-linked primitives.
  • createScopedAnimate.
  • Lazy feature loading.
  • Dev warnings for stale non-reactive targets.
  • DevTools hooks.
  • Codemods from React Motion patterns.

Release strategy #

Recommended releases:

0.1.0-alpha   Core prototype
0.2.0-alpha   Gestures
0.3.0-alpha   Presence
0.4.0-alpha   Layout
0.5.0-beta    Solid 1 API freeze
1.0.0         Solid 1 stable
1.1.0-alpha   Solid 2 experimental entry
2.0.0 or 1.x  Solid 2 stable, depending on breaking changes

Do not tie package major version to Solid major version unless public API breaks require it.

Versioning strategy #

  • Semver for public API.
  • Adapter internals are private.
  • Solid 2 experimental support can change in minor releases while clearly labeled.
  • Promote Solid 2 to stable only with compatibility guarantees.

Documentation strategy #

Docs should include:

  • Quick start.

  • Solid mental model guide.

  • React Motion migration guide.

  • SSR and hydration guide.

  • SolidStart route transition guide.

  • Reduced motion guide.

  • Layout animation guide.

  • Presence guide.

  • Solid 1 to Solid 2 migration guide.

  • API reference.

  • Troubleshooting:

    • stale props
    • hydration mismatch
    • layout not animating
    • exit not firing
    • drag constraints wrong
    • reduced motion differences

Risks and mitigations #

Risk Impact Mitigation
Solid 2 APIs change High Experimental adapter and separate entry
Presence identity surprises High presenceKey, docs, dev warnings
Layout measurement mismatch High Browser tests and frame projection
SSR style mismatch High deterministic initial style serialization
Bundle size Medium mini entry and feature modules
React-centric API drift Medium Solid-native primitive names
Prop reactivity bugs High no eager destructuring, adapter tests
Gesture cleanup leaks Medium disposer registry and leak tests

The MVP should ship only when the following are true:

  • Solid 1 production support is reliable.
  • Core component API is stable.
  • SSR initial styles are deterministic.
  • Hydration tests pass.
  • Gesture basics are implemented.
  • Presence is either implemented or explicitly marked post-MVP.
  • Layout animation may be beta if clearly labeled, but the API shape should not be knowingly wrong for Solid’s fine-grained model.

The most important engineering decision is to keep Solid-specific lifecycle, scheduling, and hydration behavior behind adapters while preserving a stable Motion-facing API. This lets the integration feel native in Solid 1 today and remain viable as Solid 2 stabilizes.