97 lines
3.0 KiB
Plaintext
97 lines
3.0 KiB
Plaintext
"use strict";
|
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
const jsxRuntime = require("react/jsx-runtime");
|
|
const React = require("react");
|
|
const Match = require("./Match.cjs");
|
|
function _interopNamespaceDefault(e) {
|
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
if (e) {
|
|
for (const k in e) {
|
|
if (k !== "default") {
|
|
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
Object.defineProperty(n, k, d.get ? d : {
|
|
enumerable: true,
|
|
get: () => e[k]
|
|
});
|
|
}
|
|
}
|
|
}
|
|
n.default = e;
|
|
return Object.freeze(n);
|
|
}
|
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
function isModuleNotFoundError(error) {
|
|
if (typeof (error == null ? void 0 : error.message) !== "string") return false;
|
|
return error.message.startsWith("Failed to fetch dynamically imported module") || error.message.startsWith("error loading dynamically imported module") || error.message.startsWith("Importing a module script failed");
|
|
}
|
|
function ClientOnly({
|
|
children,
|
|
fallback = null
|
|
}) {
|
|
return useHydrated() ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback });
|
|
}
|
|
function subscribe() {
|
|
return () => {
|
|
};
|
|
}
|
|
function useHydrated() {
|
|
return React__namespace.useSyncExternalStore(
|
|
subscribe,
|
|
() => true,
|
|
() => false
|
|
);
|
|
}
|
|
function lazyRouteComponent(importer, exportName, ssr) {
|
|
let loadPromise;
|
|
let comp;
|
|
let error;
|
|
let reload;
|
|
const load = () => {
|
|
if (typeof document === "undefined" && (ssr == null ? void 0 : ssr()) === false) {
|
|
comp = () => null;
|
|
return Promise.resolve();
|
|
}
|
|
if (!loadPromise) {
|
|
loadPromise = importer().then((res) => {
|
|
loadPromise = void 0;
|
|
comp = res[exportName ?? "default"];
|
|
}).catch((err) => {
|
|
error = err;
|
|
if (isModuleNotFoundError(error)) {
|
|
if (error instanceof Error && typeof window !== "undefined" && typeof sessionStorage !== "undefined") {
|
|
const storageKey = `tanstack_router_reload:${error.message}`;
|
|
if (!sessionStorage.getItem(storageKey)) {
|
|
sessionStorage.setItem(storageKey, "1");
|
|
reload = true;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
return loadPromise;
|
|
};
|
|
const lazyComp = function Lazy(props) {
|
|
if (reload) {
|
|
window.location.reload();
|
|
throw new Promise(() => {
|
|
});
|
|
}
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
if (!comp) {
|
|
throw load();
|
|
}
|
|
if ((ssr == null ? void 0 : ssr()) === false) {
|
|
return /* @__PURE__ */ jsxRuntime.jsx(ClientOnly, { fallback: /* @__PURE__ */ jsxRuntime.jsx(Match.Outlet, {}), children: React__namespace.createElement(comp, props) });
|
|
}
|
|
return React__namespace.createElement(comp, props);
|
|
};
|
|
lazyComp.preload = load;
|
|
return lazyComp;
|
|
}
|
|
exports.ClientOnly = ClientOnly;
|
|
exports.lazyRouteComponent = lazyRouteComponent;
|
|
exports.useHydrated = useHydrated;
|
|
//# sourceMappingURL=lazyRouteComponent.cjs.map
|