@krate/runtime 0.5.0-rc.11 → 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/react-compat.d.ts +7 -0
- package/dist/react-compat.js +36 -2
- package/dist/router.js +22 -0
- package/package.json +1 -1
package/dist/react-compat.d.ts
CHANGED
|
@@ -36,4 +36,11 @@ export declare function createReactCompatExtras(c: any, options: any): ReactComp
|
|
|
36
36
|
* client builds call it from their `react` module, once per Preact instance.
|
|
37
37
|
*/
|
|
38
38
|
export declare function installDiscreteEffects(options: any): void;
|
|
39
|
+
/**
|
|
40
|
+
* The vnodes whose diff has started and not finished, kept in
|
|
41
|
+
* options.__krateOpen (the compiler's shared preact/hooks module installs the
|
|
42
|
+
* same tracker). It is empty between renders. __b is Preact's diff hook; a
|
|
43
|
+
* vnode whose render throws gets __e (the error hook) instead of diffed.
|
|
44
|
+
*/
|
|
45
|
+
export declare function trackRenders(options: any): Set<unknown>;
|
|
39
46
|
export {};
|
package/dist/react-compat.js
CHANGED
|
@@ -348,12 +348,46 @@ export function installDiscreteEffects(options) {
|
|
|
348
348
|
raf = requestAnimationFrame(done);
|
|
349
349
|
};
|
|
350
350
|
// options._commit (mangled __c) runs after refs and, through preact/hooks'
|
|
351
|
-
// own wrapper, after layout effects.
|
|
351
|
+
// own wrapper, after layout effects. Only a commit that ends a render
|
|
352
|
+
// flushes: a portal commits while its parent's render is still running, and
|
|
353
|
+
// the queue then holds the effects of components rendered earlier in that
|
|
354
|
+
// pass, whose layout and insertion effects have not run yet.
|
|
355
|
+
const open = trackRenders(options);
|
|
352
356
|
const prevCommit = options.__c;
|
|
353
357
|
options.__c = (vnode, queue) => {
|
|
354
358
|
if (prevCommit)
|
|
355
359
|
prevCommit(vnode, queue);
|
|
356
|
-
if (discrete && flushEffects)
|
|
360
|
+
if (discrete && flushEffects && open.size === 0)
|
|
357
361
|
flushEffects();
|
|
358
362
|
};
|
|
359
363
|
}
|
|
364
|
+
/**
|
|
365
|
+
* The vnodes whose diff has started and not finished, kept in
|
|
366
|
+
* options.__krateOpen (the compiler's shared preact/hooks module installs the
|
|
367
|
+
* same tracker). It is empty between renders. __b is Preact's diff hook; a
|
|
368
|
+
* vnode whose render throws gets __e (the error hook) instead of diffed.
|
|
369
|
+
*/
|
|
370
|
+
export function trackRenders(options) {
|
|
371
|
+
if (options.__krateOpen)
|
|
372
|
+
return options.__krateOpen;
|
|
373
|
+
const open = new Set();
|
|
374
|
+
options.__krateOpen = open;
|
|
375
|
+
const prevDiff = options.__b;
|
|
376
|
+
const prevDiffed = options.diffed;
|
|
377
|
+
const prevError = options.__e;
|
|
378
|
+
options.__b = (vnode) => {
|
|
379
|
+
open.add(vnode);
|
|
380
|
+
if (prevDiff)
|
|
381
|
+
prevDiff(vnode);
|
|
382
|
+
};
|
|
383
|
+
options.diffed = (vnode) => {
|
|
384
|
+
open.delete(vnode);
|
|
385
|
+
if (prevDiffed)
|
|
386
|
+
prevDiffed(vnode);
|
|
387
|
+
};
|
|
388
|
+
options.__e = function (error, vnode, ...rest) {
|
|
389
|
+
open.delete(vnode);
|
|
390
|
+
return prevError.call(this, error, vnode, ...rest);
|
|
391
|
+
};
|
|
392
|
+
return open;
|
|
393
|
+
}
|
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