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,17 @@
// This has to be a shared module which is shared between client component error boundary and dynamic component
const BAILOUT_TO_CSR = "BAILOUT_TO_CLIENT_SIDE_RENDERING";
/** An error that should be thrown when we want to bail out to client-side rendering. */ export class BailoutToCSRError extends Error {
constructor(reason){
super("Bail out to client-side rendering: " + reason);
this.reason = reason;
this.digest = BAILOUT_TO_CSR;
}
}
/** Checks if a passed argument is an error that is thrown if we want to bail out to client-side rendering. */ export 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":["BAILOUT_TO_CSR","BailoutToCSRError","Error","constructor","reason","digest","isBailoutToCSRError","err"],"mappings":"AAAA,+GAA+G;AAC/G,MAAMA,iBAAiB;AAEvB,sFAAsF,GACtF,OAAO,MAAMC,0BAA0BC;IAGrCC,YAAY,AAAgBC,MAAc,CAAE;QAC1C,KAAK,CAAC,AAAC,wCAAqCA;aADlBA,SAAAA;aAFZC,SAASL;IAIzB;AACF;AAEA,4GAA4G,GAC5G,OAAO,SAASM,oBAAoBC,GAAY;IAC9C,IAAI,OAAOA,QAAQ,YAAYA,QAAQ,QAAQ,CAAE,CAAA,YAAYA,GAAE,GAAI;QACjE,OAAO;IACT;IAEA,OAAOA,IAAIF,MAAM,KAAKL;AACxB"}

View File

@ -0,0 +1,15 @@
"use client";
import { BailoutToCSRError } from "./bailout-to-csr";
/**
* 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 function BailoutToCSR(param) {
let { reason, children } = param;
if (typeof window === "undefined") {
throw new 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":["BailoutToCSRError","BailoutToCSR","reason","children","window"],"mappings":"AAAA;AAGA,SAASA,iBAAiB,QAAQ,mBAAkB;AAOpD;;;CAGC,GACD,OAAO,SAASC,aAAa,KAAuC;IAAvC,IAAA,EAAEC,MAAM,EAAEC,QAAQ,EAAqB,GAAvC;IAC3B,IAAI,OAAOC,WAAW,aAAa;QACjC,MAAM,IAAIJ,kBAAkBE;IAC9B;IAEA,OAAOC;AACT"}

View File

@ -0,0 +1,63 @@
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Suspense, lazy } from "react";
import { BailoutToCSR } from "./dynamic-bailout-to-csr";
import { PreloadCss } from "./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__*/ lazy(()=>opts.loader().then(convertModule));
const Loading = opts.loading;
function LoadableComponent(props) {
const fallbackElement = Loading ? /*#__PURE__*/ _jsx(Loading, {
isLoading: true,
pastDelay: true,
error: null
}) : null;
const children = opts.ssr ? /*#__PURE__*/ _jsxs(_Fragment, {
children: [
typeof window === "undefined" ? /*#__PURE__*/ _jsx(PreloadCss, {
moduleIds: opts.modules
}) : null,
/*#__PURE__*/ _jsx(Lazy, {
...props
})
]
}) : /*#__PURE__*/ _jsx(BailoutToCSR, {
reason: "next/dynamic",
children: /*#__PURE__*/ _jsx(Lazy, {
...props
})
});
return /*#__PURE__*/ _jsx(Suspense, {
fallback: fallbackElement,
children: children
});
}
LoadableComponent.displayName = "LoadableComponent";
return LoadableComponent;
}
export default Loadable;
//# sourceMappingURL=loadable.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/lazy-dynamic/loadable.tsx"],"names":["Suspense","lazy","BailoutToCSR","PreloadCss","convertModule","mod","hasDefault","default","defaultOptions","loader","Promise","resolve","loading","ssr","Loadable","options","opts","Lazy","then","Loading","LoadableComponent","props","fallbackElement","isLoading","pastDelay","error","children","window","moduleIds","modules","reason","fallback","displayName"],"mappings":";AAAA,SAASA,QAAQ,EAAEC,IAAI,QAAQ,QAAO;AACtC,SAASC,YAAY,QAAQ,2BAA0B;AAEvD,SAASC,UAAU,QAAQ,gBAAe;AAE1C,yFAAyF;AACzF,qGAAqG;AACrG,qEAAqE;AACrE,SAASC,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,qBAAOhB,KAAK,IAAMe,KAAKP,MAAM,GAAGS,IAAI,CAACd;IAC3C,MAAMe,UAAUH,KAAKJ,OAAO;IAE5B,SAASQ,kBAAkBC,KAAU;QACnC,MAAMC,kBAAkBH,wBACtB,KAACA;YAAQI,WAAW;YAAMC,WAAW;YAAMC,OAAO;aAChD;QAEJ,MAAMC,WAAWV,KAAKH,GAAG,iBACvB;;gBAEG,OAAOc,WAAW,4BACjB,KAACxB;oBAAWyB,WAAWZ,KAAKa,OAAO;qBACjC;8BACJ,KAACZ;oBAAM,GAAGI,KAAK;;;2BAGjB,KAACnB;YAAa4B,QAAO;sBACnB,cAAA,KAACb;gBAAM,GAAGI,KAAK;;;QAInB,qBAAO,KAACrB;YAAS+B,UAAUT;sBAAkBI;;IAC/C;IAEAN,kBAAkBY,WAAW,GAAG;IAEhC,OAAOZ;AACT;AAEA,eAAeN,SAAQ"}

View File

@ -0,0 +1,39 @@
"use client";
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { getExpectedRequestStore } from "../../../client/components/request-async-storage.external";
export 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 = 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__*/ _jsx(_Fragment, {
children: allFiles.map((file)=>{
return /*#__PURE__*/ _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":["getExpectedRequestStore","PreloadCss","moduleIds","window","requestStore","allFiles","reactLoadableManifest","manifest","key","cssFiles","files","filter","file","endsWith","push","length","map","link","precedence","rel","href","assetPrefix","encodeURI","as"],"mappings":"AAAA;;AAEA,SAASA,uBAAuB,QAAQ,4DAA2D;AAEnG,OAAO,SAASC,WAAW,KAAkD;IAAlD,IAAA,EAAEC,SAAS,EAAuC,GAAlD;IACzB,+EAA+E;IAC/E,IAAI,OAAOC,WAAW,aAAa;QACjC,OAAO;IACT;IAEA,MAAMC,eAAeJ,wBAAwB;IAC7C,MAAMK,WAAW,EAAE;IAEnB,4EAA4E;IAC5E,kDAAkD;IAClD,IAAID,aAAaE,qBAAqB,IAAIJ,WAAW;QACnD,MAAMK,WAAWH,aAAaE,qBAAqB;QACnD,KAAK,MAAME,OAAON,UAAW;YAC3B,IAAI,CAACK,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,KAACK;gBAEC,aAAa;gBACbC,YAAY;gBACZC,KAAI;gBACJC,MAAM,AAAGhB,aAAaiB,WAAW,GAAC,YAASC,UAAUV;gBACrDW,IAAG;eALEX;QAQX;;AAGN"}

View File

@ -0,0 +1,3 @@
export { };
//# sourceMappingURL=types.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/shared/lib/lazy-dynamic/types.ts"],"names":[],"mappings":"AAaA,WAMC"}