@rpcbase/client 0.310.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 +39 -1
- package/dist/initWithRoutes.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -124,7 +124,9 @@ const SsrErrorFallback = ({ state, renderErrorExtra }) => {
|
|
|
124
124
|
extra ? /* @__PURE__ */ jsx("div", { className: "mt-10 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-center", children: extra }) : null
|
|
125
125
|
] }) });
|
|
126
126
|
};
|
|
127
|
+
const ROUTER_DEBUG = env.RB_PUBLIC_ROUTER_DEBUG;
|
|
127
128
|
const isProduction = env.MODE === "production";
|
|
129
|
+
const LOADER_TIMEOUT_MS = 8e3;
|
|
128
130
|
const showErrorOverlay = (err) => {
|
|
129
131
|
const ErrorOverlay = customElements.get("vite-error-overlay");
|
|
130
132
|
if (!ErrorOverlay) {
|
|
@@ -145,6 +147,40 @@ const handleServerErrors = () => {
|
|
|
145
147
|
});
|
|
146
148
|
}
|
|
147
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
|
+
};
|
|
148
184
|
const getRootElement = () => {
|
|
149
185
|
const el = document.getElementById("root");
|
|
150
186
|
if (!el) {
|
|
@@ -165,7 +201,8 @@ const hydrateSsrFallbackIfPresent = (rootElement, renderErrorExtra) => {
|
|
|
165
201
|
return true;
|
|
166
202
|
};
|
|
167
203
|
const initWithRoutes = async (routesElement, opts) => {
|
|
168
|
-
const enableRouterInstrumentation =
|
|
204
|
+
const enableRouterInstrumentation = ROUTER_DEBUG === "1" || ROUTER_DEBUG === "true" || ROUTER_DEBUG === true;
|
|
205
|
+
console.log("Router instrumentation enabled:", enableRouterInstrumentation);
|
|
169
206
|
const rootElement = getRootElement();
|
|
170
207
|
if (hydrateSsrFallbackIfPresent(rootElement, opts?.renderErrorExtra)) {
|
|
171
208
|
return;
|
|
@@ -174,6 +211,7 @@ const initWithRoutes = async (routesElement, opts) => {
|
|
|
174
211
|
cleanupURL();
|
|
175
212
|
handleServerErrors();
|
|
176
213
|
const routes = createRoutesFromElements(routesElement);
|
|
214
|
+
applyLoaderTimeouts(routes);
|
|
177
215
|
const router = createBrowserRouter(routes, {
|
|
178
216
|
basename: "/",
|
|
179
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"}
|