Initial boiler plate project

This commit is contained in:
2024-09-24 03:52:46 +00:00
parent 6120b2d6c3
commit 154b93e267
10034 changed files with 2079352 additions and 2 deletions

View File

@ -0,0 +1,8 @@
/** An error that should be thrown when we want to bail out to client-side rendering. */
export declare class BailoutToCSRError extends Error {
readonly reason: string;
readonly digest = "BAILOUT_TO_CLIENT_SIDE_RENDERING";
constructor(reason: string);
}
/** Checks if a passed argument is an error that is thrown if we want to bail out to client-side rendering. */
export declare function isBailoutToCSRError(err: unknown): err is BailoutToCSRError;

View File

@ -0,0 +1,39 @@
// This has to be a shared module which is shared between client component error boundary and dynamic component
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
BailoutToCSRError: null,
isBailoutToCSRError: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
BailoutToCSRError: function() {
return BailoutToCSRError;
},
isBailoutToCSRError: function() {
return isBailoutToCSRError;
}
});
const BAILOUT_TO_CSR = "BAILOUT_TO_CLIENT_SIDE_RENDERING";
class BailoutToCSRError extends Error {
constructor(reason){
super("Bail out to client-side rendering: " + reason);
this.reason = reason;
this.digest = BAILOUT_TO_CSR;
}
}
function isBailoutToCSRError(err) {
if (typeof err !== "object" || err === null || !("digest" in err)) {
return false;
}
return err.digest === BAILOUT_TO_CSR;
}
//# sourceMappingURL=bailout-to-csr.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/lazy-dynamic/bailout-to-csr.ts"],"names":["BailoutToCSRError","isBailoutToCSRError","BAILOUT_TO_CSR","Error","constructor","reason","digest","err"],"mappings":"AAAA,+GAA+G;;;;;;;;;;;;;;;;IAIlGA,iBAAiB;eAAjBA;;IASGC,mBAAmB;eAAnBA;;;AAZhB,MAAMC,iBAAiB;AAGhB,MAAMF,0BAA0BG;IAGrCC,YAAY,AAAgBC,MAAc,CAAE;QAC1C,KAAK,CAAC,AAAC,wCAAqCA;aADlBA,SAAAA;aAFZC,SAASJ;IAIzB;AACF;AAGO,SAASD,oBAAoBM,GAAY;IAC9C,IAAI,OAAOA,QAAQ,YAAYA,QAAQ,QAAQ,CAAE,CAAA,YAAYA,GAAE,GAAI;QACjE,OAAO;IACT;IAEA,OAAOA,IAAID,MAAM,KAAKJ;AACxB"}

View File

@ -0,0 +1,11 @@
import type { ReactElement } from 'react';
interface BailoutToCSRProps {
reason: string;
children: ReactElement;
}
/**
* If rendered on the server, this component throws an error
* to signal Next.js that it should bail out to client-side rendering instead.
*/
export declare function BailoutToCSR({ reason, children }: BailoutToCSRProps): ReactElement<any, string | import("react").JSXElementConstructor<any>>;
export {};

View File

@ -0,0 +1,22 @@
"use client";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "BailoutToCSR", {
enumerable: true,
get: function() {
return BailoutToCSR;
}
});
const _bailouttocsr = require("./bailout-to-csr");
function BailoutToCSR(param) {
let { reason, children } = param;
if (typeof window === "undefined") {
throw new _bailouttocsr.BailoutToCSRError(reason);
}
return children;
}
//# sourceMappingURL=dynamic-bailout-to-csr.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/lazy-dynamic/dynamic-bailout-to-csr.tsx"],"names":["BailoutToCSR","reason","children","window","BailoutToCSRError"],"mappings":"AAAA;;;;;+BAcgBA;;;eAAAA;;;8BAXkB;AAW3B,SAASA,aAAa,KAAuC;IAAvC,IAAA,EAAEC,MAAM,EAAEC,QAAQ,EAAqB,GAAvC;IAC3B,IAAI,OAAOC,WAAW,aAAa;QACjC,MAAM,IAAIC,+BAAiB,CAACH;IAC9B;IAEA,OAAOC;AACT"}

View File

@ -0,0 +1,13 @@
/// <reference types="react" />
import type { ComponentModule } from './types';
interface LoadableOptions {
loader?: () => Promise<React.ComponentType<any> | ComponentModule<any>>;
loading?: React.ComponentType<any> | null;
ssr?: boolean;
modules?: string[];
}
declare function Loadable(options: LoadableOptions): {
(props: any): import("react/jsx-runtime").JSX.Element;
displayName: string;
};
export default Loadable;

