UNPKG

6.44 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../../next-server/lib/dynamic.tsx"],"names":["isServerSide","window","noSSR","LoadableInitializer","loadableOptions","webpack","modules","Loading","loading","dynamic","dynamicOptions","options","loadableFn","Loadable","error","isLoading","pastDelay","process","env","NODE_ENV","message","stack","Promise","loader","loadableGenerated","ssr"],"mappings":"iFAAA,oDACA,4D,mFAEA,KAAMA,CAAAA,YAAY,CAAG,MAAOC,CAAAA,MAAP,GAAkB,WAAvC,CA0CO,QAASC,CAAAA,KAAT,CACLC,mBADK,CAELC,eAFK,CAGmB,CACxB;AACA,MAAOA,CAAAA,eAAe,CAACC,OAAvB,CACA,MAAOD,CAAAA,eAAe,CAACE,OAAvB,CAEA;AACA,GAAI,CAACN,YAAL,CAAmB,CACjB,MAAOG,CAAAA,mBAAmB,CAACC,eAAD,CAA1B,CACD,CAED,KAAMG,CAAAA,OAAO,CAAGH,eAAe,CAACI,OAAhC,CACA;AACA,MAAO,iBACL,6BAAC,OAAD,EAAS,KAAK,CAAE,IAAhB,CAAsB,SAAS,KAA/B,CAAgC,SAAS,CAAE,KAA3C,CAAkD,QAAQ,CAAE,KAA5D,EADF,CAGD,CAED;AAEe,QAASC,CAAAA,OAAT,CACbC,cADa,CAEbC,OAFa,CAGW,CACxB,GAAIC,CAAAA,UAAyB,CAAGC,iBAAhC,CACA,GAAIT,CAAAA,eAAmC,CAAG,CACxC;AACAI,OAAO,CAAE,CAAC,CAAEM,KAAF,CAASC,SAAT,CAAoBC,SAApB,CAAD,GAAqC,CAC5C,GAAI,CAACA,SAAL,CAAgB,MAAO,KAAP,CAChB,GAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,GAAyB,aAA7B,CAA4C,CAC1C,GAAIJ,SAAJ,CAAe,CACb,MAAO,KAAP,CACD,CACD,GAAID,KAAJ,CAAW,CACT,mBACE,sCACGA,KAAK,CAACM,OADT,cAEE,uCAFF,CAGGN,KAAK,CAACO,KAHT,CADF,CAOD,CACF,CAED,MAAO,KAAP,CACD,CApBuC,CAA1C,CAuBA;AACA;AACA;AACA;AACA,GAAIX,cAAc,WAAYY,CAAAA,OAA9B,CAAuC,CACrClB,eAAe,CAACmB,MAAhB,CAAyB,IAAMb,cAA/B,CACA;AACD,CAHD,IAGO,IAAI,MAAOA,CAAAA,cAAP,GAA0B,UAA9B,CAA0C,CAC/CN,eAAe,CAACmB,MAAhB,CAAyBb,cAAzB,CACA;AACD,CAHM,IAGA,IAAI,MAAOA,CAAAA,cAAP,GAA0B,QAA9B,CAAwC,CAC7CN,eAAe,CAAG,CAAE,GAAGA,eAAL,CAAsB,GAAGM,cAAzB,CAAlB,CACD,CAED;AACAN,eAAe,CAAG,CAAE,GAAGA,eAAL,CAAsB,GAAGO,OAAzB,CAAlB,CAEA;AACA,GAAIP,eAAe,CAACoB,iBAApB,CAAuC,CACrCpB,eAAe,CAAG,CAChB,GAAGA,eADa,CAEhB,GAAGA,eAAe,CAACoB,iBAFH,CAAlB,CAIA,MAAOpB,CAAAA,eAAe,CAACoB,iBAAvB,CACD,CAED;AACA,GAAI,MAAOpB,CAAAA,eAAe,CAACqB,GAAvB,GAA+B,SAAnC,CAA8C,CAC5C,GAAI,CAACrB,eAAe,CAACqB,GAArB,CAA0B,CACxB,MAAOrB,CAAAA,eAAe,CAACqB,GAAvB,CACA,MAAOvB,CAAAA,KAAK,CAACU,UAAD,CAAaR,eAAb,CAAZ,CACD,CACD,MAAOA,CAAAA,eAAe,CAACqB,GAAvB,CACD,CAED,MAAOb,CAAAA,UAAU,CAACR,eAAD,CAAjB,CACD","sourcesContent":["import React from 'react'\nimport Loadable from './loadable'\n\nconst isServerSide = typeof window === 'undefined'\n\nexport type LoaderComponent<P = {}> = Promise<\n React.ComponentType<P> | { default: React.ComponentType<P> }\n>\n\nexport type Loader<P = {}> = (() => LoaderComponent<P>) | LoaderComponent<P>\n\nexport type LoaderMap = { [mdule: string]: () => Loader<any> }\n\nexport type LoadableGeneratedOptions = {\n webpack?(): any\n modules?(): LoaderMap\n}\n\nexport type LoadableBaseOptions<P = {}> = LoadableGeneratedOptions & {\n loading?: ({\n error,\n isLoading,\n pastDelay,\n }: {\n error?: Error | null\n isLoading?: boolean\n pastDelay?: boolean\n retry?: () => void\n timedOut?: boolean\n }) => JSX.Element | null\n loader?: Loader<P> | LoaderMap\n loadableGenerated?: LoadableGeneratedOptions\n ssr?: boolean\n}\n\nexport type LoadableOptions<P = {}> = LoadableBaseOptions<P>\n\nexport type DynamicOptions<P = {}> = LoadableBaseOptions<P>\n\nexport type LoadableFn<P = {}> = (\n opts: LoadableOptions<P>\n) => React.ComponentType<P>\n\nexport type LoadableComponent<P = {}> = React.ComponentType<P>\n\nexport function noSSR<P = {}>(\n LoadableInitializer: LoadableFn<P>,\n loadableOptions: LoadableOptions<P>\n): React.ComponentType<P> {\n // Removing webpack and modules means react-loadable won't try preloading\n delete loadableOptions.webpack\n delete loadableOptions.modules\n\n // This check is necessary to prevent react-loadable from initializing on the server\n if (!isServerSide) {\n return LoadableInitializer(loadableOptions)\n }\n\n const Loading = loadableOptions.loading!\n // This will only be rendered on the server side\n return () => (\n <Loading error={null} isLoading pastDelay={false} timedOut={false} />\n )\n}\n\n// function dynamic<P = {}, O extends DynamicOptions>(options: O):\n\nexport default function dynamic<P = {}>(\n dynamicOptions: DynamicOptions<P> | Loader<P>,\n options?: DynamicOptions<P>\n): React.ComponentType<P> {\n let loadableFn: LoadableFn<P> = Loadable\n let loadableOptions: LoadableOptions<P> = {\n // A loading component is not required, so we default it\n loading: ({ error, isLoading, pastDelay }) => {\n if (!pastDelay) return null\n if (process.env.NODE_ENV === 'development') {\n if (isLoading) {\n return null\n }\n if (error) {\n return (\n <p>\n {error.message}\n <br />\n {error.stack}\n </p>\n )\n }\n }\n\n return null\n },\n }\n\n // Support for direct import(), eg: dynamic(import('../hello-world'))\n // Note that this is only kept for the edge case where someone is passing in a promise as first argument\n // The react-loadable babel plugin will turn dynamic(import('../hello-world')) into dynamic(() => import('../hello-world'))\n // To make sure we don't execute the import without rendering first\n if (dynamicOptions instanceof Promise) {\n loadableOptions.loader = () => dynamicOptions\n // Support for having import as a function, eg: dynamic(() => import('../hello-world'))\n } else if (typeof dynamicOptions === 'function') {\n loadableOptions.loader = dynamicOptions\n // Support for having first argument being options, eg: dynamic({loader: import('../hello-world')})\n } else if (typeof dynamicOptions === 'object') {\n loadableOptions = { ...loadableOptions, ...dynamicOptions }\n }\n\n // Support for passing options, eg: dynamic(import('../hello-world'), {loading: () => <p>Loading something</p>})\n loadableOptions = { ...loadableOptions, ...options }\n\n // coming from build/babel/plugins/react-loadable-plugin.js\n if (loadableOptions.loadableGenerated) {\n loadableOptions = {\n ...loadableOptions,\n ...loadableOptions.loadableGenerated,\n }\n delete loadableOptions.loadableGenerated\n }\n\n // support for disabling server side rendering, eg: dynamic(import('../hello-world'), {ssr: false})\n if (typeof loadableOptions.ssr === 'boolean') {\n if (!loadableOptions.ssr) {\n delete loadableOptions.ssr\n return noSSR(loadableFn, loadableOptions)\n }\n delete loadableOptions.ssr\n }\n\n return loadableFn(loadableOptions)\n}\n"]}
\No newline at end of file