{"version":3,"file":"bdc6553c.js","sources":["../../../node_modules/@shopify/hydrogen/dist/esnext/foundation/useUrl/useUrl.js"],"sourcesContent":["import { useContext, useMemo } from 'react';\nimport { RSC_PATHNAME } from '../../constants.js';\nimport { parseJSON } from '../../utilities/parse.js';\nimport { RouterContext } from '../Router/BrowserRouter.client.js';\nimport { useEnvContext, META_ENV_SSR } from '../ssr-interop.js';\n/**\n * The `useUrl` hook retrieves the current URL in a server or client component.\n */\nexport function useUrl() {\n if (META_ENV_SSR) {\n const serverUrl = new URL(useEnvContext((req) => req.url) // eslint-disable-line react-hooks/rules-of-hooks\n );\n if (serverUrl.pathname === RSC_PATHNAME) {\n const state = parseJSON(serverUrl.searchParams.get('state') || '{}');\n const parsedUrl = `${serverUrl.origin}${state.pathname ?? ''}${state.search ?? ''}`;\n return new URL(parsedUrl);\n }\n return new URL(serverUrl);\n }\n /**\n * We return a `URL` object instead of passing through `location` because\n * the URL object contains important info like hostname, etc.\n * Note: do not call `useLocation` directly here to avoid throwing errors\n * when `useUrl` is used outside of a Router component (e.g. in ).\n */\n const location = useContext(RouterContext); // eslint-disable-line react-hooks/rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useMemo(() => new URL(window.location.href), [location]); // eslint-disable-line react-hooks/exhaustive-deps\n}\n"],"names":["useUrl","META_ENV_SSR","serverUrl","useEnvContext","RSC_PATHNAME","state","parseJSON","parsedUrl","_a","_b","location","useContext","RouterContext","useMemo"],"mappings":"4JAQO,SAASA,GAAS,SACrB,GAAIC,EAAc,CACd,MAAMC,EAAY,IAAI,IAAIC,EAA8B,CAChE,EACQ,GAAID,EAAU,WAAaE,EAAc,CACrC,MAAMC,EAAQC,EAAUJ,EAAU,aAAa,IAAI,OAAO,GAAK,IAAI,EAC7DK,EAAY,GAAGL,EAAU,UAASM,EAAAH,EAAM,WAAN,KAAAG,EAAkB,MAAKC,EAAAJ,EAAM,SAAN,KAAAI,EAAgB,KAC/E,OAAO,IAAI,IAAIF,CAAS,CAC3B,CACD,OAAO,IAAI,IAAIL,CAAS,CAC3B,CAOD,MAAMQ,EAAWC,qBAAWC,CAAa,EAEzC,OAAOC,EAAO,QAAA,QAAC,IAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAAG,CAACH,CAAQ,CAAC,CAClE"}