@krate/runtime 0.5.0-rc.12 → 0.5.0-rc.13
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/krate-f-router.js +1 -1
- package/dist/krate-hydrate.js +5 -5
- package/dist/krate-runtime.js +5 -5
- package/dist/router.js +22 -0
- package/package.json +1 -1
package/dist/router.js
CHANGED
|
@@ -1304,9 +1304,30 @@ async function runNavigation(req) {
|
|
|
1304
1304
|
}
|
|
1305
1305
|
await commitDocument(result.doc, req, seq);
|
|
1306
1306
|
}
|
|
1307
|
+
/** The build a document belongs to: the compiler's krate-build meta ("" in dev). */
|
|
1308
|
+
function buildOf(doc) {
|
|
1309
|
+
const meta = doc.querySelector('meta[name="krate-build"]');
|
|
1310
|
+
return (meta && meta.getAttribute('content')) || '';
|
|
1311
|
+
}
|
|
1312
|
+
/** The build of the page that started the router. */
|
|
1313
|
+
let loadedBuild;
|
|
1307
1314
|
async function commitDocument(loaded, req, seq) {
|
|
1308
1315
|
const doc = new DOMParser().parseFromString(loaded.html, 'text/html');
|
|
1309
1316
|
const url = loaded.url;
|
|
1317
|
+
// A document of another build (a deploy since this page loaded) brings that
|
|
1318
|
+
// build's islands and page scripts. Next to the modules already running (a
|
|
1319
|
+
// kept layout island), every module they share would exist twice, such as
|
|
1320
|
+
// a React context its provider and consumers then disagree on. Load it with a
|
|
1321
|
+
// full navigation, as Next.js does when its build id changes.
|
|
1322
|
+
if (loadedBuild === undefined)
|
|
1323
|
+
loadedBuild = buildOf(document);
|
|
1324
|
+
const build = buildOf(doc);
|
|
1325
|
+
if (loadedBuild && build && build !== loadedBuild) {
|
|
1326
|
+
endTransition();
|
|
1327
|
+
setStatus('idle');
|
|
1328
|
+
hardNavigate(url, req.kind !== 'push');
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1310
1331
|
const newRoot = appRoot(doc);
|
|
1311
1332
|
const oldRoot = appRoot(document);
|
|
1312
1333
|
// Load the incoming stylesheets before swapping so the new page (and kept
|
|
@@ -2355,6 +2376,7 @@ export function destroyRouter() {
|
|
|
2355
2376
|
if (!initialized)
|
|
2356
2377
|
return;
|
|
2357
2378
|
initialized = false;
|
|
2379
|
+
loadedBuild = undefined;
|
|
2358
2380
|
if (globalThis[LIVE_ROUTER] === krateRouter)
|
|
2359
2381
|
delete globalThis[LIVE_ROUTER];
|
|
2360
2382
|
document.removeEventListener('click', clickHandler);
|
package/package.json
CHANGED