@rpcbase/client 0.311.0 → 0.313.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.
@@ -1 +1 @@
1
- {"version":3,"file":"getFeatureFlag.d.ts","sourceRoot":"","sources":["../src/getFeatureFlag.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,GACzB,MAAM,MAAM,KACX,OAAO,CAAC,OAAO,GAAG,MAAM,GAAG,SAAS,CAuDtC,CAAA"}
1
+ {"version":3,"file":"getFeatureFlag.d.ts","sourceRoot":"","sources":["../src/getFeatureFlag.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,GACzB,MAAM,MAAM,KACX,OAAO,CAAC,OAAO,GAAG,MAAM,GAAG,SAAS,CA8DtC,CAAA"}
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 ? {
@@ -821,12 +857,16 @@ const getFeatureFlag = async (flag) => {
821
857
  return value;
822
858
  } else {
823
859
  let waitForFeatureFlags = function() {
824
- return new Promise((resolve) => {
860
+ return new Promise((resolve, reject) => {
825
861
  if (hasLoadedFeatureFlags) {
826
862
  resolve();
827
863
  } else {
864
+ const timeout = setTimeout(() => {
865
+ reject(new Error(`PostHog feature flags did not load within ${TIMEOUT_MS}ms`));
866
+ }, TIMEOUT_MS);
828
867
  posthog2.onFeatureFlags(() => {
829
868
  hasLoadedFeatureFlags = true;
869
+ clearTimeout(timeout);
830
870
  resolve();
831
871
  });
832
872
  }
@@ -838,6 +878,7 @@ const getFeatureFlag = async (flag) => {
838
878
  const startTime = performance.now();
839
879
  const { posthog: posthog2 } = await import("posthog-js");
840
880
  let hasLoadedFeatureFlags = false;
881
+ const TIMEOUT_MS = 8e3;
841
882
  await waitForFeatureFlags();
842
883
  const endTime = performance.now();
843
884
  console.log(`Client: Feature flag "${flag}" loaded in ${(endTime - startTime).toFixed(2)}ms`);
@@ -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;AAmCxB,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,kBA8I7B,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.311.0",
3
+ "version": "0.313.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"