import { createContext, useContext } from "solid-js"; import type { ToastStore } from "../toast-store"; /** * Context carrying the ambient ``'s store. * * Solid 2's `useContext` throws `ContextNotFoundError` when the resolved * value is `undefined`, so the sentinel for "no provider mounted" is `null` * — `useToastManager` is a public hook that users can legitimately call * outside a provider (mistakenly), and we want the Base UI error message, * not Solid's raw `ContextNotFoundError`. */ export const ToastProviderContext = createContext(null); export function useToastProviderContext(): ToastStore { let store: ToastStore | null = null; try { store = useContext(ToastProviderContext); } catch { // Belt-and-braces for cross-module-instance ownership (e.g. a hook // test that sets up its owner via a CJS `require("solid-js")` while // this module's `createContext` came from the ESM bundle — Solid's // two copies don't share the context registry and `useContext` // throws `ContextNotFoundError` despite the `null` default). } if (store == null) { throw new Error( "Base UI: useToastManager must be used within .", ); } return store; }