View File

@ -0,0 +1,73 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _dynamicbailouttocsr = require("./dynamic-bailout-to-csr");
const _preloadcss = require("./preload-css");
// Normalize loader to return the module as form { default: Component } for `React.lazy`.
// Also for backward compatible since next/dynamic allows to resolve a component directly with loader
// Client component reference proxy need to be converted to a module.
function convertModule(mod) {
// Check "default" prop before accessing it, as it could be client reference proxy that could break it reference.
// Cases:
// mod: { default: Component }
// mod: Component
// mod: { $$typeof, default: proxy(Component) }
// mod: proxy(Component)
const hasDefault = mod && "default" in mod;
return {
default: hasDefault ? mod.default : mod
};
}
const defaultOptions = {
loader: ()=>Promise.resolve(convertModule(()=>null)),
loading: null,
ssr: true
};
function Loadable(options) {
const opts = {
...defaultOptions,
...options
};
const Lazy = /*#__PURE__*/ (0, _react.lazy)(()=>opts.loader().then(convertModule));
const Loading = opts.loading;
function LoadableComponent(props) {
const fallbackElement = Loading ? /*#__PURE__*/ (0, _jsxruntime.jsx)(Loading, {
isLoading: true,
pastDelay: true,
error: null
}) : null;
const children = opts.ssr ? /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
children: [
typeof window === "undefined" ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_preloadcss.PreloadCss, {
moduleIds: opts.modules
}) : null,
/*#__PURE__*/ (0, _jsxruntime.jsx)(Lazy, {
...props
})
]
}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_dynamicbailouttocsr.BailoutToCSR, {
reason: "next/dynamic",
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(Lazy, {
...props
})
});
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_react.Suspense, {
fallback: fallbackElement,
children: children
});
}
LoadableComponent.displayName = "LoadableComponent";
return LoadableComponent;
}
const _default = Loadable;
//# sourceMappingURL=loadable.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/lazy-dynamic/loadable.tsx"],"names":["convertModule","mod","hasDefault","default","defaultOptions","loader","Promise","resolve","loading","ssr","Loadable","options","opts","Lazy","lazy","then","Loading","LoadableComponent","props","fallbackElement","isLoading","pastDelay","error","children","window","PreloadCss","moduleIds","modules","BailoutToCSR","reason","Suspense","fallback","displayName"],"mappings":";;;;+BAwEA;;;eAAA;;;;uBAxE+B;qCACF;4BAEF;AAE3B,yFAAyF;AACzF,qGAAqG;AACrG,qEAAqE;AACrE,SAASA,cACPC,GAA4D;IAI5D,iHAAiH;IACjH,SAAS;IACT,8BAA8B;IAC9B,iBAAiB;IACjB,+CAA+C;IAC/C,wBAAwB;IACxB,MAAMC,aAAaD,OAAO,aAAaA;IACvC,OAAO;QACLE,SAASD,aACL,AAACD,IAA2BE,OAAO,GAClCF;IACP;AACF;AAEA,MAAMG,iBAAiB;IACrBC,QAAQ,IAAMC,QAAQC,OAAO,CAACP,cAAc,IAAM;IAClDQ,SAAS;IACTC,KAAK;AACP;AASA,SAASC,SAASC,OAAwB;IACxC,MAAMC,OAAO;QAAE,GAAGR,cAAc;QAAE,GAAGO,OAAO;IAAC;IAC7C,MAAME,qBAAOC,IAAAA,WAAI,EAAC,IAAMF,KAAKP,MAAM,GAAGU,IAAI,CAACf;IAC3C,MAAMgB,UAAUJ,KAAKJ,OAAO;IAE5B,SAASS,kBAAkBC,KAAU;QACnC,MAAMC,kBAAkBH,wBACtB,qBAACA;YAAQI,WAAW;YAAMC,WAAW;YAAMC,OAAO;aAChD;QAEJ,MAAMC,WAAWX,KAAKH,GAAG,iBACvB;;gBAEG,OAAOe,WAAW,4BACjB,qBAACC,sBAAU;oBAACC,WAAWd,KAAKe,OAAO;qBACjC;8BACJ,qBAACd;oBAAM,GAAGK,KAAK;;;2BAGjB,qBAACU,iCAAY;YAACC,QAAO;sBACnB,cAAA,qBAAChB;gBAAM,GAAGK,KAAK;;;QAInB,qBAAO,qBAACY,eAAQ;YAACC,UAAUZ;sBAAkBI;;IAC/C;IAEAN,kBAAkBe,WAAW,GAAG;IAEhC,OAAOf;AACT;MAEA,WAAeP"}

