preact
Version:
Fast 4kb React-compatible Virtual DOM library.
1 lines • 25.1 kB
Source Map (JSON)
{"version":3,"file":"hooks.mjs","sources":["../src/index.js"],"sourcesContent":["import { options as _options } from 'preact';\n\nconst ObjectIs = Object.is;\n\n/** @type {number} */\nlet currentIndex;\n\n/** @type {import('./internal').Component} */\nlet currentComponent;\n\n/** @type {import('./internal').Component} */\nlet previousComponent;\n\n/** @type {number} */\nlet currentHook = 0;\n\n/** @type {Array<import('./internal').Component>} */\nlet afterPaintEffects = [];\n\n/**\n * Passive (useEffect) hook states of unmounted components whose cleanup is\n * still pending. Deferred to the after-paint flush to match React, which runs\n * passive destroys after the commit has painted. Each state's `_passive` holds\n * the surviving component its errors should be routed to.\n * @type {Array<import('./internal').EffectHookState>}\n */\nlet unmountCleanups = [];\n\n// Cast to use internal Options type\nconst options = /** @type {import('./internal').Options} */ (_options);\n\nlet oldBeforeDiff = options._diff;\nlet oldBeforeRender = options._render;\nlet oldAfterDiff = options.diffed;\nlet oldCommit = options._commit;\nlet oldBeforeUnmount = options.unmount;\nlet oldRoot = options._root;\n\n// We take the minimum timeout for requestAnimationFrame to ensure that\n// the callback is invoked after the next frame. 35ms is based on a 30hz\n// refresh rate, which is the minimum rate for a smooth user experience.\nconst RAF_TIMEOUT = 35;\nlet prevRaf;\n\n/** @type {(vnode: import('./internal').VNode) => void} */\noptions._diff = vnode => {\n\tcurrentComponent = null;\n\tif (oldBeforeDiff) oldBeforeDiff(vnode);\n};\n\noptions._root = (vnode, parentDom) => {\n\tif (vnode && parentDom._children && parentDom._children._mask) {\n\t\tvnode._mask = parentDom._children._mask;\n\t}\n\n\tif (oldRoot) oldRoot(vnode, parentDom);\n};\n\n/** @type {(vnode: import('./internal').VNode) => void} */\noptions._render = vnode => {\n\tif (oldBeforeRender) oldBeforeRender(vnode);\n\n\tcurrentComponent = vnode._component;\n\tcurrentIndex = 0;\n\n\tconst hooks = currentComponent.__hooks;\n\tif (hooks) {\n\t\tif (previousComponent == currentComponent) {\n\t\t\tcurrentComponent._renderCallbacks = [];\n\t\t} else {\n\t\t\thooks._pendingEffects.some(invokeCleanup);\n\t\t\thooks._pendingEffects.some(invokeEffect);\n\t\t\tcurrentIndex = 0;\n\t\t}\n\t\thooks._pendingEffects = [];\n\n\t\t// Runs before every render, forced or not, so `shouldComponentUpdate`\n\t\t// never has to apply these itself.\n\t\thooks._list.some(hookItem => {\n\t\t\tif (hookItem._nextValue) {\n\t\t\t\thookItem._value = hookItem._nextValue;\n\t\t\t}\n\t\t\thookItem._pendingArgs = hookItem._nextValue = undefined;\n\t\t});\n\t}\n\tpreviousComponent = currentComponent;\n};\n\n/** @type {(vnode: import('./internal').VNode) => void} */\noptions.diffed = vnode => {\n\tif (oldAfterDiff) oldAfterDiff(vnode);\n\n\tconst c = vnode._component;\n\tif (c && c.__hooks) {\n\t\tif (c.__hooks._pendingEffects.length) afterPaint(afterPaintEffects.push(c));\n\t\t// `_pendingArgs` is cleared again by `options._render` before anything\n\t\t// can read it, so committing it here is enough.\n\t\tc.__hooks._list.some(hookItem => {\n\t\t\tif (hookItem._pendingArgs) hookItem._args = hookItem._pendingArgs;\n\t\t});\n\t}\n\tpreviousComponent = currentComponent = null;\n};\n\n// TODO: Improve typing of commitQueue parameter\n/** @type {(vnode: import('./internal').VNode, commitQueue: any) => void} */\noptions._commit = (vnode, commitQueue) => {\n\tcommitQueue.some(component => {\n\t\ttry {\n\t\t\tcomponent._renderCallbacks.some(invokeCleanup);\n\t\t\tcomponent._renderCallbacks = component._renderCallbacks.filter(cb =>\n\t\t\t\tcb._value ? invokeEffect(cb) : true\n\t\t\t);\n\t\t} catch (e) {\n\t\t\tcommitQueue.some(c => {\n\t\t\t\tif (c._renderCallbacks) c._renderCallbacks = [];\n\t\t\t});\n\t\t\tcommitQueue = [];\n\t\t\toptions._catchError(e, component._vnode);\n\t\t}\n\t});\n\n\tif (oldCommit) oldCommit(vnode, commitQueue);\n};\n\n/** @type {(vnode: import('./internal').VNode) => void} */\noptions.unmount = vnode => {\n\tif (oldBeforeUnmount) oldBeforeUnmount(vnode);\n\n\tconst c = vnode._component;\n\tif (c && c.__hooks) {\n\t\tlet hasErrored, errorParent;\n\t\tc.__hooks._list.some(s => {\n\t\t\ttry {\n\t\t\t\t// Layout cleanups have to run before the new DOM is in place, so\n\t\t\t\t// they stay in the commit phase (see #1886). Passive cleanups run\n\t\t\t\t// after paint, before any new passive effect (see #4299), with\n\t\t\t\t// `_passive` repurposed to hold the error-routing component.\n\t\t\t\tif (s._passive && s._cleanup) {\n\t\t\t\t\tif (errorParent === undefined) {\n\t\t\t\t\t\terrorParent = vnode._parent;\n\t\t\t\t\t\twhile (\n\t\t\t\t\t\t\terrorParent &&\n\t\t\t\t\t\t\t!(errorParent._component && errorParent._component._parentDom)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\terrorParent = errorParent._parent;\n\t\t\t\t\t\t}\n\t\t\t\t\t\terrorParent = errorParent && errorParent._component;\n\t\t\t\t\t}\n\t\t\t\t\ts._passive = errorParent;\n\t\t\t\t\tafterPaint(unmountCleanups.push(s));\n\t\t\t\t} else {\n\t\t\t\t\tinvokeCleanup(s);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\thasErrored = e;\n\t\t\t}\n\t\t});\n\t\tc.__hooks = undefined;\n\t\tif (hasErrored) options._catchError(hasErrored, c._vnode);\n\t}\n};\n\n/**\n * Get a hook's state from the currentComponent\n * @param {number} index The index of the hook to get\n * @param {number} type The type of the hook to get\n * @returns {any}\n */\nfunction getHookState(index, type) {\n\tif (options._hook) {\n\t\toptions._hook(currentComponent, index, currentHook || type);\n\t}\n\tcurrentHook = 0;\n\n\t// Largely inspired by:\n\t// * https://github.com/michael-klein/funcy.js/blob/f6be73468e6ec46b0ff5aa3cc4c9baf72a29025a/src/hooks/core_hooks.mjs\n\t// * https://github.com/michael-klein/funcy.js/blob/650beaa58c43c33a74820a3c98b3c7079cf2e333/src/renderer.mjs\n\t// Other implementations to look at:\n\t// * https://codesandbox.io/s/mnox05qp8\n\tconst hooks =\n\t\tcurrentComponent.__hooks ||\n\t\t(currentComponent.__hooks = {\n\t\t\t_list: [],\n\t\t\t_pendingEffects: []\n\t\t});\n\n\tif (index >= hooks._list.length) {\n\t\thooks._list.push({});\n\t}\n\n\treturn hooks._list[index];\n}\n\n/**\n * @template {unknown} S\n * @param {import('./index').Dispatch<import('./index').StateUpdater<S>>} [initialState]\n * @returns {[S, (state: S) => void]}\n */\nexport function useState(initialState) {\n\tcurrentHook = 1;\n\treturn useReducer(invokeOrReturn, initialState);\n}\n\n/**\n * @template {unknown} S\n * @template {unknown} A\n * @param {import('./index').Reducer<S, A>} reducer\n * @param {import('./index').Dispatch<import('./index').StateUpdater<S>>} initialState\n * @param {(initialState: any) => void} [init]\n * @returns {[ S, (state: S) => void ]}\n */\nexport function useReducer(reducer, initialState, init) {\n\t/** @type {import('./internal').ReducerHookState} */\n\tconst hookState = getHookState(currentIndex++, 2);\n\thookState._reducer = reducer;\n\tif (!hookState._component) {\n\t\thookState._value = [\n\t\t\t!init ? invokeOrReturn(undefined, initialState) : init(initialState),\n\n\t\t\taction => {\n\t\t\t\tconst currentValue = hookState._nextValue\n\t\t\t\t\t? hookState._nextValue[0]\n\t\t\t\t\t: hookState._value[0];\n\t\t\t\tconst nextValue = hookState._reducer(currentValue, action);\n\n\t\t\t\tif (!ObjectIs(currentValue, nextValue)) {\n\t\t\t\t\thookState._nextValue = [nextValue, hookState._value[1]];\n\t\t\t\t\thookState._component.setState({});\n\t\t\t\t}\n\t\t\t}\n\t\t];\n\n\t\thookState._component = currentComponent;\n\n\t\tif (!currentComponent._hasScuFromHooks) {\n\t\t\tcurrentComponent._hasScuFromHooks = true;\n\t\t\tconst prevScu = currentComponent.shouldComponentUpdate;\n\n\t\t\t// This SCU has the purpose of bailing out after repeated updates\n\t\t\t// to stateful hooks. We store the next value in `_nextValue[0]` and\n\t\t\t// keep doing that for all state setters; if we have next states and\n\t\t\t// all next states within a component end up being equal to their\n\t\t\t// original state we are safe to bail out for this specific component.\n\t\t\tcurrentComponent.shouldComponentUpdate = function (p, s, c) {\n\t\t\t\tconst hooks = this.__hooks;\n\t\t\t\tif (!hooks) return true;\n\n\t\t\t\t// We check whether we have components with a nextValue set that\n\t\t\t\t// have values that aren't equal to one another this pushes\n\t\t\t\t// us to update further down the tree\n\t\t\t\tlet updatedHook = false;\n\t\t\t\tlet shouldUpdate = this.props != p;\n\t\t\t\thooks._list.some(hookItem => {\n\t\t\t\t\tif (hookItem._nextValue) {\n\t\t\t\t\t\tupdatedHook = true;\n\t\t\t\t\t\tif (!ObjectIs(hookItem._value[0], hookItem._nextValue[0])) {\n\t\t\t\t\t\t\tshouldUpdate = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tif (prevScu) {\n\t\t\t\t\tconst result = prevScu.call(this, p, s, c);\n\t\t\t\t\treturn updatedHook ? result || shouldUpdate : result;\n\t\t\t\t}\n\n\t\t\t\treturn !updatedHook || shouldUpdate;\n\t\t\t};\n\t\t}\n\t}\n\n\treturn hookState._value;\n}\n\n/**\n * @param {import('./internal').Effect} callback\n * @param {unknown[]} args\n * @returns {void}\n */\nexport function useEffect(callback, args) {\n\t/** @type {import('./internal').EffectHookState} */\n\tconst state = getHookState(currentIndex++, 3);\n\tif (!options._skipEffects && argsChanged(state._args, args)) {\n\t\tstate._passive = true;\n\t\tstate._value = callback;\n\t\tstate._pendingArgs = args;\n\n\t\tcurrentComponent.__hooks._pendingEffects.push(state);\n\t}\n}\n\n/**\n * @param {import('./internal').Effect} callback\n * @param {unknown[]} args\n * @returns {void}\n */\nexport function useLayoutEffect(callback, args) {\n\t/** @type {import('./internal').EffectHookState} */\n\tconst state = getHookState(currentIndex++, 4);\n\tif (!options._skipEffects && argsChanged(state._args, args)) {\n\t\tstate._passive = false;\n\t\tstate._value = callback;\n\t\tstate._pendingArgs = args;\n\n\t\tcurrentComponent._renderCallbacks.push(state);\n\t}\n}\n\n/** @type {(initialValue: unknown) => unknown} */\nexport function useRef(initialValue) {\n\tcurrentHook = 5;\n\treturn useMemo(() => ({ current: initialValue }), []);\n}\n\n/**\n * @param {object} ref\n * @param {() => object} createHandle\n * @param {unknown[]} args\n * @returns {void}\n */\nexport function useImperativeHandle(ref, createHandle, args) {\n\tcurrentHook = 6;\n\tuseLayoutEffect(\n\t\t() => {\n\t\t\tif (typeof ref == 'function') {\n\t\t\t\tconst result = ref(createHandle());\n\t\t\t\treturn () => {\n\t\t\t\t\tref(null);\n\t\t\t\t\tif (result && typeof result == 'function') result();\n\t\t\t\t};\n\t\t\t} else if (ref) {\n\t\t\t\tref.current = createHandle();\n\t\t\t\treturn () => (ref.current = null);\n\t\t\t}\n\t\t},\n\t\targs == null ? args : args.concat(ref)\n\t);\n}\n\n/**\n * @template {unknown} T\n * @param {() => T} factory\n * @param {unknown[]} args\n * @returns {T}\n */\nexport function useMemo(factory, args) {\n\t/** @type {import('./internal').MemoHookState<T>} */\n\tconst state = getHookState(currentIndex++, 7);\n\tif (argsChanged(state._args, args)) {\n\t\tstate._value = factory();\n\t\tstate._args = args;\n\t}\n\n\treturn state._value;\n}\n\n/**\n * @param {() => void} callback\n * @param {unknown[]} args\n * @returns {() => void}\n */\nexport function useCallback(callback, args) {\n\tcurrentHook = 8;\n\treturn useMemo(() => callback, args);\n}\n\n/**\n * @param {import('./internal').PreactContext} context\n */\nexport function useContext(context) {\n\tconst provider = currentComponent.context[context._id];\n\t// We could skip this call here, but than we'd not call\n\t// `options._hook`. We need to do that in order to make\n\t// the devtools aware of this hook.\n\t/** @type {import('./internal').ContextHookState} */\n\tconst state = getHookState(currentIndex++, 9);\n\t// The devtools needs access to the context object to\n\t// be able to pull of the default value when no provider\n\t// is present in the tree.\n\tstate._context = context;\n\tif (!provider) return context._defaultValue;\n\t// This is probably not safe to convert to \"!\"\n\tif (state._value == null) {\n\t\tstate._value = true;\n\t\tprovider.sub(currentComponent);\n\t}\n\treturn provider.props.value;\n}\n\n/**\n * Display a custom label for a custom hook for the devtools panel\n * @type {<T>(value: T, cb?: (value: T) => string | number) => void}\n */\nexport function useDebugValue(value, formatter) {\n\tif (options.useDebugValue) {\n\t\toptions.useDebugValue(\n\t\t\tformatter ? formatter(value) : /** @type {any}*/ (value)\n\t\t);\n\t}\n}\n\n/**\n * @param {(error: unknown, errorInfo: import('preact').ErrorInfo) => void} cb\n * @returns {[unknown, () => void]}\n */\nexport function useErrorBoundary(cb) {\n\t/** @type {import('./internal').ErrorBoundaryHookState} */\n\tconst state = getHookState(currentIndex++, 10);\n\tconst errState = useState();\n\tstate._value = cb;\n\tif (!currentComponent.componentDidCatch) {\n\t\tcurrentComponent.componentDidCatch = (err, errorInfo) => {\n\t\t\tif (state._value) state._value(err, errorInfo);\n\t\t\terrState[1](err);\n\t\t};\n\t}\n\treturn [\n\t\terrState[0],\n\t\t() => {\n\t\t\terrState[1](undefined);\n\t\t}\n\t];\n}\n\n/** @type {() => string} */\nexport function useId() {\n\t/** @type {import('./internal').IdHookState} */\n\tconst state = getHookState(currentIndex++, 11);\n\tif (!state._value) {\n\t\t// Grab either the root node or the nearest async boundary node.\n\t\t/** @type {import('./internal').VNode} */\n\t\tlet root = currentComponent._vnode;\n\t\twhile (!root._mask && root._parent) {\n\t\t\troot = root._parent;\n\t\t}\n\n\t\tlet mask = root._mask || (root._mask = [0, 0]);\n\t\tstate._value = 'P' + mask[0] + '-' + mask[1]++;\n\t}\n\n\treturn state._value;\n}\n\n/**\n * After paint effects consumer.\n */\nfunction flushAfterPaintEffects() {\n\tlet component;\n\t// The loop picks up components unmounted by an effect we just invoked, which\n\t// don't necessarily schedule a flush of their own.\n\tdo {\n\t\t// Unmounted components' passive cleanups run before any new passive\n\t\t// effect, mirroring React running all destroys before any create.\n\t\twhile ((component = unmountCleanups.shift())) {\n\t\t\ttry {\n\t\t\t\tinvokeCleanup(component);\n\t\t\t} catch (e) {\n\t\t\t\tcomponent = /** @type {any} */ (component._passive);\n\t\t\t\toptions._catchError(e, { _parent: component && component._vnode });\n\t\t\t}\n\t\t}\n\n\t\twhile ((component = afterPaintEffects.shift())) {\n\t\t\tconst hooks = component.__hooks;\n\t\t\tif (!component._parentDom || !hooks) continue;\n\t\t\ttry {\n\t\t\t\thooks._pendingEffects.some(invokeCleanup);\n\t\t\t\thooks._pendingEffects.some(invokeEffect);\n\t\t\t\thooks._pendingEffects = [];\n\t\t\t} catch (e) {\n\t\t\t\thooks._pendingEffects = [];\n\t\t\t\toptions._catchError(e, component._vnode);\n\t\t\t}\n\t\t}\n\t} while (unmountCleanups.length);\n}\n\nlet HAS_RAF = typeof requestAnimationFrame == 'function';\n\n/**\n * Schedule a callback to be invoked after the browser has a chance to paint a new frame.\n * Do this by combining requestAnimationFrame (rAF) + setTimeout to invoke a callback after\n * the next browser frame.\n *\n * Also, schedule a timeout in parallel to the the rAF to ensure the callback is invoked\n * even if RAF doesn't fire (for example if the browser tab is not visible)\n *\n * @param {() => void} callback\n */\nfunction afterNextFrame(callback) {\n\tconst done = () => {\n\t\tclearTimeout(timeout);\n\t\tif (HAS_RAF) cancelAnimationFrame(raf);\n\t\tsetTimeout(callback);\n\t};\n\tconst timeout = setTimeout(done, RAF_TIMEOUT);\n\n\tlet raf;\n\tif (HAS_RAF) {\n\t\traf = requestAnimationFrame(done);\n\t}\n}\n\n// Note: if someone used options.debounceRendering = requestAnimationFrame,\n// then effects will ALWAYS run on the NEXT frame instead of the current one, incurring a ~16ms delay.\n// Perhaps this is not such a big deal.\n/**\n * Schedule afterPaintEffects flush after the browser paints\n * @param {number} newQueueLength\n * @returns {void}\n */\nfunction afterPaint(newQueueLength) {\n\tif (newQueueLength == 1 || prevRaf != options.requestAnimationFrame) {\n\t\tprevRaf = options.requestAnimationFrame;\n\t\t(prevRaf || afterNextFrame)(flushAfterPaintEffects);\n\t}\n}\n\n/**\n * @param {import('./internal').HookState} hook\n * @returns {void}\n */\nfunction invokeCleanup(hook) {\n\t// A hook cleanup can introduce a call to render which creates a new root, this will call options.vnode\n\t// and move the currentComponent away.\n\tconst comp = currentComponent;\n\tlet cleanup = hook._cleanup;\n\tif (typeof cleanup == 'function') {\n\t\thook._cleanup = undefined;\n\t\tcleanup();\n\t}\n\n\tcurrentComponent = comp;\n}\n\n/**\n * Invoke a Hook's effect\n * @param {import('./internal').EffectHookState} hook\n * @returns {void}\n */\nfunction invokeEffect(hook) {\n\t// A hook call can introduce a call to render which creates a new root, this will call options.vnode\n\t// and move the currentComponent away.\n\tconst comp = currentComponent;\n\thook._cleanup = hook._value();\n\tcurrentComponent = comp;\n}\n\n/**\n * @param {unknown[]} oldArgs\n * @param {unknown[]} newArgs\n * @returns {boolean}\n */\nfunction argsChanged(oldArgs, newArgs) {\n\treturn (\n\t\t!oldArgs ||\n\t\toldArgs.length != newArgs.length ||\n\t\tnewArgs.some((arg, index) => !ObjectIs(arg, oldArgs[index]))\n\t);\n}\n\n/**\n * @template Arg\n * @param {Arg} arg\n * @param {(arg: Arg) => any} f\n * @returns {any}\n */\nfunction invokeOrReturn(arg, f) {\n\treturn typeof f == 'function' ? f(arg) : f;\n}\n"],"names":["currentIndex","currentComponent","previousComponent","prevRaf","ObjectIs","Object","is","currentHook","afterPaintEffects","unmountCleanups","options","_options","oldBeforeDiff","__b","oldBeforeRender","__r","oldAfterDiff","diffed","oldCommit","__c","oldBeforeUnmount","unmount","oldRoot","__","getHookState","index","type","__h","hooks","__H","length","push","useState","initialState","useReducer","invokeOrReturn","reducer","init","hookState","_reducer","undefined","action","currentValue","__N","nextValue","setState","__f","prevScu","shouldComponentUpdate","p","s","c","this","updatedHook","shouldUpdate","props","some","hookItem","result","call","useEffect","callback","args","state","__s","argsChanged","__P","_pendingArgs","useLayoutEffect","useRef","initialValue","useMemo","current","useImperativeHandle","ref","createHandle","concat","factory","useCallback","useContext","context","provider","sub","value","useDebugValue","formatter","useErrorBoundary","cb","errState","componentDidCatch","err","errorInfo","useId","root","__v","__m","mask","flushAfterPaintEffects","component","shift","invokeCleanup","e","__e","invokeEffect","vnode","parentDom","__k","afterPaint","commitQueue","filter","hasErrored","errorParent","HAS_RAF","requestAnimationFrame","afterNextFrame","raf","done","clearTimeout","timeout","cancelAnimationFrame","setTimeout","newQueueLength","hook","comp","cleanup","oldArgs","newArgs","arg","f"],"mappings":"iCAEA,IAGIA,EAGAC,EAGAC,EA+BAC,EAxCEC,EAAWC,OAAOC,GAYpBC,EAAc,EAGdC,EAAoB,GASpBC,EAAkB,GAGhBC,EAAuDC,EAEzDC,EAAgBF,EAAOG,IACvBC,EAAkBJ,EAAOK,IACzBC,EAAeN,EAAQO,OACvBC,EAAYR,EAAOS,IACnBC,EAAmBV,EAAQW,QAC3BC,EAAUZ,EAAOa,GAqIrB,SAASC,EAAaC,EAAOC,GACxBhB,EAAOiB,KACVjB,EAAOiB,IAAO1B,EAAkBwB,EAAOlB,GAAemB,GAEvDnB,EAAc,EAOd,IAAMqB,EACL3B,EAAgB4B,MACf5B,EAAgB4B,IAAW,CAC3BN,GAAO,GACPI,IAAiB,KAOnB,OAJIF,GAASG,EAAKL,GAAOO,QACxBF,EAAKL,GAAOQ,KAAK,IAGXH,EAAKL,GAAOE,EACpB,CAOO,SAASO,EAASC,GAExB,OADA1B,EAAc,EACP2B,EAAWC,EAAgBF,EACnC,CAUO,SAASC,EAAWE,EAASH,EAAcI,GAEjD,IAAMC,EAAYd,EAAaxB,IAAgB,GAE/C,GADAsC,EAAUC,EAAWH,GAChBE,EAASnB,MACbmB,EAASf,GAAU,CACjBc,EAAiDA,EAAKJ,GAA/CE,OAAeK,EAAWP,GAElC,SAAAQ,GACC,IAAMC,EAAeJ,EAASK,IAC3BL,EAASK,IAAY,GACrBL,EAASf,GAAQ,GACdqB,EAAYN,EAAUC,EAASG,EAAcD,GAE9CrC,EAASsC,EAAcE,KAC3BN,EAASK,IAAc,CAACC,EAAWN,EAASf,GAAQ,IACpDe,EAASnB,IAAY0B,SAAS,IAEhC,GAGDP,EAASnB,IAAclB,GAElBA,EAAgB6C,KAAmB,CACvC7C,EAAg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