{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport $89yE2$react, { useContext as $89yE2$useContext, useMemo as $89yE2$useMemo, useRef as $89yE2$useRef, useState as $89yE2$useState, useLayoutEffect as $89yE2$useLayoutEffect } from \"react\";\nvar $704cf1d3b684cc5c$var$defaultContext = {\n  prefix: String(Math.round(Math.random() * 10000000000)),\n  current: 0\n};\nvar $704cf1d3b684cc5c$var$SSRContext = (0, $89yE2$react).createContext($704cf1d3b684cc5c$var$defaultContext);\nfunction $704cf1d3b684cc5c$export$9f8ac96af4b1b2ae(props) {\n  var cur = (0, $89yE2$useContext)($704cf1d3b684cc5c$var$SSRContext);\n  var counter = $704cf1d3b684cc5c$var$useCounter(cur === $704cf1d3b684cc5c$var$defaultContext);\n  var value = (0, $89yE2$useMemo)(function () {\n    return {\n      prefix: cur === $704cf1d3b684cc5c$var$defaultContext ? \"\" : cur.prefix + \"-\" + counter,\n      current: 0\n    };\n  }, [cur, counter]);\n  return (0, $89yE2$react).createElement($704cf1d3b684cc5c$var$SSRContext.Provider, {\n    value: value\n  }, props.children);\n}\nvar $704cf1d3b684cc5c$var$canUseDOM = Boolean(typeof window !== \"undefined\" && window.document && window.document.createElement);\nvar $704cf1d3b684cc5c$var$componentIds = new WeakMap();\nfunction $704cf1d3b684cc5c$var$useCounter() {\n  var isDisabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n  var ctx = (0, $89yE2$useContext)($704cf1d3b684cc5c$var$SSRContext);\n  var ref = (0, $89yE2$useRef)(null);\n  if (ref.current === null && !isDisabled) {\n    var _React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, _React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_ReactCurrentOwner;\n    var currentOwner = (_React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = (0, $89yE2$react).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED === void 0 ? void 0 : (_React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_ReactCurrentOwner = _React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner) === null || _React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_ReactCurrentOwner === void 0 ? void 0 : _React___SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_ReactCurrentOwner.current;\n    if (currentOwner) {\n      var prevComponentValue = $704cf1d3b684cc5c$var$componentIds.get(currentOwner);\n      if (prevComponentValue == null) $704cf1d3b684cc5c$var$componentIds.set(currentOwner, {\n          id: ctx.current,\n          state: currentOwner.memoizedState\n        });else if (currentOwner.memoizedState !== prevComponentValue.state) {\n        ctx.current = prevComponentValue.id;\n        $704cf1d3b684cc5c$var$componentIds.delete(currentOwner);\n      }\n    }\n    ref.current = ++ctx.current;\n  }\n  return ref.current;\n}\nfunction $704cf1d3b684cc5c$export$619500959fc48b26(defaultId) {\n  var ctx = (0, $89yE2$useContext)($704cf1d3b684cc5c$var$SSRContext);\n  if (ctx === $704cf1d3b684cc5c$var$defaultContext && !$704cf1d3b684cc5c$var$canUseDOM) console.warn(\"When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.\");\n  var counter = $704cf1d3b684cc5c$var$useCounter(!!defaultId);\n  return defaultId || \"react-aria\" + ctx.prefix + \"-\" + counter;\n}\nfunction $704cf1d3b684cc5c$export$535bd6ca7f90a273() {\n  var cur = (0, $89yE2$useContext)($704cf1d3b684cc5c$var$SSRContext);\n  var isInSSRContext = cur !== $704cf1d3b684cc5c$var$defaultContext;\n  var _ref = (0, $89yE2$useState)(isInSSRContext),\n    _ref2 = _slicedToArray(_ref, 2),\n    isSSR = _ref2[0],\n    setIsSSR = _ref2[1];\n  if (typeof window !== \"undefined\" && isInSSRContext) (0, $89yE2$useLayoutEffect)(function () {\n      setIsSSR(false);\n    }, []);\n  return isSSR;\n}\nexport { $704cf1d3b684cc5c$export$9f8ac96af4b1b2ae as SSRProvider, $704cf1d3b684cc5c$export$619500959fc48b26 as useSSRSafeId, $704cf1d3b684cc5c$export$535bd6ca7f90a273 as useIsSSR };","map":{"version":3,"sources":["packages/@react-aria/ssr/src/SSRProvider.tsx"],"names":[],"mappings":";;AAiCA,IAAM,oCAAA,GAAkC;EACtC,MAAA,EAAQ,MAAA,CAAO,IAAA,CAAK,KAAK,CAAC,IAAA,CAAK,MAAM,CAAA,CAAA,GAAK,WAAA,CAAA,CAAA;EAC1C,OAAA,EAAS;AACX,CAAA;AAEA,IAAM,gCAAA,GAAa,CAAA,CAAA,EAAA,YAAK,EAAC,aAAa,CAAkB,oCAAA,CAAA;AAWjD,SAAS,yCAAA,CAAY,KAAuB,EAAe;EAChE,IAAI,GAAA,GAAM,CAAA,CAAA,EAAA,iBAAS,EAAE,gCAAA,CAAA;EACrB,IAAI,OAAA,GAAU,gCAAA,CAAW,GAAA,KAAQ,oCAAA,CAAA;EACjC,IAAI,KAAA,GAAyB,CAAA,CAAA,EAAA,cAAO,EAAC;IAAA,OAAO;MAG1C,MAAA,EAAQ,GAAA,KAAQ,oCAAA,GAAiB,EAAA,GAAQ,GAAA,CAAI,MAAM,SAAI,OAAS;MAChE,OAAA,EAAS;IACX,CAAA;EAAA,CAAA,EAAI,CAAC,GAAA,EAAK,OAAA,CAAQ,CAAA;EAElB,OACE,CAAA,CAAA,EAAA,YAAA,EAAA,aAAA,CAAC,gCAAA,CAAW,QAAQ,EAAA;IAAC,KAAA,EAAO;KACzB,KAAA,CAAM,QAAQ,CAAA;AAGrB;AAEA,IAAI,+BAAA,GAAY,OAAA,CACd,OAAO,MAAA,KAAW,WAAA,IAClB,MAAA,CAAO,QAAQ,IACf,MAAA,CAAO,QAAQ,CAAC,aAAa,CAAA;AAG/B,IAAI,kCAAA,GAAe,IAAI,O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AAM,CAAA,CAAA,EAAA,iBAAS,EAAE,gCAAA,CAAA;EAIrB,IAAI,GAAA,KAAQ,oCAAA,IAAkB,CAAC,+BAAA,EAC7B,OAAA,CAAQ,IAAI,CAAC,iJAAA,CAAA;EAGf,IAAI,OAAA,GAAU,gCAAA,CAAW,CAAC,CAAC,SAAA,CAAA;EAC3B,OAAO,SAAA,mBAA0B,GAAA,CAAI,MAAM,SAAI,OAAS;AAC1D;AAOO,SAAS,yCAAA,CAAA,EAAoB;EAClC,IAAI,GAAA,GAAM,CAAA,CAAA,EAAA,iBAAS,EAAE,gCAAA,CAAA;EACrB,IAAI,cAAA,GAAiB,GAAA,KAAQ,oCAAA;EAC7B,IAAA,IAAA,GAAwB,CAAA,CAAA,EAAA,eAAQ,EAAC,cAAA,CAAA;IAAA,KAAA,GAAA,cAAA,CAAA,IAAA;IAA5B,KAAA,GAAA,KAAA;IAAO,QAAA,GAAA,KAAA;EAIZ,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,cAAA,EAInC,CAAA,CAAA,EAAA,sBAAe,EAAC,YAAM;MACpB,QAAA,CAAS,KAAK,CAAA;IAChB,CAAA,EAAG,EAAE,CAAA;EAGP,OAAO,KAAA;AACT","sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// We must avoid a circular dependency with @react-aria/utils, and this useLayoutEffect is\n// guarded by a check that it only runs on the client side.\n// eslint-disable-next-line rulesdir/useLayoutEffectRule\nimport React, {ReactNode, useContext, useLayoutEffect, useMemo, useRef, useState} from 'react';\n\n// To support SSR, the auto incrementing id counter is stored in a context. This allows\n// it to be reset on every request to ensure the client and server are consistent.\n// There is also a prefix string that is used to support async loading components\n// Each async boundary must be wrapped in an SSR provider, which appends to the prefix\n// and resets the current id counter. This ensures that async loaded components have\n// consistent ids regardless of the loading order.\ninterface SSRContextValue {\n  prefix: string,\n  current: number\n}\n\n// Default context value to use in case there is no SSRProvider. This is fine for\n// client-only apps. In order to support multiple copies of React Aria potentially\n// being on the page at once, the prefix is set to a random number. SSRProvider\n// will reset this to zero for consistency between server and client, so in the\n// SSR case multiple copies of React Aria is not supported.\nconst defaultContext: SSRContextValue = {\n  prefix: String(Math.round(Math.random() * 10000000000)),\n  current: 0\n};\n\nconst SSRContext = React.createContext<SSRContextValue>(defaultContext);\n\nexport interface SSRProviderProps {\n  /** Your application here. */\n  children: ReactNode\n}\n\n/**\n * When using SSR with React Aria, applications must be wrapped in an SSRProvider.\n * This ensures that auto generated ids are consistent between the client and server.\n */\nexport function SSRProvider(props: SSRProviderProps): JSX.Element {\n  let cur = useContext(SSRContext);\n  let counter = useCounter(cur === defaultContext);\n  let value: SSRContextValue = useMemo(() => ({\n    // If this is the first SSRProvider, start with an empty string prefix, otherwise\n    // append and increment the counter.\n    prefix: cur === defaultContext ? '' : `${cur.prefix}-${counter}`,\n    current: 0\n  }), [cur, counter]);\n\n  return (\n    <SSRContext.Provider value={value}>\n      {props.children}\n    </SSRContext.Provider>\n  );\n}\n\nlet canUseDOM = Boolean(\n  typeof window !== 'undefined' &&\n  window.document &&\n  window.document.createElement\n);\n\nlet componentIds = new WeakMap();\n\nfunction useCounter(isDisabled = false) {\n  let ctx = useContext(SSRContext);\n  let ref = useRef<number | null>(null);\n  if (ref.current === null && !isDisabled) {\n    // In strict mode, React renders components twice, and the ref will be reset to null on the second render.\n    // This means our id counter will be incremented twice instead of once. This is a problem because on the\n    // server, components are only rendered once and so ids generated on the server won't match the client.\n    // In React 18, useId was introduced to solve this, but it is not available in older versions. So to solve this\n    // we need to use some React internals to access the underlying Fiber instance, which is stable between renders.\n    // This is exposed as ReactCurrentOwner in development, which is all we need since StrictMode only runs in development.\n    // To ensure that we only increment the global counter once, we store the starting id for this component in\n    // a weak map associated with the Fiber. On the second render, we reset the global counter to this value.\n    // Since React runs the second render immediately after the first, this is safe.\n    // @ts-ignore\n    let currentOwner = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentOwner?.current;\n    if (currentOwner) {\n      let prevComponentValue = componentIds.get(currentOwner);\n      if (prevComponentValue == null) {\n        // On the first render, and first call to useId, store the id and state in our weak map.\n        componentIds.set(currentOwner, {\n          id: ctx.current,\n          state: currentOwner.memoizedState\n        });\n      } else if (currentOwner.memoizedState !== prevComponentValue.state) {\n        // On the second render, the memoizedState gets reset by React.\n        // Reset the counter, and remove from the weak map so we don't\n        // do this for subsequent useId calls.\n        ctx.current = prevComponentValue.id;\n        componentIds.delete(currentOwner);\n      }\n    }\n\n    ref.current = ++ctx.current;\n  }\n\n  return ref.current;\n}\n\n/** @private */\nexport function useSSRSafeId(defaultId?: string): string {\n  let ctx = useContext(SSRContext);\n\n  // If we are rendering in a non-DOM environment, and there's no SSRProvider,\n  // provide a warning to hint to the developer to add one.\n  if (ctx === defaultContext && !canUseDOM) {\n    console.warn('When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.');\n  }\n\n  let counter = useCounter(!!defaultId);\n  return defaultId || `react-aria${ctx.prefix}-${counter}`;\n}\n\n/**\n * Returns whether the component is currently being server side rendered or\n * hydrated on the client. Can be used to delay browser-specific rendering\n * until after hydration.\n */\nexport function useIsSSR(): boolean {\n  let cur = useContext(SSRContext);\n  let isInSSRContext = cur !== defaultContext;\n  let [isSSR, setIsSSR] = useState(isInSSRContext);\n\n  // If on the client, and the component was initially server rendered,\n  // then schedule a layout effect to update the component after hydration.\n  if (typeof window !== 'undefined' && isInSSRContext) {\n    // This if statement technically breaks the rules of hooks, but is safe\n    // because the condition never changes after mounting.\n    // eslint-disable-next-line react-hooks/rules-of-hooks\n    useLayoutEffect(() => {\n      setIsSSR(false);\n    }, []);\n  }\n\n  return isSSR;\n}\n"]},"metadata":{},"sourceType":"module"}