@rpcbase/client 0.311.0 → 0.312.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +36 -0
- package/dist/initWithRoutes.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -126,6 +126,7 @@ const SsrErrorFallback = ({ state, renderErrorExtra }) => {
|
|
|
126
126
|
};
|
|
127
127
|
const ROUTER_DEBUG = env.RB_PUBLIC_ROUTER_DEBUG;
|
|
128
128
|
const isProduction = env.MODE === "production";
|
|
129
|
+
const LOADER_TIMEOUT_MS = 8e3;
|
|
129
130
|
const showErrorOverlay = (err) => {
|
|
130
131
|
const ErrorOverlay = customElements.get("vite-error-overlay");
|
|
131
132
|
if (!ErrorOverlay) {
|
|
@@ -146,6 +147,40 @@ const handleServerErrors = () => {
|
|
|
146
147
|
});
|
|
147
148
|
}
|
|
148
149
|
};
|
|
150
|
+
const wrapLoaderWithTimeout = (loader, routeId) => async (...args) => new Promise((resolve, reject) => {
|
|
151
|
+
const timer = setTimeout(() => {
|
|
152
|
+
console.error("[rpcbase timeout][client loader]", { routeId, ms: LOADER_TIMEOUT_MS, url: window.location.href });
|
|
153
|
+
reject(new Response("Loader timeout", { status: 504 }));
|
|
154
|
+
}, LOADER_TIMEOUT_MS);
|
|
155
|
+
Promise.resolve(loader(...args)).then((val) => {
|
|
156
|
+
clearTimeout(timer);
|
|
157
|
+
resolve(val);
|
|
158
|
+
}).catch((err) => {
|
|
159
|
+
clearTimeout(timer);
|
|
160
|
+
reject(err);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
const applyLoaderTimeouts = (routes) => {
|
|
164
|
+
routes.forEach((route) => {
|
|
165
|
+
if (route.loader) {
|
|
166
|
+
route.loader = wrapLoaderWithTimeout(route.loader, route.id);
|
|
167
|
+
}
|
|
168
|
+
if (route.lazy) {
|
|
169
|
+
const origLazy = route.lazy;
|
|
170
|
+
route.lazy = async (...lazyArgs) => {
|
|
171
|
+
const mod = await origLazy(...lazyArgs);
|
|
172
|
+
if (mod?.loader) {
|
|
173
|
+
const origLoader = mod.loader;
|
|
174
|
+
mod.loader = (...loaderArgs) => wrapLoaderWithTimeout(origLoader, route.id)(...loaderArgs);
|
|
175
|
+
}
|
|
176
|
+
return mod;
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (route.children) {
|
|
180
|
+
applyLoaderTimeouts(route.children);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
};
|
|
149
184
|
const getRootElement = () => {
|
|
150
185
|
const el = document.getElementById("root");
|
|
151
186
|
if (!el) {
|
|
@@ -176,6 +211,7 @@ const initWithRoutes = async (routesElement, opts) => {
|
|
|
176
211
|
cleanupURL();
|
|
177
212
|
handleServerErrors();
|
|
178
213
|
const routes = createRoutesFromElements(routesElement);
|
|
214
|
+
applyLoaderTimeouts(routes);
|
|
179
215
|
const router = createBrowserRouter(routes, {
|
|
180
216
|
basename: "/",
|
|
181
217
|
...enableRouterInstrumentation ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initWithRoutes.d.ts","sourceRoot":"","sources":["../src/initWithRoutes.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAc,MAAM,OAAO,CAAA;AAE7C,OAAO,EAAsB,wBAAwB,EAAiB,MAAM,iBAAiB,CAAA;AAK7F,OAAO,EAGL,oBAAoB,EACrB,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"initWithRoutes.d.ts","sourceRoot":"","sources":["../src/initWithRoutes.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAc,MAAM,OAAO,CAAA;AAE7C,OAAO,EAAsB,wBAAwB,EAAiB,MAAM,iBAAiB,CAAA;AAK7F,OAAO,EAGL,oBAAoB,EACrB,MAAM,iBAAiB,CAAA;AAiFxB,KAAK,qBAAqB,GAAG;IAC3B,0BAA0B,CAAC,EAAE,OAAO,CAAA;IACpC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,SAAS,CAAA;CAC9D,CAAA;AAED,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAA;AA8BnE,eAAO,MAAM,cAAc,GACzB,eAAe,aAAa,EAC5B,OAAO,qBAAqB,kBA+I7B,CAAA"}
|