UNPKG

next

Version:

The React Framework

16 lines 2.91 kB
"use strict";exports.__esModule=true;exports.noSSR=noSSR;exports.default=dynamic;var _react=_interopRequireDefault(require("react"));var _loadable=_interopRequireDefault(require("./loadable"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}const isServerSide=typeof window==='undefined';function noSSR(LoadableInitializer,loadableOptions){// Removing webpack and modules means react-loadable won't try preloading delete loadableOptions.webpack;delete loadableOptions.modules;// This check is necessary to prevent react-loadable from initializing on the server if(!isServerSide){return LoadableInitializer(loadableOptions);}const Loading=loadableOptions.loading;// This will only be rendered on the server side return()=>/*#__PURE__*/_react.default.createElement(Loading,{error:null,isLoading:true,pastDelay:false,timedOut:false});}// function dynamic<P = {}, O extends DynamicOptions>(options: O): function dynamic(dynamicOptions,options){let loadableFn=_loadable.default;let loadableOptions={// A loading component is not required, so we default it loading:({error,isLoading,pastDelay})=>{if(!pastDelay)return null;if(process.env.NODE_ENV==='development'){if(isLoading){return null;}if(error){return/*#__PURE__*/_react.default.createElement("p",null,error.message,/*#__PURE__*/_react.default.createElement("br",null),error.stack);}}return null;}};// Support for direct import(), eg: dynamic(import('../hello-world')) // Note that this is only kept for the edge case where someone is passing in a promise as first argument // The react-loadable babel plugin will turn dynamic(import('../hello-world')) into dynamic(() => import('../hello-world')) // To make sure we don't execute the import without rendering first if(dynamicOptions instanceof Promise){loadableOptions.loader=()=>dynamicOptions;// Support for having import as a function, eg: dynamic(() => import('../hello-world')) }else if(typeof dynamicOptions==='function'){loadableOptions.loader=dynamicOptions;// Support for having first argument being options, eg: dynamic({loader: import('../hello-world')}) }else if(typeof dynamicOptions==='object'){loadableOptions={...loadableOptions,...dynamicOptions};}// Support for passing options, eg: dynamic(import('../hello-world'), {loading: () => <p>Loading something</p>}) loadableOptions={...loadableOptions,...options};// coming from build/babel/plugins/react-loadable-plugin.js if(loadableOptions.loadableGenerated){loadableOptions={...loadableOptions,...loadableOptions.loadableGenerated};delete loadableOptions.loadableGenerated;}// support for disabling server side rendering, eg: dynamic(import('../hello-world'), {ssr: false}) if(typeof loadableOptions.ssr==='boolean'){if(!loadableOptions.ssr){delete loadableOptions.ssr;return noSSR(loadableFn,loadableOptions);}delete loadableOptions.ssr;}return loadableFn(loadableOptions);} //# sourceMappingURL=dynamic.js.map