@cedarjs/web 8.0.0-canary.3327 → 8.0.0-canary.3330

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 CHANGED
@@ -19,6 +19,8 @@ import { Helmet } from "@dr.pogodin/react-helmet";
19
19
  export * from "./components/htmlTags.js";
20
20
  export * from "./routeHooks.types.js";
21
21
  export * from "./components/ServerInject.js";
22
+ import { registerPreloadErrorReload } from "./reloadOnPreloadError.js";
23
+ registerPreloadErrorReload();
22
24
  export {
23
25
  FatalErrorBoundary,
24
26
  FetchConfigProvider,
@@ -0,0 +1,37 @@
1
+ /**
2
+ * `sessionStorage` key that marks the next page load as one triggered by the
3
+ * `vite:preloadError` handler
4
+ */
5
+ export declare const PRELOAD_ERROR_RELOAD_KEY = "cedar:preload-error-reload";
6
+ /**
7
+ * On a page that the handler itself reloaded, a preload error within this many
8
+ * milliseconds of the page starting to load is left for the app to handle. A
9
+ * chunk that is missing even on the latest deploy then surfaces as an error
10
+ * instead of causing a reload loop, no matter how long each attempt takes to
11
+ * fail. After this long, the page is treated like any other, so a later deploy
12
+ * can reload it again.
13
+ */
14
+ export declare const RELOADED_PAGE_GRACE_MS = 60000;
15
+ /**
16
+ * Handles Vite's `vite:preloadError` event, which fires when a dynamically
17
+ * imported chunk fails to load. After a new deploy, a tab running the
18
+ * previous build requests hashed chunks that no longer exist on the server.
19
+ * Reloading the page fetches the latest build so the navigation can succeed.
20
+ *
21
+ * The handler does nothing if the event was already handled
22
+ * (`defaultPrevented`), if this page is the result of the handler's own
23
+ * reload and started loading less than `RELOADED_PAGE_GRACE_MS` ago, or if
24
+ * `sessionStorage` is unavailable (without it, a reload loop can't be ruled
25
+ * out). In those cases Vite rethrows the error and it surfaces through the
26
+ * app's normal error handling.
27
+ *
28
+ * See https://vite.dev/guide/build#load-error-handling
29
+ */
30
+ export declare function handlePreloadError(event: Event): void;
31
+ /**
32
+ * Registers `handlePreloadError` as a `vite:preloadError` listener on
33
+ * `window`. Runs at most once per page load, and does nothing outside the
34
+ * browser.
35
+ */
36
+ export declare function registerPreloadErrorReload(): void;
37
+ //# sourceMappingURL=reloadOnPreloadError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reloadOnPreloadError.d.ts","sourceRoot":"","sources":["../src/reloadOnPreloadError.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,wBAAwB,+BAA+B,CAAA;AAEpE;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,QAAS,CAAA;AA2B5C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,QAkB9C;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,SAYzC"}
@@ -0,0 +1,49 @@
1
+ const PRELOAD_ERROR_RELOAD_KEY = "cedar:preload-error-reload";
2
+ const RELOADED_PAGE_GRACE_MS = 6e4;
3
+ let pageWasReloadedForPreloadError = false;
4
+ function consumeReloadMarker() {
5
+ try {
6
+ pageWasReloadedForPreloadError = window.sessionStorage.getItem(PRELOAD_ERROR_RELOAD_KEY) !== null;
7
+ window.sessionStorage.removeItem(PRELOAD_ERROR_RELOAD_KEY);
8
+ } catch {
9
+ pageWasReloadedForPreloadError = false;
10
+ }
11
+ }
12
+ function setReloadMarker() {
13
+ try {
14
+ window.sessionStorage.setItem(PRELOAD_ERROR_RELOAD_KEY, "1");
15
+ return true;
16
+ } catch {
17
+ return false;
18
+ }
19
+ }
20
+ function handlePreloadError(event) {
21
+ if (event.defaultPrevented) {
22
+ return;
23
+ }
24
+ if (pageWasReloadedForPreloadError && performance.now() < RELOADED_PAGE_GRACE_MS) {
25
+ return;
26
+ }
27
+ if (!setReloadMarker()) {
28
+ return;
29
+ }
30
+ event.preventDefault();
31
+ window.location.reload();
32
+ }
33
+ function registerPreloadErrorReload() {
34
+ if (typeof window === "undefined") {
35
+ return;
36
+ }
37
+ if (globalThis.__CEDAR__PRELOAD_ERROR_RELOAD_REGISTERED) {
38
+ return;
39
+ }
40
+ globalThis.__CEDAR__PRELOAD_ERROR_RELOAD_REGISTERED = true;
41
+ consumeReloadMarker();
42
+ window.addEventListener("vite:preloadError", handlePreloadError);
43
+ }
44
+ export {
45
+ PRELOAD_ERROR_RELOAD_KEY,
46
+ RELOADED_PAGE_GRACE_MS,
47
+ handlePreloadError,
48
+ registerPreloadErrorReload
49
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/web",
3
- "version": "8.0.0-canary.3327",
3
+ "version": "8.0.0-canary.3330",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -79,7 +79,7 @@
79
79
  },
80
80
  "dependencies": {
81
81
  "@apollo/client": "4.3.1",
82
- "@cedarjs/server-store": "8.0.0-canary.3327",
82
+ "@cedarjs/server-store": "8.0.0-canary.3330",
83
83
  "@dr.pogodin/react-helmet": "2.0.4",
84
84
  "@whatwg-node/fetch": "0.12.1",
85
85
  "apollo-upload-client": "19.0.0",
@@ -95,9 +95,9 @@
95
95
  "devDependencies": {
96
96
  "@apollo/client-react-streaming": "0.14.5",
97
97
  "@arethetypeswrong/cli": "0.18.5",
98
- "@cedarjs/auth": "8.0.0-canary.3327",
99
- "@cedarjs/framework-tools": "8.0.0-canary.3327",
100
- "@cedarjs/internal": "8.0.0-canary.3327",
98
+ "@cedarjs/auth": "8.0.0-canary.3330",
99
+ "@cedarjs/framework-tools": "8.0.0-canary.3330",
100
+ "@cedarjs/internal": "8.0.0-canary.3330",
101
101
  "@testing-library/dom": "10.4.2",
102
102
  "@testing-library/jest-dom": "6.9.1",
103
103
  "@testing-library/react": "16.3.3",
@@ -114,7 +114,7 @@
114
114
  "vitest": "4.1.11"
115
115
  },
116
116
  "peerDependencies": {
117
- "@cedarjs/auth": "8.0.0-canary.3327",
117
+ "@cedarjs/auth": "8.0.0-canary.3330",
118
118
  "react": "19.3.0",
119
119
  "react-dom": "19.3.0"
120
120
  },