@jundle/cloudflare 0.0.1-14 → 0.0.1-15
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/package.json +1 -1
- package/src/harness.js +36 -2
package/package.json
CHANGED
package/src/harness.js
CHANGED
|
@@ -220,16 +220,50 @@ async function syncVersion() {
|
|
|
220
220
|
// document in a worker), and surfacing it would trip the
|
|
221
221
|
// hot client's first-update overlay rule and force a full
|
|
222
222
|
// reload on the next update instead of HMR.
|
|
223
|
+
//
|
|
224
|
+
// The re-import can install a second (browser) shim over
|
|
225
|
+
// the dev shim's globals — client.browser.js imports
|
|
226
|
+
// ./shim.js first, so any module importing the client
|
|
227
|
+
// runtime installs it as a side effect — and the
|
|
228
|
+
// client's chunkCache skips re-loading chunks, so a
|
|
229
|
+
// poisoned global makes the next render require through
|
|
230
|
+
// an empty shim ("has not been loaded yet"). Snapshot the
|
|
231
|
+
// four shim globals before the re-import and restore
|
|
232
|
+
// them before the push lands (finally, so a failed
|
|
233
|
+
// import cannot leave them poisoned). A snapshot of
|
|
234
|
+
// undefined restores by deleting the global, not by
|
|
235
|
+
// assigning undefined (the shim was not installed yet).
|
|
236
|
+
const SHIM_GLOBALS = [
|
|
237
|
+
"__webpack_require__",
|
|
238
|
+
"__webpack_chunk_load__",
|
|
239
|
+
"__webpack_get_script_filename__",
|
|
240
|
+
"__jundleFlight",
|
|
241
|
+
];
|
|
242
|
+
function snapshotShimGlobals() {
|
|
243
|
+
return SHIM_GLOBALS.map((name) => [name, globalThis[name]]);
|
|
244
|
+
}
|
|
245
|
+
function restoreShimGlobals(saved) {
|
|
246
|
+
for (const [name, value] of saved) {
|
|
247
|
+
if (value === undefined) delete globalThis[name];
|
|
248
|
+
else globalThis[name] = value;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
223
251
|
async function pushSsrUpdates(clientKeys) {
|
|
224
252
|
for (const key of clientKeys) {
|
|
225
253
|
const [env, file] = key.split("\0");
|
|
226
254
|
const url = `/@jundle/module?env=${encodeURIComponent(env)}&file=${encodeURIComponent(file)}`;
|
|
255
|
+
const saved = snapshotShimGlobals();
|
|
256
|
+
let rec;
|
|
257
|
+
let ok = false;
|
|
227
258
|
try {
|
|
228
|
-
|
|
229
|
-
|
|
259
|
+
rec = await ensureModuleByUrl(url);
|
|
260
|
+
ok = true;
|
|
230
261
|
} catch (e) {
|
|
231
262
|
console.error(`[jundle runner] SSR push ${url}: ${e && e.message ? e.message : String(e)}`);
|
|
263
|
+
} finally {
|
|
264
|
+
restoreShimGlobals(saved);
|
|
232
265
|
}
|
|
266
|
+
if (ok) globalThis.__jundleFlight?.updateModule?.(url, rec.exports);
|
|
233
267
|
}
|
|
234
268
|
}
|
|
235
269
|
|