'use client' // Loading and unloading a script tag is an effect against a live // document, which is a browser concern and has no react-server counterpart. /** * Third-party scripts with a loading strategy. * * A raw ` * ``` */ export function Script({ src, id, strategy = 'afterInteractive', children, onLoad, onError, ...rest }: Readonly) { // Held in refs so a caller passing a fresh arrow function every render does // not re-run the effect and inject the script twice. const handlers = useRef({ onLoad, onError }) handlers.current = { onLoad, onError } const inlineCode = typeof children === 'string' ? children : null useEffect(() => { if (strategy === 'beforeInteractive') return if (typeof document === 'undefined') return const key = scriptKey({ id, src }) if (key === null) { handlers.current.onError?.( new Error('