UNPKG

2.8 kBSource Map (JSON)View Raw
1{"version":3,"names":["CurrentRenderContext","React","ServerContext","forwardRef","ServerContainer","ref","children","location","useEffect","console","error","current","value","getCurrentOptions","options"],"sources":["ServerContainer.tsx"],"sourcesContent":["import { CurrentRenderContext } from '@react-navigation/core';\nimport * as React from 'react';\n\nimport ServerContext, { ServerContextType } from './ServerContext';\nimport type { ServerContainerRef } from './types';\n\ntype Props = ServerContextType & {\n children: React.ReactNode;\n};\n\n/**\n * Container component for server rendering.\n *\n * @param props.location Location object to base the initial URL for SSR.\n * @param props.children Child elements to render the content.\n * @param props.ref Ref object which contains helper methods.\n */\nexport default React.forwardRef(function ServerContainer(\n { children, location }: Props,\n ref: React.Ref<ServerContainerRef>\n) {\n React.useEffect(() => {\n console.error(\n \"'ServerContainer' should only be used on the server with 'react-dom/server' for SSR.\"\n );\n }, []);\n\n const current: { options?: object } = {};\n\n if (ref) {\n const value = {\n getCurrentOptions() {\n return current.options;\n },\n };\n\n // We write to the `ref` during render instead of `React.useImperativeHandle`\n // This is because `useImperativeHandle` will update the ref after 'commit',\n // and there's no 'commit' phase during SSR.\n // Mutating ref during render is unsafe in concurrent mode, but we don't care about it for SSR.\n if (typeof ref === 'function') {\n ref(value);\n } else {\n // @ts-expect-error: the TS types are incorrect and say that ref.current is readonly\n ref.current = value;\n }\n }\n\n return (\n <ServerContext.Provider value={{ location }}>\n <CurrentRenderContext.Provider value={current}>\n {children}\n </CurrentRenderContext.Provider>\n </ServerContext.Provider>\n );\n});\n"],"mappings":"AAAA,SAASA,oBAAT,QAAqC,wBAArC;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,aAAP,MAAiD,iBAAjD;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAAeD,KAAK,CAACE,UAAN,CAAiB,SAASC,eAAT,OAE9BC,GAF8B,EAG9B;EAAA,IAFA;IAAEC,QAAF;IAAYC;EAAZ,CAEA;EACAN,KAAK,CAACO,SAAN,CAAgB,MAAM;IACpBC,OAAO,CAACC,KAAR,CACE,sFADF;EAGD,CAJD,EAIG,EAJH;EAMA,MAAMC,OAA6B,GAAG,EAAtC;;EAEA,IAAIN,GAAJ,EAAS;IACP,MAAMO,KAAK,GAAG;MACZC,iBAAiB,GAAG;QAClB,OAAOF,OAAO,CAACG,OAAf;MACD;;IAHW,CAAd,CADO,CAOP;IACA;IACA;IACA;;IACA,IAAI,OAAOT,GAAP,KAAe,UAAnB,EAA+B;MAC7BA,GAAG,CAACO,KAAD,CAAH;IACD,CAFD,MAEO;MACL;MACAP,GAAG,CAACM,OAAJ,GAAcC,KAAd;IACD;EACF;;EAED,oBACE,oBAAC,aAAD,CAAe,QAAf;IAAwB,KAAK,EAAE;MAAEL;IAAF;EAA/B,gBACE,oBAAC,oBAAD,CAAsB,QAAtB;IAA+B,KAAK,EAAEI;EAAtC,GACGL,QADH,CADF,CADF;AAOD,CAtCc,CAAf"}
\No newline at end of file