View File

@ -0,0 +1,3 @@
export declare function PreloadCss({ moduleIds }: {
moduleIds: string[] | undefined;
}): import("react/jsx-runtime").JSX.Element | null;

View File

@ -0,0 +1,49 @@
"use client";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "PreloadCss", {
enumerable: true,
get: function() {
return PreloadCss;
}
});
const _jsxruntime = require("react/jsx-runtime");
const _requestasyncstorageexternal = require("../../../client/components/request-async-storage.external");
function PreloadCss(param) {
let { moduleIds } = param;
// Early return in client compilation and only load requestStore on server side
if (typeof window !== "undefined") {
return null;
}
const requestStore = (0, _requestasyncstorageexternal.getExpectedRequestStore)("next/dynamic css");
const allFiles = [];
// Search the current dynamic call unique key id in react loadable manifest,
// and find the corresponding CSS files to preload
if (requestStore.reactLoadableManifest && moduleIds) {
const manifest = requestStore.reactLoadableManifest;
for (const key of moduleIds){
if (!manifest[key]) continue;
const cssFiles = manifest[key].files.filter((file)=>file.endsWith(".css"));
allFiles.push(...cssFiles);
}
}
if (allFiles.length === 0) {
return null;
}
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
children: allFiles.map((file)=>{
return /*#__PURE__*/ (0, _jsxruntime.jsx)("link", {
// @ts-ignore
precedence: "dynamic",
rel: "stylesheet",
href: requestStore.assetPrefix + "/_next/" + encodeURI(file),
as: "style"
}, file);
})
});
}
//# sourceMappingURL=preload-css.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/lazy-dynamic/preload-css.tsx"],"names":["PreloadCss","moduleIds","window","requestStore","getExpectedRequestStore","allFiles","reactLoadableManifest","manifest","key","cssFiles","files","filter","file","endsWith","push","length","map","link","precedence","rel","href","assetPrefix","encodeURI","as"],"mappings":"AAAA;;;;;+BAIgBA;;;eAAAA;;;;6CAFwB;AAEjC,SAASA,WAAW,KAAkD;IAAlD,IAAA,EAAEC,SAAS,EAAuC,GAAlD;IACzB,+EAA+E;IAC/E,IAAI,OAAOC,WAAW,aAAa;QACjC,OAAO;IACT;IAEA,MAAMC,eAAeC,IAAAA,oDAAuB,EAAC;IAC7C,MAAMC,WAAW,EAAE;IAEnB,4EAA4E;IAC5E,kDAAkD;IAClD,IAAIF,aAAaG,qBAAqB,IAAIL,WAAW;QACnD,MAAMM,WAAWJ,aAAaG,qBAAqB;QACnD,KAAK,MAAME,OAAOP,UAAW;YAC3B,IAAI,CAACM,QAAQ,CAACC,IAAI,EAAE;YACpB,MAAMC,WAAWF,QAAQ,CAACC,IAAI,CAACE,KAAK,CAACC,MAAM,CAAC,CAACC,OAC3CA,KAAKC,QAAQ,CAAC;YAEhBR,SAASS,IAAI,IAAIL;QACnB;IACF;IAEA,IAAIJ,SAASU,MAAM,KAAK,GAAG;QACzB,OAAO;IACT;IAEA,qBACE;kBACGV,SAASW,GAAG,CAAC,CAACJ;YACb,qBACE,qBAACK;gBAEC,aAAa;gBACbC,YAAY;gBACZC,KAAI;gBACJC,MAAM,AAAGjB,aAAakB,WAAW,GAAC,YAASC,UAAUV;gBACrDW,IAAG;eALEX;QAQX;;AAGN"}

View File

@ -0,0 +1,17 @@
/// <reference types="react" />
export type ComponentModule<P = {}> = {
default: React.ComponentType<P>;
};
export declare type LoaderComponent<P = {}> = Promise<React.ComponentType<P> | ComponentModule<P>>;
export declare type Loader<P = {}> = () => LoaderComponent<P>;
export type LoadableGeneratedOptions = {
webpack?(): any;
modules?: string[];
};
export type DynamicOptionsLoadingProps = {
error?: Error | null;
isLoading?: boolean;
pastDelay?: boolean;
retry?: () => void;
timedOut?: boolean;
};

View File

@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=types.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":""}