@base44-preview/vite-plugin 1.0.32-pr.114.574de6d → 1.0.32-pr.115.93671d4
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/html-injections-plugin.d.ts.map +1 -1
- package/dist/html-injections-plugin.js +0 -8
- package/dist/html-injections-plugin.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -8
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +12 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/html-injections-plugin.ts +0 -8
- package/src/index.ts +21 -8
- package/src/utils.ts +13 -1
- package/dist/injections/stale-deps-reloader.d.ts +0 -23
- package/dist/injections/stale-deps-reloader.d.ts.map +0 -1
- package/dist/injections/stale-deps-reloader.js +0 -161
- package/dist/injections/stale-deps-reloader.js.map +0 -1
- package/src/injections/stale-deps-reloader.ts +0 -179
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-injections-plugin.d.ts","sourceRoot":"","sources":["../src/html-injections-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAqB,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"html-injections-plugin.d.ts","sourceRoot":"","sources":["../src/html-injections-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAqB,MAAM,MAAM,CAAC;AAyEtD,wBAAgB,oBAAoB,CAAC,EACnC,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,gBAAgB,GACjB,EAAE;IACD,WAAW,EAAE,OAAO,CAAC;IACrB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;CAC3B,GAmFM,MAAM,CACZ"}
|
|
@@ -42,11 +42,6 @@ const INJECTIONS = {
|
|
|
42
42
|
injectTo: "body",
|
|
43
43
|
mode: "dev",
|
|
44
44
|
},
|
|
45
|
-
staleDepsReloader: {
|
|
46
|
-
src: "/node_modules/@base44/vite-plugin/dist/injections/stale-deps-reloader.js",
|
|
47
|
-
injectTo: "head",
|
|
48
|
-
mode: "dev",
|
|
49
|
-
},
|
|
50
45
|
hmrNotifier: {
|
|
51
46
|
src: "/node_modules/@base44/vite-plugin/dist/injections/sandbox-hmr-notifier.js",
|
|
52
47
|
injectTo: "head",
|
|
@@ -67,9 +62,6 @@ export function htmlInjectionsPlugin({ hmrNotifier, navigationNotifier, visualEd
|
|
|
67
62
|
const enabledInjections = {
|
|
68
63
|
unhandledErrors: true,
|
|
69
64
|
sandboxMount: true,
|
|
70
|
-
// Deliberately not an opt-in option: existing apps must pick this up from a
|
|
71
|
-
// plugin version bump alone, without editing their vite.config.js.
|
|
72
|
-
staleDepsReloader: true,
|
|
73
65
|
hmrNotifier,
|
|
74
66
|
navigationNotifier,
|
|
75
67
|
analyticsTracker,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-injections-plugin.js","sourceRoot":"","sources":["../src/html-injections-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAW/B,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BhC,CAAC;AAEF,MAAM,UAAU,GAA8B;IAC5C,eAAe,EAAE;QACf,GAAG,EAAE,gFAAgF;QACrF,QAAQ,EAAE,MAAM;QAChB,IAAI,EAAE,KAAK;KACZ;IACD,YAAY,EAAE;QACZ,GAAG,EAAE,6EAA6E;QAClF,QAAQ,EAAE,MAAM;QAChB,IAAI,EAAE,KAAK;KACZ;IACD,
|
|
1
|
+
{"version":3,"file":"html-injections-plugin.js","sourceRoot":"","sources":["../src/html-injections-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAW/B,MAAM,wB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nC,4EAA4E;4BAC5E,gCAAgC;4BAChC,0CAA0C;4BAC1C,UAAU,IAAI,sBAAsB;4BACpC,eAAe;4BACf,oBAAoB;4BACpB,uFAAuF;4BACvF,QAAQ;4BACR,2EAA2E;4BAC3E,GAAG;yBACJ,CAAC,IAAI,CAAC,IAAI,CAAC;wBACZ,QAAQ,EAAE,MAAM;qBACjB,CAAC,CAAC;gBACL,CAAC;gBAED,OAAO,IAAI,CAAC;YACd,CAAC;SACF;KACQ,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAiB/C,eAAO,MAAM,uBAAuB,UAWnC,CAAC;AAeF,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,IAAI,GAAE;IACJ,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACvB,iBA4OP"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,25 @@ import { filterPackagesInProject } from "./utils.js";
|
|
|
6
6
|
import { htmlInjectionsPlugin } from "./html-injections-plugin.js";
|
|
7
7
|
import { buildStatusPlugin } from "./build-status-plugin.js";
|
|
8
8
|
const isRunningInSandbox = !!process.env.MODAL_SANDBOX_ID;
|
|
9
|
+
// Every entry Vite must pre-bundle before the browser loads the app. Deep
|
|
10
|
+
// entries are listed explicitly: to the optimizer `react/jsx-dev-runtime` and
|
|
11
|
+
// `react-dom/client` are separate entries, NOT covered by `react`/`react-dom`.
|
|
12
|
+
// Leaving one out means Vite discovers it mid-load, re-runs the optimizer and
|
|
13
|
+
// mints a new browserHash — so the same page ends up holding `react.js?v=A`
|
|
14
|
+
// and `react.js?v=B`, two React instances, and dies on its first hook with
|
|
15
|
+
// "Cannot read properties of null (reading 'useState')".
|
|
16
|
+
export const PREBUNDLED_SANDBOX_DEPS = [
|
|
17
|
+
"react",
|
|
18
|
+
"react/jsx-runtime",
|
|
19
|
+
"react/jsx-dev-runtime",
|
|
20
|
+
"react-dom",
|
|
21
|
+
"react-dom/client",
|
|
22
|
+
"react-router-dom",
|
|
23
|
+
"framer-motion",
|
|
24
|
+
"lodash",
|
|
25
|
+
"moment",
|
|
26
|
+
"react-quill",
|
|
27
|
+
];
|
|
9
28
|
const ENV_UNSET_GUIDANCE = [
|
|
10
29
|
"[base44] No Base44 backend configured — VITE_BASE44_APP_BASE_URL is not set, so /api requests have nowhere to go.",
|
|
11
30
|
"[base44] Run the app through the Base44 CLI instead:",
|
|
@@ -119,14 +138,7 @@ export default function vitePlugin(opts = {}) {
|
|
|
119
138
|
optimizeDeps: {
|
|
120
139
|
...(isRunningInSandbox
|
|
121
140
|
? {
|
|
122
|
-
include: filterPackagesInProject(
|
|
123
|
-
"react",
|
|
124
|
-
"react-dom",
|
|
125
|
-
"framer-motion",
|
|
126
|
-
"lodash",
|
|
127
|
-
"moment",
|
|
128
|
-
"react-quill",
|
|
129
|
-
], root),
|
|
141
|
+
include: filterPackagesInProject(PREBUNDLED_SANDBOX_DEPS, root),
|
|
130
142
|
}
|
|
131
143
|
: {}),
|
|
132
144
|
esbuildOptions: {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,O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AW,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC;QAC5F,yEAAyE;QACzE,iEAAiE;QACjE,sEAAsE;QACtE,wEAAwE;QACxE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,GAAG;YACjD,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;YACvB,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC"}
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAeA,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAAE,EAClB,IAAI,EAAE,MAAM,GACX,MAAM,EAAE,CAmBV"}
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { readFileSync, existsSync } from "fs";
|
|
2
2
|
import { join } from "path";
|
|
3
|
+
/**
|
|
4
|
+
* The package that owns an optimizeDeps entry. Deep entries like
|
|
5
|
+
* `react-dom/client` are separate entries to Vite's optimizer but are declared
|
|
6
|
+
* in package.json only under their owning package.
|
|
7
|
+
*/
|
|
8
|
+
function owningPackage(entry) {
|
|
9
|
+
const segments = entry.split("/");
|
|
10
|
+
return entry.startsWith("@")
|
|
11
|
+
? segments.slice(0, 2).join("/")
|
|
12
|
+
: segments[0] ?? entry;
|
|
13
|
+
}
|
|
3
14
|
export function filterPackagesInProject(packages, root) {
|
|
4
15
|
try {
|
|
5
16
|
const packageJsonPath = join(root, "package.json");
|
|
@@ -12,7 +23,7 @@ export function filterPackagesInProject(packages, root) {
|
|
|
12
23
|
...packageJson.devDependencies,
|
|
13
24
|
...packageJson.peerDependencies,
|
|
14
25
|
};
|
|
15
|
-
return packages.filter((pkg) => pkg in allDeps);
|
|
26
|
+
return packages.filter((pkg) => owningPackage(pkg) in allDeps);
|
|
16
27
|
}
|
|
17
28
|
catch (error) {
|
|
18
29
|
console.warn("Failed to read project package.json:", error);
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,MAAM,UAAU,uBAAuB,CACrC,QAAkB,EAClB,IAAY;IAEZ,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;YACjC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;QACvE,MAAM,OAAO,GAAG;YACd,GAAG,WAAW,CAAC,YAAY;YAC3B,GAAG,WAAW,CAAC,eAAe;YAC9B,GAAG,WAAW,CAAC,gBAAgB;SAChC,CAAC;QAEF,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B;;;;GAIG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;QAC1B,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAChC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,QAAkB,EAClB,IAAY;IAEZ,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;YACjC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;QACvE,MAAM,OAAO,GAAG;YACd,GAAG,WAAW,CAAC,YAAY;YAC3B,GAAG,WAAW,CAAC,eAAe;YAC9B,GAAG,WAAW,CAAC,gBAAgB;SAChC,CAAC;QAEF,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC5D,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -54,11 +54,6 @@ const INJECTIONS: Record<string, Injection> = {
|
|
|
54
54
|
injectTo: "body",
|
|
55
55
|
mode: "dev",
|
|
56
56
|
},
|
|
57
|
-
staleDepsReloader: {
|
|
58
|
-
src: "/node_modules/@base44/vite-plugin/dist/injections/stale-deps-reloader.js",
|
|
59
|
-
injectTo: "head",
|
|
60
|
-
mode: "dev",
|
|
61
|
-
},
|
|
62
57
|
hmrNotifier: {
|
|
63
58
|
src: "/node_modules/@base44/vite-plugin/dist/injections/sandbox-hmr-notifier.js",
|
|
64
59
|
injectTo: "head",
|
|
@@ -90,9 +85,6 @@ export function htmlInjectionsPlugin({
|
|
|
90
85
|
const enabledInjections: Record<string, boolean> = {
|
|
91
86
|
unhandledErrors: true,
|
|
92
87
|
sandboxMount: true,
|
|
93
|
-
// Deliberately not an opt-in option: existing apps must pick this up from a
|
|
94
|
-
// plugin version bump alone, without editing their vite.config.js.
|
|
95
|
-
staleDepsReloader: true,
|
|
96
88
|
hmrNotifier,
|
|
97
89
|
navigationNotifier,
|
|
98
90
|
analyticsTracker,
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,26 @@ import { buildStatusPlugin } from "./build-status-plugin.js";
|
|
|
9
9
|
|
|
10
10
|
const isRunningInSandbox = !!process.env.MODAL_SANDBOX_ID;
|
|
11
11
|
|
|
12
|
+
// Every entry Vite must pre-bundle before the browser loads the app. Deep
|
|
13
|
+
// entries are listed explicitly: to the optimizer `react/jsx-dev-runtime` and
|
|
14
|
+
// `react-dom/client` are separate entries, NOT covered by `react`/`react-dom`.
|
|
15
|
+
// Leaving one out means Vite discovers it mid-load, re-runs the optimizer and
|
|
16
|
+
// mints a new browserHash — so the same page ends up holding `react.js?v=A`
|
|
17
|
+
// and `react.js?v=B`, two React instances, and dies on its first hook with
|
|
18
|
+
// "Cannot read properties of null (reading 'useState')".
|
|
19
|
+
export const PREBUNDLED_SANDBOX_DEPS = [
|
|
20
|
+
"react",
|
|
21
|
+
"react/jsx-runtime",
|
|
22
|
+
"react/jsx-dev-runtime",
|
|
23
|
+
"react-dom",
|
|
24
|
+
"react-dom/client",
|
|
25
|
+
"react-router-dom",
|
|
26
|
+
"framer-motion",
|
|
27
|
+
"lodash",
|
|
28
|
+
"moment",
|
|
29
|
+
"react-quill",
|
|
30
|
+
];
|
|
31
|
+
|
|
12
32
|
const ENV_UNSET_GUIDANCE = [
|
|
13
33
|
"[base44] No Base44 backend configured — VITE_BASE44_APP_BASE_URL is not set, so /api requests have nowhere to go.",
|
|
14
34
|
"[base44] Run the app through the Base44 CLI instead:",
|
|
@@ -152,14 +172,7 @@ export default function vitePlugin(
|
|
|
152
172
|
...(isRunningInSandbox
|
|
153
173
|
? {
|
|
154
174
|
include: filterPackagesInProject(
|
|
155
|
-
|
|
156
|
-
"react",
|
|
157
|
-
"react-dom",
|
|
158
|
-
"framer-motion",
|
|
159
|
-
"lodash",
|
|
160
|
-
"moment",
|
|
161
|
-
"react-quill",
|
|
162
|
-
],
|
|
175
|
+
PREBUNDLED_SANDBOX_DEPS,
|
|
163
176
|
root
|
|
164
177
|
),
|
|
165
178
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { readFileSync, existsSync } from "fs";
|
|
2
2
|
import { join } from "path";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The package that owns an optimizeDeps entry. Deep entries like
|
|
6
|
+
* `react-dom/client` are separate entries to Vite's optimizer but are declared
|
|
7
|
+
* in package.json only under their owning package.
|
|
8
|
+
*/
|
|
9
|
+
function owningPackage(entry: string): string {
|
|
10
|
+
const segments = entry.split("/");
|
|
11
|
+
return entry.startsWith("@")
|
|
12
|
+
? segments.slice(0, 2).join("/")
|
|
13
|
+
: segments[0] ?? entry;
|
|
14
|
+
}
|
|
15
|
+
|
|
4
16
|
export function filterPackagesInProject(
|
|
5
17
|
packages: string[],
|
|
6
18
|
root: string
|
|
@@ -18,7 +30,7 @@ export function filterPackagesInProject(
|
|
|
18
30
|
...packageJson.peerDependencies,
|
|
19
31
|
};
|
|
20
32
|
|
|
21
|
-
return packages.filter((pkg) => pkg in allDeps);
|
|
33
|
+
return packages.filter((pkg) => owningPackage(pkg) in allDeps);
|
|
22
34
|
} catch (error) {
|
|
23
35
|
console.warn("Failed to read project package.json:", error);
|
|
24
36
|
return [];
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
type BudgetStorage = Pick<Storage, "getItem" | "setItem">;
|
|
2
|
-
export type StaleDepsTracker = {
|
|
3
|
-
observe: (url: string) => boolean;
|
|
4
|
-
};
|
|
5
|
-
export type StaleDepsReloaderOptions = {
|
|
6
|
-
reload?: () => void;
|
|
7
|
-
now?: () => number;
|
|
8
|
-
storage?: BudgetStorage | null;
|
|
9
|
-
graceMs?: number;
|
|
10
|
-
};
|
|
11
|
-
/** The `v` param of an optimized-dep URL, or null for anything else. */
|
|
12
|
-
export declare function extractDepHash(url: string): string | null;
|
|
13
|
-
/** Reports true once a dep URL carries a hash different from the first one seen. */
|
|
14
|
-
export declare function createStaleDepsTracker(): StaleDepsTracker;
|
|
15
|
-
/**
|
|
16
|
-
* Consume one reload from the per-window budget. Fails open when storage is
|
|
17
|
-
* unreadable — an unrecoverable white screen is worse than a reload loop we can
|
|
18
|
-
* at least see in the logs.
|
|
19
|
-
*/
|
|
20
|
-
export declare function takeReloadBudget(storage: BudgetStorage, now: number): boolean;
|
|
21
|
-
export declare function setupStaleDepsReloader(options?: StaleDepsReloaderOptions): () => void;
|
|
22
|
-
export {};
|
|
23
|
-
//# sourceMappingURL=stale-deps-reloader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stale-deps-reloader.d.ts","sourceRoot":"","sources":["../../src/injections/stale-deps-reloader.ts"],"names":[],"mappings":"AAoBA,KAAK,aAAa,GAAG,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;AAE1D,MAAM,MAAM,gBAAgB,GAAG;IAAE,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,CAAC;AAErE,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKzD;AAED,oFAAoF;AACpF,wBAAgB,sBAAsB,IAAI,gBAAgB,CAazD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAuB7E;AAkBD,wBAAgB,sBAAsB,CACpC,OAAO,GAAE,wBAA6B,GACrC,MAAM,IAAI,CAuEZ"}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
|
2
|
-
// Vite serves every optimized dependency under a single `?v=<browserHash>`. When the
|
|
3
|
-
// optimizer re-runs mid-session — a newly discovered import, or `vite --force` on a
|
|
4
|
-
// dev-server restart — that hash changes, and a page that already fetched chunks under
|
|
5
|
-
// the old one finishes loading with two copies of React. The second resolves to null
|
|
6
|
-
// and the app dies on its first hook: "Cannot read properties of null (reading
|
|
7
|
-
// 'useState')". Vite's own 504-based recovery only covers requests it can still
|
|
8
|
-
// identify as outdated, so it misses the swap that lands between two requests of the
|
|
9
|
-
// same page load. Reloading on the second distinct hash turns a dead preview into a
|
|
10
|
-
// flicker.
|
|
11
|
-
const DEPS_MARKER = "/.vite/deps/";
|
|
12
|
-
const RELOAD_GRACE_MS = 200;
|
|
13
|
-
const RELOAD_BUDGET = 2;
|
|
14
|
-
const RELOAD_WINDOW_MS = 15_000;
|
|
15
|
-
const STORAGE_KEY = "__base44_stale_deps_reload";
|
|
16
|
-
/** The `v` param of an optimized-dep URL, or null for anything else. */
|
|
17
|
-
export function extractDepHash(url) {
|
|
18
|
-
if (!url.includes(DEPS_MARKER))
|
|
19
|
-
return null;
|
|
20
|
-
const query = url.indexOf("?");
|
|
21
|
-
if (query === -1)
|
|
22
|
-
return null;
|
|
23
|
-
return new URLSearchParams(url.slice(query + 1)).get("v");
|
|
24
|
-
}
|
|
25
|
-
/** Reports true once a dep URL carries a hash different from the first one seen. */
|
|
26
|
-
export function createStaleDepsTracker() {
|
|
27
|
-
let firstHash = null;
|
|
28
|
-
return {
|
|
29
|
-
observe(url) {
|
|
30
|
-
const hash = extractDepHash(url);
|
|
31
|
-
if (hash === null)
|
|
32
|
-
return false;
|
|
33
|
-
if (firstHash === null) {
|
|
34
|
-
firstHash = hash;
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
return hash !== firstHash;
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Consume one reload from the per-window budget. Fails open when storage is
|
|
43
|
-
* unreadable — an unrecoverable white screen is worse than a reload loop we can
|
|
44
|
-
* at least see in the logs.
|
|
45
|
-
*/
|
|
46
|
-
export function takeReloadBudget(storage, now) {
|
|
47
|
-
let prev = null;
|
|
48
|
-
try {
|
|
49
|
-
const raw = storage.getItem(STORAGE_KEY);
|
|
50
|
-
if (raw)
|
|
51
|
-
prev = JSON.parse(raw);
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
let n = 1;
|
|
57
|
-
let windowStart = now;
|
|
58
|
-
if (prev && typeof prev.n === "number" && now - prev.t < RELOAD_WINDOW_MS) {
|
|
59
|
-
n = prev.n + 1;
|
|
60
|
-
windowStart = prev.t;
|
|
61
|
-
}
|
|
62
|
-
if (n > RELOAD_BUDGET)
|
|
63
|
-
return false;
|
|
64
|
-
try {
|
|
65
|
-
storage.setItem(STORAGE_KEY, JSON.stringify({ n, t: windowStart }));
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
// Budget can't be persisted; the cap degrades but the reload still helps.
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
function defaultStorage() {
|
|
73
|
-
try {
|
|
74
|
-
return window.sessionStorage;
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function notifyParent(type) {
|
|
81
|
-
try {
|
|
82
|
-
window.parent?.postMessage({ type }, "*");
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
// Parent is cross-origin or gone; observability is best-effort.
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
export function setupStaleDepsReloader(options = {}) {
|
|
89
|
-
const reload = options.reload ?? (() => window.location.reload());
|
|
90
|
-
const now = options.now ?? (() => Date.now());
|
|
91
|
-
const graceMs = options.graceMs ?? RELOAD_GRACE_MS;
|
|
92
|
-
const storage = options.storage === undefined ? defaultStorage() : options.storage;
|
|
93
|
-
const Observer = globalThis.PerformanceObserver;
|
|
94
|
-
if (typeof Observer !== "function")
|
|
95
|
-
return () => { };
|
|
96
|
-
const tracker = createStaleDepsTracker();
|
|
97
|
-
let viteIsReloading = false;
|
|
98
|
-
let timer = null;
|
|
99
|
-
let done = false;
|
|
100
|
-
// Vite handles most swaps itself. Stand down rather than reload twice.
|
|
101
|
-
if (import.meta.hot) {
|
|
102
|
-
import.meta.hot.on("vite:beforeFullReload", () => {
|
|
103
|
-
viteIsReloading = true;
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
const scheduleReload = () => {
|
|
107
|
-
if (done || timer !== null)
|
|
108
|
-
return;
|
|
109
|
-
// The grace exists to let Vite's own full reload win the race. During the
|
|
110
|
-
// initial load its HMR client may not even be connected yet, and every
|
|
111
|
-
// millisecond of delay is a millisecond of broken preview — so don't wait.
|
|
112
|
-
const delay = document.readyState === "loading" ? 0 : graceMs;
|
|
113
|
-
timer = setTimeout(() => {
|
|
114
|
-
timer = null;
|
|
115
|
-
if (done || viteIsReloading)
|
|
116
|
-
return;
|
|
117
|
-
done = true;
|
|
118
|
-
observer.disconnect();
|
|
119
|
-
if (storage && !takeReloadBudget(storage, now())) {
|
|
120
|
-
notifyParent("sandbox:staleDepsReloadBudgetExhausted");
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
notifyParent("sandbox:staleDepsReload");
|
|
124
|
-
reload();
|
|
125
|
-
}, delay);
|
|
126
|
-
};
|
|
127
|
-
const observer = new Observer((list) => {
|
|
128
|
-
for (const entry of list.getEntries()) {
|
|
129
|
-
if (tracker.observe(entry.name))
|
|
130
|
-
scheduleReload();
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
try {
|
|
134
|
-
observer.observe({ type: "resource", buffered: true });
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
return () => { };
|
|
138
|
-
}
|
|
139
|
-
// `buffered` is not honored everywhere; sweep what already landed.
|
|
140
|
-
try {
|
|
141
|
-
for (const entry of performance.getEntriesByType("resource")) {
|
|
142
|
-
if (tracker.observe(entry.name))
|
|
143
|
-
scheduleReload();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
catch {
|
|
147
|
-
// No resource timing available; the observer above is the only source.
|
|
148
|
-
}
|
|
149
|
-
return () => {
|
|
150
|
-
done = true;
|
|
151
|
-
if (timer !== null) {
|
|
152
|
-
clearTimeout(timer);
|
|
153
|
-
timer = null;
|
|
154
|
-
}
|
|
155
|
-
observer.disconnect();
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
if (typeof window !== "undefined") {
|
|
159
|
-
setupStaleDepsReloader();
|
|
160
|
-
}
|
|
161
|
-
//# sourceMappingURL=stale-deps-reloader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stale-deps-reloader.js","sourceRoot":"","sources":["../../src/injections/stale-deps-reloader.ts"],"names":[],"mappings":"AAAA,qCAAqC;AAErC,qFAAqF;AACrF,oFAAoF;AACpF,uFAAuF;AACvF,qFAAqF;AACrF,+EAA+E;AAC/E,gFAAgF;AAChF,qFAAqF;AACrF,oFAAoF;AACpF,WAAW;AAEX,MAAM,WAAW,GAAG,cAAc,CAAC;AACnC,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,WAAW,GAAG,4BAA4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,CAAC;IACZ,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,CAAC,IAAkC,EAAE,EAAE;QACnE,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;YACtC,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;gBAAE,cAAc,EAAE,CAAC;QACpD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAS,EAAE,GAAE,CAAC,CAAC;IACxB,CAAC;IAED,mEAAmE;IACnE,IAAI,CAAC;QACH,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7D,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;gBAAE,cAAc,EAAE,CAAC;QACpD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,uEAAuE;IACzE,CAAC;IAED,OAAO,GAAS,EAAE;QAChB,IAAI,GAAG,IAAI,CAAC;QACZ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,KAAK,GAAG,IAAI,CAAC;QACf,CAAC;QACD,QAAQ,CAAC,UAAU,EAAE,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC;AAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,sBAAsB,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
|
2
|
-
|
|
3
|
-
// Vite serves every optimized dependency under a single `?v=<browserHash>`. When the
|
|
4
|
-
// optimizer re-runs mid-session — a newly discovered import, or `vite --force` on a
|
|
5
|
-
// dev-server restart — that hash changes, and a page that already fetched chunks under
|
|
6
|
-
// the old one finishes loading with two copies of React. The second resolves to null
|
|
7
|
-
// and the app dies on its first hook: "Cannot read properties of null (reading
|
|
8
|
-
// 'useState')". Vite's own 504-based recovery only covers requests it can still
|
|
9
|
-
// identify as outdated, so it misses the swap that lands between two requests of the
|
|
10
|
-
// same page load. Reloading on the second distinct hash turns a dead preview into a
|
|
11
|
-
// flicker.
|
|
12
|
-
|
|
13
|
-
const DEPS_MARKER = "/.vite/deps/";
|
|
14
|
-
const RELOAD_GRACE_MS = 200;
|
|
15
|
-
const RELOAD_BUDGET = 2;
|
|
16
|
-
const RELOAD_WINDOW_MS = 15_000;
|
|
17
|
-
const STORAGE_KEY = "__base44_stale_deps_reload";
|
|
18
|
-
|
|
19
|
-
type ReloadRecord = { n: number; t: number };
|
|
20
|
-
|
|
21
|
-
type BudgetStorage = Pick<Storage, "getItem" | "setItem">;
|
|
22
|
-
|
|
23
|
-
export type StaleDepsTracker = { observe: (url: string) => boolean };
|
|
24
|
-
|
|
25
|
-
export type StaleDepsReloaderOptions = {
|
|
26
|
-
reload?: () => void;
|
|
27
|
-
now?: () => number;
|
|
28
|
-
storage?: BudgetStorage | null;
|
|
29
|
-
graceMs?: number;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/** The `v` param of an optimized-dep URL, or null for anything else. */
|
|
33
|
-
export function extractDepHash(url: string): string | null {
|
|
34
|
-
if (!url.includes(DEPS_MARKER)) return null;
|
|
35
|
-
const query = url.indexOf("?");
|
|
36
|
-
if (query === -1) return null;
|
|
37
|
-
return new URLSearchParams(url.slice(query + 1)).get("v");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Reports true once a dep URL carries a hash different from the first one seen. */
|
|
41
|
-
export function createStaleDepsTracker(): StaleDepsTracker {
|
|
42
|
-
let firstHash: string | null = null;
|
|
43
|
-
return {
|
|
44
|
-
observe(url: string): boolean {
|
|
45
|
-
const hash = extractDepHash(url);
|
|
46
|
-
if (hash === null) return false;
|
|
47
|
-
if (firstHash === null) {
|
|
48
|
-
firstHash = hash;
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
return hash !== firstHash;
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Consume one reload from the per-window budget. Fails open when storage is
|
|
58
|
-
* unreadable — an unrecoverable white screen is worse than a reload loop we can
|
|
59
|
-
* at least see in the logs.
|
|
60
|
-
*/
|
|
61
|
-
export function takeReloadBudget(storage: BudgetStorage, now: number): boolean {
|
|
62
|
-
let prev: ReloadRecord | null = null;
|
|
63
|
-
try {
|
|
64
|
-
const raw = storage.getItem(STORAGE_KEY);
|
|
65
|
-
if (raw) prev = JSON.parse(raw) as ReloadRecord;
|
|
66
|
-
} catch {
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
let n = 1;
|
|
71
|
-
let windowStart = now;
|
|
72
|
-
if (prev && typeof prev.n === "number" && now - prev.t < RELOAD_WINDOW_MS) {
|
|
73
|
-
n = prev.n + 1;
|
|
74
|
-
windowStart = prev.t;
|
|
75
|
-
}
|
|
76
|
-
if (n > RELOAD_BUDGET) return false;
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
storage.setItem(STORAGE_KEY, JSON.stringify({ n, t: windowStart }));
|
|
80
|
-
} catch {
|
|
81
|
-
// Budget can't be persisted; the cap degrades but the reload still helps.
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function defaultStorage(): BudgetStorage | null {
|
|
87
|
-
try {
|
|
88
|
-
return window.sessionStorage;
|
|
89
|
-
} catch {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function notifyParent(type: string): void {
|
|
95
|
-
try {
|
|
96
|
-
window.parent?.postMessage({ type }, "*");
|
|
97
|
-
} catch {
|
|
98
|
-
// Parent is cross-origin or gone; observability is best-effort.
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function setupStaleDepsReloader(
|
|
103
|
-
options: StaleDepsReloaderOptions = {}
|
|
104
|
-
): () => void {
|
|
105
|
-
const reload = options.reload ?? ((): void => window.location.reload());
|
|
106
|
-
const now = options.now ?? ((): number => Date.now());
|
|
107
|
-
const graceMs = options.graceMs ?? RELOAD_GRACE_MS;
|
|
108
|
-
const storage =
|
|
109
|
-
options.storage === undefined ? defaultStorage() : options.storage;
|
|
110
|
-
|
|
111
|
-
const Observer = globalThis.PerformanceObserver;
|
|
112
|
-
if (typeof Observer !== "function") return (): void => {};
|
|
113
|
-
|
|
114
|
-
const tracker = createStaleDepsTracker();
|
|
115
|
-
let viteIsReloading = false;
|
|
116
|
-
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
117
|
-
let done = false;
|
|
118
|
-
|
|
119
|
-
// Vite handles most swaps itself. Stand down rather than reload twice.
|
|
120
|
-
if (import.meta.hot) {
|
|
121
|
-
import.meta.hot.on("vite:beforeFullReload", () => {
|
|
122
|
-
viteIsReloading = true;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const scheduleReload = (): void => {
|
|
127
|
-
if (done || timer !== null) return;
|
|
128
|
-
// The grace exists to let Vite's own full reload win the race. During the
|
|
129
|
-
// initial load its HMR client may not even be connected yet, and every
|
|
130
|
-
// millisecond of delay is a millisecond of broken preview — so don't wait.
|
|
131
|
-
const delay = document.readyState === "loading" ? 0 : graceMs;
|
|
132
|
-
timer = setTimeout(() => {
|
|
133
|
-
timer = null;
|
|
134
|
-
if (done || viteIsReloading) return;
|
|
135
|
-
done = true;
|
|
136
|
-
observer.disconnect();
|
|
137
|
-
if (storage && !takeReloadBudget(storage, now())) {
|
|
138
|
-
notifyParent("sandbox:staleDepsReloadBudgetExhausted");
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
notifyParent("sandbox:staleDepsReload");
|
|
142
|
-
reload();
|
|
143
|
-
}, delay);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const observer = new Observer((list: PerformanceObserverEntryList) => {
|
|
147
|
-
for (const entry of list.getEntries()) {
|
|
148
|
-
if (tracker.observe(entry.name)) scheduleReload();
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
try {
|
|
153
|
-
observer.observe({ type: "resource", buffered: true });
|
|
154
|
-
} catch {
|
|
155
|
-
return (): void => {};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// `buffered` is not honored everywhere; sweep what already landed.
|
|
159
|
-
try {
|
|
160
|
-
for (const entry of performance.getEntriesByType("resource")) {
|
|
161
|
-
if (tracker.observe(entry.name)) scheduleReload();
|
|
162
|
-
}
|
|
163
|
-
} catch {
|
|
164
|
-
// No resource timing available; the observer above is the only source.
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return (): void => {
|
|
168
|
-
done = true;
|
|
169
|
-
if (timer !== null) {
|
|
170
|
-
clearTimeout(timer);
|
|
171
|
-
timer = null;
|
|
172
|
-
}
|
|
173
|
-
observer.disconnect();
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (typeof window !== "undefined") {
|
|
178
|
-
setupStaleDepsReloader();
|
|
179
|
-
}
|