{"version":3,"names":["createRenderEffect","untrack","useLatestRef","value","ref","current","next"],"sources":["use-latest-ref.ts"],"sourcesContent":["import { type Accessor, createRenderEffect, untrack } from \"solid-js\";\n\n/**\n * Plain `{ current }` container matching the shape other `MutableRef<T>`\n * declarations in this codebase use (see `floating-ui-react/types.ts`,\n * `field-context.ts`, `scroll-area-root-context.ts`). Kept structurally\n * identical — TypeScript duck-types them, so a `MutableRef<T>` from any\n * module is interchangeable at call sites.\n */\nexport interface MutableRef<T> {\n\tcurrent: T;\n}\n\n/**\n * Port of Base UI React's `useValueAsRef` / \"latest ref\" idiom. Returns a\n * stable-identity container whose `.current` is kept in sync with the latest\n * value produced by `value()`.\n *\n * React uses `useRef(value)` plus a layout effect to flush the new value into\n * `ref.current` before the browser paints. The Solid equivalent is a\n * `createRenderEffect` — it runs in the render phase, synchronously, before\n * paint, which matches React's layout-effect timing closely enough for the\n * \"latest value\" contract.\n *\n * Typical usage: a callback captured in a non-reactive scope (event listener,\n * timer, Promise `.then`) needs to read the current value at firing time\n * without causing the captured scope to re-run when the value changes. Read\n * `ref.current` inside the callback; the consumer gets the newest value\n * without any reactivity propagation.\n *\n * The returned object's identity is stable for the component's lifetime — it\n * is allocated once and only `.current` is reassigned. This mirrors React's\n * guarantee that `useRef`'s wrapper object doesn't change.\n *\n * @param value Accessor for the tracked value.\n * @returns A mutable ref whose `.current` reflects the latest `value()`.\n */\nexport function useLatestRef<T>(value: Accessor<T>): MutableRef<T> {\n\t// Seed `.current` with the initial value so reads that happen before the\n\t// first render-effect apply (e.g. synchronous post-mount code inside the\n\t// same setup phase) still see a real value, not `undefined`. The seed\n\t// is intentionally a snapshot — subscription happens through the\n\t// `createRenderEffect` below — so wrap in `untrack` to silence\n\t// `[STRICT_READ_UNTRACKED]` raised in the consumer's component-body\n\t// strict-read scope.\n\tconst ref: MutableRef<T> = { current: untrack(value) };\n\n\t// Keep `.current` pinned to the latest tracked value. `createRenderEffect`\n\t// runs synchronously in the render phase (before paint), so downstream\n\t// layout-effect reads and DOM event handlers will observe the freshest\n\t// value. Solid 2's render effect uses the split compute/apply shape — the\n\t// compute half tracks `value()` and forwards it to the apply half, which\n\t// writes it into the ref. No `prev` comparison here: we want every tick\n\t// through, even when `Object.is` considers the new value equal (the\n\t// writes are idempotent).\n\tcreateRenderEffect(\n\t\t() => value(),\n\t\t(next) => {\n\t\t\tref.current = next;\n\t\t},\n\t);\n\n\treturn ref;\n}\n"],"mappings":"AAAA,SAAwBA,kBAAkB,EAAEC,OAAO,QAAQ,UAAU;;AAErE;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAAIC,KAAkB,EAAiB;EAClE;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,GAAkB,GAAG;IAAEC,OAAO,EAAEJ,OAAO,CAACE,KAAK;EAAE,CAAC;;EAEtD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACAH,kBAAkB,CACjB,MAAMG,KAAK,CAAC,CAAC,EACZG,IAAI,IAAK;IACTF,GAAG,CAACC,OAAO,GAAGC,IAAI;EACnB,CACD,CAAC;EAED,OAAOF,GAAG;AACX","ignoreList":[]}