@krate/runtime 0.5.0-beta.3 → 0.5.0-rc.10
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/action-context.js +1 -1
- package/dist/actions.d.ts +7 -0
- package/dist/actions.js +34 -10
- package/dist/after.d.ts +28 -0
- package/dist/after.js +48 -0
- package/dist/assets-static.d.ts +10 -1
- package/dist/assets-static.js +10 -2
- package/dist/base-path.d.ts +7 -0
- package/dist/base-path.js +20 -0
- package/dist/boundary.js +1 -1
- package/dist/builtin-tags.d.ts +12 -0
- package/dist/builtin-tags.js +42 -0
- package/dist/cache-adapter.js +1 -1
- package/dist/cache-scope.d.ts +8 -0
- package/dist/cache-scope.js +14 -1
- package/dist/cloudflare-workers.d.ts +2 -0
- package/dist/cloudflare-workers.js +27 -0
- package/dist/context.d.ts +5 -0
- package/dist/context.js +28 -17
- package/dist/dev-overlay.d.ts +54 -3
- package/dist/dev-overlay.js +496 -91
- package/dist/dom.d.ts +4 -0
- package/dist/dom.js +62 -16
- package/dist/effects.js +43 -10
- package/dist/events.d.ts +2 -0
- package/dist/events.js +18 -0
- package/dist/flight-props.d.ts +7 -0
- package/dist/flight-props.js +105 -0
- package/dist/handler-html.js +4 -4
- package/dist/handler-routing.d.ts +2 -23
- package/dist/handler-routing.js +9 -190
- package/dist/handler-segments.d.ts +6 -0
- package/dist/handler-segments.js +18 -4
- package/dist/head-tags.d.ts +9 -0
- package/dist/head-tags.js +93 -6
- package/dist/highlight-bind.js +1 -1
- package/dist/highlight.d.ts +3 -2
- package/dist/highlight.js +17 -12
- package/dist/hints.d.ts +25 -2
- package/dist/hints.js +147 -74
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/island-swap.d.ts +47 -0
- package/dist/island-swap.js +635 -0
- package/dist/jsx-dev-runtime.d.ts +1 -1
- package/dist/jsx-types.d.ts +99 -3
- package/dist/krate-core.js +1 -1
- package/dist/krate-dev.js +407 -80
- package/dist/krate-f-actions.js +1 -1
- package/dist/krate-f-classes.js +1 -1
- package/dist/krate-f-highlight.js +1 -1
- package/dist/krate-f-list.js +1 -1
- package/dist/krate-f-navigation.js +1 -1
- package/dist/krate-f-router-lite.js +1 -1
- package/dist/krate-f-router.js +1 -1
- package/dist/krate-features.json +455 -0
- package/dist/krate-hydrate-lite.js +5 -5
- package/dist/krate-hydrate.js +5 -5
- package/dist/krate-island-swap.js +1 -0
- package/dist/krate-runtime.js +5 -5
- package/dist/krate-suspense.js +1 -1
- package/dist/list.d.ts +14 -4
- package/dist/list.js +30 -23
- package/dist/metadata.js +5 -2
- package/dist/navigation-react.d.ts +13 -0
- package/dist/navigation-react.js +86 -0
- package/dist/navigation.d.ts +19 -0
- package/dist/navigation.js +35 -0
- package/dist/node-server.js +3 -3
- package/dist/og.js +1 -1
- package/dist/platform.d.ts +52 -0
- package/dist/platform.js +57 -0
- package/dist/react-compat.d.ts +39 -0
- package/dist/react-compat.js +359 -0
- package/dist/react-server.d.ts +63 -0
- package/dist/react-server.js +125 -0
- package/dist/region-wire.d.ts +10 -0
- package/dist/region-wire.js +154 -0
- package/dist/request-context.js +1 -1
- package/dist/request-extras.d.ts +4 -0
- package/dist/request-extras.js +51 -0
- package/dist/resp.js +1 -1
- package/dist/route-source.d.ts +39 -0
- package/dist/route-source.js +532 -0
- package/dist/router-lite.js +3 -9
- package/dist/router.d.ts +1 -1
- package/dist/router.js +675 -100
- package/dist/server-handler.d.ts +69 -1
- package/dist/server-handler.js +515 -96
- package/dist/server-renderer.js +16 -7
- package/dist/server.d.ts +73 -16
- package/dist/server.js +619 -102
- package/dist/sha256.js +9 -9
- package/dist/signal.js +47 -20
- package/dist/site-config.d.ts +15 -0
- package/dist/site-config.js +28 -0
- package/dist/slot.d.ts +12 -0
- package/dist/slot.js +23 -0
- package/dist/ssr-core.d.ts +2 -0
- package/dist/ssr-core.js +12 -4
- package/dist/suspense.js +34 -2
- package/dist/testing.d.ts +62 -0
- package/dist/testing.js +90 -0
- package/dist/use-id.js +1 -1
- package/package.json +28 -3
- package/dist/action-context.test.d.ts +0 -1
- package/dist/action-context.test.js +0 -72
- package/dist/actions.test.d.ts +0 -1
- package/dist/actions.test.js +0 -477
- package/dist/cache-adapter.test.d.ts +0 -1
- package/dist/cache-adapter.test.js +0 -244
- package/dist/cache.test.d.ts +0 -1
- package/dist/cache.test.js +0 -233
- package/dist/class-component.test.d.ts +0 -1
- package/dist/class-component.test.js +0 -462
- package/dist/class-helpers.test.d.ts +0 -1
- package/dist/class-helpers.test.js +0 -169
- package/dist/context.test.d.ts +0 -1
- package/dist/context.test.js +0 -57
- package/dist/derived.test.d.ts +0 -1
- package/dist/derived.test.js +0 -140
- package/dist/dev-overlay.test.d.ts +0 -1
- package/dist/dev-overlay.test.js +0 -152
- package/dist/discrete.test.d.ts +0 -1
- package/dist/discrete.test.js +0 -100
- package/dist/dom.test.d.ts +0 -1
- package/dist/dom.test.js +0 -31
- package/dist/effect-errors.test.d.ts +0 -1
- package/dist/effect-errors.test.js +0 -163
- package/dist/effects.test.d.ts +0 -1
- package/dist/effects.test.js +0 -485
- package/dist/events.test.d.ts +0 -1
- package/dist/events.test.js +0 -447
- package/dist/handler-html.test.d.ts +0 -1
- package/dist/handler-html.test.js +0 -256
- package/dist/handler-routing.test.d.ts +0 -1
- package/dist/handler-routing.test.js +0 -99
- package/dist/handler-segments.test.d.ts +0 -1
- package/dist/handler-segments.test.js +0 -217
- package/dist/head-tags.test.d.ts +0 -1
- package/dist/head-tags.test.js +0 -131
- package/dist/highlight-bind.test.d.ts +0 -1
- package/dist/highlight-bind.test.js +0 -124
- package/dist/highlight.test.d.ts +0 -1
- package/dist/highlight.test.js +0 -56
- package/dist/lanes.test.d.ts +0 -1
- package/dist/lanes.test.js +0 -59
- package/dist/list.test.d.ts +0 -1
- package/dist/list.test.js +0 -344
- package/dist/metadata.test.d.ts +0 -1
- package/dist/metadata.test.js +0 -167
- package/dist/navigation.test.d.ts +0 -1
- package/dist/navigation.test.js +0 -130
- package/dist/node-server.test.d.ts +0 -1
- package/dist/node-server.test.js +0 -492
- package/dist/optimistic-lanes.test.d.ts +0 -1
- package/dist/optimistic-lanes.test.js +0 -45
- package/dist/patterns.test.d.ts +0 -1
- package/dist/patterns.test.js +0 -98
- package/dist/portal.test.d.ts +0 -1
- package/dist/portal.test.js +0 -99
- package/dist/react-effects.test.d.ts +0 -1
- package/dist/react-effects.test.js +0 -96
- package/dist/react-suspense.test.d.ts +0 -1
- package/dist/react-suspense.test.js +0 -194
- package/dist/react.test.d.ts +0 -1
- package/dist/react.test.js +0 -60
- package/dist/react19.test.d.ts +0 -1
- package/dist/react19.test.js +0 -176
- package/dist/reactivity-core.test.d.ts +0 -1
- package/dist/reactivity-core.test.js +0 -152
- package/dist/reconcile.test.d.ts +0 -1
- package/dist/reconcile.test.js +0 -110
- package/dist/refs.test.d.ts +0 -1
- package/dist/refs.test.js +0 -257
- package/dist/router-layout.test.d.ts +0 -1
- package/dist/router-layout.test.js +0 -249
- package/dist/router-nav.test.d.ts +0 -1
- package/dist/router-nav.test.js +0 -464
- package/dist/router-slots.test.d.ts +0 -1
- package/dist/router-slots.test.js +0 -144
- package/dist/router-speculation.test.d.ts +0 -1
- package/dist/router-speculation.test.js +0 -25
- package/dist/router-styles.test.d.ts +0 -1
- package/dist/router-styles.test.js +0 -98
- package/dist/router.test.d.ts +0 -1
- package/dist/router.test.js +0 -36
- package/dist/server-async.test.d.ts +0 -1
- package/dist/server-async.test.js +0 -216
- package/dist/server-handler.test.d.ts +0 -1
- package/dist/server-handler.test.js +0 -535
- package/dist/server-highlight.test.d.ts +0 -1
- package/dist/server-highlight.test.js +0 -32
- package/dist/server-renderer.test.d.ts +0 -1
- package/dist/server-renderer.test.js +0 -266
- package/dist/server.test.d.ts +0 -1
- package/dist/server.test.js +0 -88
- package/dist/sha256.test.d.ts +0 -1
- package/dist/sha256.test.js +0 -13
- package/dist/signal-lanes.test.d.ts +0 -1
- package/dist/signal-lanes.test.js +0 -32
- package/dist/signal.test.d.ts +0 -1
- package/dist/signal.test.js +0 -68
- package/dist/slots.test.d.ts +0 -1
- package/dist/slots.test.js +0 -169
- package/dist/snapshots.test.d.ts +0 -1
- package/dist/snapshots.test.js +0 -208
- package/dist/ssr-core-behavior.test.d.ts +0 -1
- package/dist/ssr-core-behavior.test.js +0 -620
- package/dist/ssr-core.test.d.ts +0 -1
- package/dist/ssr-core.test.js +0 -324
- package/dist/static-memory.test.d.ts +0 -1
- package/dist/static-memory.test.js +0 -26
- package/dist/storage.test.d.ts +0 -1
- package/dist/storage.test.js +0 -46
- package/dist/suspense-actions.test.d.ts +0 -1
- package/dist/suspense-actions.test.js +0 -72
- package/dist/suspense.test.d.ts +0 -1
- package/dist/suspense.test.js +0 -518
package/dist/sha256.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Portable synchronous SHA-256 (no node:crypto, no Web Crypto) so the render
|
|
2
2
|
// core can compute the same error digest on Node, Workers and edge hosts.
|
|
3
3
|
const K = new Uint32Array([
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
|
|
5
|
+
0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
|
|
6
|
+
0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
|
|
7
|
+
0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
|
|
8
|
+
0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
|
|
9
|
+
0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
|
|
10
|
+
0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
|
|
11
|
+
0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2,
|
|
12
12
|
]);
|
|
13
13
|
export function sha256Hex(input) {
|
|
14
14
|
const msg = new TextEncoder().encode(input);
|
|
@@ -21,7 +21,7 @@ export function sha256Hex(input) {
|
|
|
21
21
|
view.setUint32(total - 8, Math.floor(bitLen / 0x100000000), false);
|
|
22
22
|
view.setUint32(total - 4, bitLen >>> 0, false);
|
|
23
23
|
const h = new Uint32Array([
|
|
24
|
-
|
|
24
|
+
0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19,
|
|
25
25
|
]);
|
|
26
26
|
const w = new Uint32Array(64);
|
|
27
27
|
const rotr = (x, n) => (x >>> n) | (x << (32 - n));
|
package/dist/signal.js
CHANGED
|
@@ -80,7 +80,6 @@ export function krateTagOwner(owner, scope) {
|
|
|
80
80
|
// subscriber re-runs into a single flush so N writes in a loop (or one write
|
|
81
81
|
// fanning out) produce one pass instead of N synchronous effect runs.
|
|
82
82
|
const pending = [];
|
|
83
|
-
let flushScheduled = false;
|
|
84
83
|
function newEffectState(fn) {
|
|
85
84
|
const scope = krateCurrentScope();
|
|
86
85
|
const effect = { fn, cleanups: [], disposed: false, sources: new Set(), running: false, rerun: false, queued: false, owner: currentOwner, boundaryOwner: ownerHooks ? ownerHooks.current() : null, scope };
|
|
@@ -106,7 +105,7 @@ export function krateDisposeOwner(owner) {
|
|
|
106
105
|
ownerEffects.delete(owner);
|
|
107
106
|
if (effects) {
|
|
108
107
|
for (const effect of effects) {
|
|
109
|
-
|
|
108
|
+
disposeEffectQuietly(effect);
|
|
110
109
|
allEffects.delete(effect);
|
|
111
110
|
}
|
|
112
111
|
}
|
|
@@ -341,6 +340,31 @@ function drainAfterQueue() {
|
|
|
341
340
|
export function sameValue(a, b) {
|
|
342
341
|
return Object.is(a, b);
|
|
343
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Runs every cleanup in order even when one throws, so a failing cleanup
|
|
345
|
+
* cannot strand the listeners and timers registered after it; the first error
|
|
346
|
+
* is rethrown once all have run, the others are logged.
|
|
347
|
+
*/
|
|
348
|
+
function runCleanups(list) {
|
|
349
|
+
let failed = false;
|
|
350
|
+
let first;
|
|
351
|
+
for (const cleanup of list.splice(0)) {
|
|
352
|
+
try {
|
|
353
|
+
cleanup();
|
|
354
|
+
}
|
|
355
|
+
catch (err) {
|
|
356
|
+
if (!failed) {
|
|
357
|
+
failed = true;
|
|
358
|
+
first = err;
|
|
359
|
+
}
|
|
360
|
+
else if (typeof console !== 'undefined') {
|
|
361
|
+
console.error(err);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (failed)
|
|
366
|
+
throw first;
|
|
367
|
+
}
|
|
344
368
|
function disposeEffect(effect) {
|
|
345
369
|
if (!effect.disposed) {
|
|
346
370
|
effect.disposed = true;
|
|
@@ -352,10 +376,17 @@ function disposeEffect(effect) {
|
|
|
352
376
|
set.delete(effect);
|
|
353
377
|
}
|
|
354
378
|
effect.sources.clear();
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
379
|
+
runCleanups(effect.cleanups);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/** Teardown disposal: a failing cleanup is logged and never stops the sweep. */
|
|
383
|
+
function disposeEffectQuietly(effect) {
|
|
384
|
+
try {
|
|
385
|
+
disposeEffect(effect);
|
|
386
|
+
}
|
|
387
|
+
catch (err) {
|
|
388
|
+
if (typeof console !== 'undefined')
|
|
389
|
+
console.error(err);
|
|
359
390
|
}
|
|
360
391
|
}
|
|
361
392
|
/**
|
|
@@ -393,13 +424,15 @@ function disposeMatching(gone, pageTeardown) {
|
|
|
393
424
|
try {
|
|
394
425
|
hook(gone);
|
|
395
426
|
}
|
|
396
|
-
catch {
|
|
427
|
+
catch (err) {
|
|
397
428
|
// Unmount errors must not prevent the rest of the teardown.
|
|
429
|
+
if (typeof console !== 'undefined')
|
|
430
|
+
console.error(err);
|
|
398
431
|
}
|
|
399
432
|
}
|
|
400
433
|
for (const effect of Array.from(allEffects)) {
|
|
401
434
|
if (gone(effect.scope)) {
|
|
402
|
-
|
|
435
|
+
disposeEffectQuietly(effect);
|
|
403
436
|
allEffects.delete(effect);
|
|
404
437
|
}
|
|
405
438
|
}
|
|
@@ -447,12 +480,14 @@ export function disposeAll() {
|
|
|
447
480
|
try {
|
|
448
481
|
hook(null);
|
|
449
482
|
}
|
|
450
|
-
catch {
|
|
483
|
+
catch (err) {
|
|
451
484
|
// Unmount errors must not prevent the rest of the teardown.
|
|
485
|
+
if (typeof console !== 'undefined')
|
|
486
|
+
console.error(err);
|
|
452
487
|
}
|
|
453
488
|
}
|
|
454
489
|
for (const effect of allEffects) {
|
|
455
|
-
|
|
490
|
+
disposeEffectQuietly(effect);
|
|
456
491
|
}
|
|
457
492
|
allEffects.clear();
|
|
458
493
|
for (const cleanup of rootCleanups) {
|
|
@@ -488,7 +523,6 @@ export function disposeAll() {
|
|
|
488
523
|
}
|
|
489
524
|
pending.length = 0;
|
|
490
525
|
afterQueue.length = 0;
|
|
491
|
-
flushScheduled = false;
|
|
492
526
|
flushMode = 0;
|
|
493
527
|
flushToken++;
|
|
494
528
|
syncLane = false;
|
|
@@ -825,7 +859,6 @@ function scheduleFlush(reactWrite = false) {
|
|
|
825
859
|
const micro = !later || discrete || committing > 0 || renderDepth > 0 || typeof setTimeout !== 'function';
|
|
826
860
|
if (flushMode === 1 || (!micro && flushMode === 2))
|
|
827
861
|
return;
|
|
828
|
-
flushScheduled = true;
|
|
829
862
|
const token = ++flushToken;
|
|
830
863
|
const run = () => {
|
|
831
864
|
if (token === flushToken)
|
|
@@ -851,7 +884,6 @@ function flushEffects() {
|
|
|
851
884
|
}
|
|
852
885
|
}
|
|
853
886
|
function flushEffectsInner() {
|
|
854
|
-
flushScheduled = false;
|
|
855
887
|
flushMode = 0;
|
|
856
888
|
flushToken++;
|
|
857
889
|
// One effect throwing must not strand the effects queued behind it: their
|
|
@@ -915,7 +947,6 @@ function flushEffectsInner() {
|
|
|
915
947
|
if (pending.length === 0) {
|
|
916
948
|
// The cascade is done: a flush the passes scheduled has nothing to do.
|
|
917
949
|
flushMode = 0;
|
|
918
|
-
flushScheduled = false;
|
|
919
950
|
flushToken++;
|
|
920
951
|
}
|
|
921
952
|
if (pending.length === 0) {
|
|
@@ -973,7 +1004,6 @@ function abortUpdateLoop() {
|
|
|
973
1004
|
const looping = pending.splice(0);
|
|
974
1005
|
for (const effect of looping)
|
|
975
1006
|
effect.queued = false;
|
|
976
|
-
flushScheduled = false;
|
|
977
1007
|
flushMode = 0;
|
|
978
1008
|
flushToken++;
|
|
979
1009
|
const culprits = looping.length > 0 ? looping : lastPassEffects;
|
|
@@ -1053,9 +1083,7 @@ function runEffect(effect) {
|
|
|
1053
1083
|
snapshotEpoch = null;
|
|
1054
1084
|
try {
|
|
1055
1085
|
// Run cleanups from previous execution
|
|
1056
|
-
|
|
1057
|
-
cleanup();
|
|
1058
|
-
}
|
|
1086
|
+
runCleanups(effect.cleanups);
|
|
1059
1087
|
// Re-track from scratch so a dependency the last run did not read stops
|
|
1060
1088
|
// re-running the effect.
|
|
1061
1089
|
for (const set of effect.sources) {
|
|
@@ -1234,8 +1262,7 @@ export function createMemo(fn) {
|
|
|
1234
1262
|
const node = newEffectState(() => { });
|
|
1235
1263
|
allEffects.add(node);
|
|
1236
1264
|
const recompute = () => {
|
|
1237
|
-
|
|
1238
|
-
cleanup();
|
|
1265
|
+
runCleanups(node.cleanups);
|
|
1239
1266
|
for (const source of node.sources)
|
|
1240
1267
|
source.delete(node);
|
|
1241
1268
|
node.sources.clear();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Site config injected by the compiler. */
|
|
2
|
+
export interface KrateRuntimeConfig {
|
|
3
|
+
basePath?: string;
|
|
4
|
+
viewTransitions?: boolean | 'auto';
|
|
5
|
+
/** Milliseconds a prefetched document stays fresh (default 30000). */
|
|
6
|
+
prefetchTTL?: number;
|
|
7
|
+
/** Default link prefetch: "viewport" also prefetches links as they scroll into view. */
|
|
8
|
+
prefetch?: 'intent' | 'viewport';
|
|
9
|
+
/** Set by `krate dev`: enables router dev warnings. */
|
|
10
|
+
dev?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Id of the JSON data block the compiler writes. */
|
|
13
|
+
export declare const CFG_BLOCK_ID = "__krate_cfg__";
|
|
14
|
+
/** The site config, read once from the head's JSON block when the global is not set. */
|
|
15
|
+
export declare function siteConfig(): KrateRuntimeConfig;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// The site runtime config (`__KRATE_CFG__`). The compiler writes it into the
|
|
2
|
+
// page head as a JSON data block rather than an inline script, so a strict
|
|
3
|
+
// `script-src 'self'` policy needs no allowance for it. Server bundles set the
|
|
4
|
+
// global directly. The block is only present when something differs from the
|
|
5
|
+
// defaults (a base path, View Transitions off, dev mode).
|
|
6
|
+
/** Id of the JSON data block the compiler writes. */
|
|
7
|
+
export const CFG_BLOCK_ID = '__krate_cfg__';
|
|
8
|
+
/** The site config, read once from the head's JSON block when the global is not set. */
|
|
9
|
+
export function siteConfig() {
|
|
10
|
+
const g = globalThis;
|
|
11
|
+
if (g.__KRATE_CFG__)
|
|
12
|
+
return g.__KRATE_CFG__;
|
|
13
|
+
const doc = g.document;
|
|
14
|
+
const el = doc && typeof doc.getElementById === 'function' ? doc.getElementById(CFG_BLOCK_ID) : null;
|
|
15
|
+
if (el) {
|
|
16
|
+
try {
|
|
17
|
+
const parsed = JSON.parse(el.textContent || '{}');
|
|
18
|
+
if (parsed && typeof parsed === 'object') {
|
|
19
|
+
g.__KRATE_CFG__ = parsed;
|
|
20
|
+
return parsed;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// a malformed block falls back to the defaults
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {};
|
|
28
|
+
}
|
package/dist/slot.d.ts
CHANGED
|
@@ -5,4 +5,16 @@ export declare const Root: typeof KrateSlot;
|
|
|
5
5
|
export declare function Slottable(props: {
|
|
6
6
|
children?: unknown;
|
|
7
7
|
}): unknown;
|
|
8
|
+
type SlotProps = Record<string, unknown> & {
|
|
9
|
+
children?: unknown;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Radix's `createSlot(ownerName)` (react-slot >= 1.2): a Slot that merges its
|
|
13
|
+
* props and `ref` onto its single child. `ownerName` only labels the component.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createSlot(ownerName: string): (props: SlotProps) => Node | null;
|
|
16
|
+
/** Radix's `createSlottable(ownerName)`: a `Slottable` marker for one owner. */
|
|
17
|
+
export declare function createSlottable(ownerName: string): (props: {
|
|
18
|
+
children?: unknown;
|
|
19
|
+
}) => unknown;
|
|
8
20
|
export default Slot;
|
package/dist/slot.js
CHANGED
|
@@ -8,4 +8,27 @@ export const Root = KrateSlot;
|
|
|
8
8
|
export function Slottable(props) {
|
|
9
9
|
return props?.children;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Radix's `createSlot(ownerName)` (react-slot >= 1.2): a Slot that merges its
|
|
13
|
+
* props and `ref` onto its single child. `ownerName` only labels the component.
|
|
14
|
+
*/
|
|
15
|
+
export function createSlot(ownerName) {
|
|
16
|
+
const OwnerSlot = (props) => {
|
|
17
|
+
const node = KrateSlot(props);
|
|
18
|
+
const ref = props?.ref;
|
|
19
|
+
if (node && typeof ref === 'function')
|
|
20
|
+
ref(node);
|
|
21
|
+
else if (node && ref && typeof ref === 'object')
|
|
22
|
+
ref.current = node;
|
|
23
|
+
return node;
|
|
24
|
+
};
|
|
25
|
+
OwnerSlot.displayName = ownerName + '.Slot';
|
|
26
|
+
return OwnerSlot;
|
|
27
|
+
}
|
|
28
|
+
/** Radix's `createSlottable(ownerName)`: a `Slottable` marker for one owner. */
|
|
29
|
+
export function createSlottable(ownerName) {
|
|
30
|
+
const OwnerSlottable = (props) => props?.children;
|
|
31
|
+
OwnerSlottable.displayName = ownerName + '.Slottable';
|
|
32
|
+
return OwnerSlottable;
|
|
33
|
+
}
|
|
11
34
|
export default Slot;
|
package/dist/ssr-core.d.ts
CHANGED
|
@@ -63,6 +63,8 @@ export interface RenderResponse {
|
|
|
63
63
|
digest?: string;
|
|
64
64
|
stack?: string;
|
|
65
65
|
noStore?: boolean;
|
|
66
|
+
/** An error boundary caught a render error; html is its fallback and the answer is a 500. */
|
|
67
|
+
errorCaught?: boolean;
|
|
66
68
|
}
|
|
67
69
|
export declare function variantKey(req: {
|
|
68
70
|
route: string;
|
package/dist/ssr-core.js
CHANGED
|
@@ -30,7 +30,7 @@ export function newQueryTracker() {
|
|
|
30
30
|
return { keys: new Set(), all: false };
|
|
31
31
|
}
|
|
32
32
|
export function trackedQuery(query, t) {
|
|
33
|
-
const target = { ...
|
|
33
|
+
const target = { ...query };
|
|
34
34
|
const note = (prop) => {
|
|
35
35
|
if (typeof prop === "string" && prop !== "then" && prop !== "toJSON" && prop !== "constructor")
|
|
36
36
|
t.keys.add(prop);
|
|
@@ -369,8 +369,8 @@ export function createSSRCore(opts) {
|
|
|
369
369
|
method: req.method || "GET",
|
|
370
370
|
headers: h,
|
|
371
371
|
cookies: parseCookieHeader(h.get("cookie")),
|
|
372
|
-
params: { ...
|
|
373
|
-
searchParams: tracker ? trackedQuery(req.query, tracker) : { ...
|
|
372
|
+
params: { ...req.params },
|
|
373
|
+
searchParams: tracker ? trackedQuery(req.query, tracker) : { ...req.query },
|
|
374
374
|
};
|
|
375
375
|
}
|
|
376
376
|
function withRequest(req, fn, tracker) {
|
|
@@ -449,6 +449,12 @@ export function createSSRCore(opts) {
|
|
|
449
449
|
status: 200,
|
|
450
450
|
noStore: scope.noStore || invalidated,
|
|
451
451
|
};
|
|
452
|
+
if (scope.errorCaught) {
|
|
453
|
+
// An error boundary rendered its fallback: the page is an error
|
|
454
|
+
// response, so it is never cached (scope.noStore keeps it out of ISR).
|
|
455
|
+
response.errorCaught = true;
|
|
456
|
+
response.noStore = true;
|
|
457
|
+
}
|
|
452
458
|
// An uncacheable read (no-store) keeps the render out of the ISR cache, and
|
|
453
459
|
// a revalidation that landed mid-render means the HTML may be stale.
|
|
454
460
|
if (page.mode === "isr" && !scope.noStore && !invalidated) {
|
|
@@ -585,7 +591,7 @@ export function createSSRCore(opts) {
|
|
|
585
591
|
// defines globalThis.__krate_render(propsJSON)) with the build-time baked props,
|
|
586
592
|
// so nothing is re-derived at request time.
|
|
587
593
|
function regionProps(region, req) {
|
|
588
|
-
const props = { ...
|
|
594
|
+
const props = { ...region.props };
|
|
589
595
|
if (req.params && Object.keys(req.params).length > 0)
|
|
590
596
|
props.params = req.params;
|
|
591
597
|
if (req.query && Object.keys(req.query).length > 0)
|
|
@@ -865,6 +871,8 @@ export function createSSRCore(opts) {
|
|
|
865
871
|
frame.stack = result.stack;
|
|
866
872
|
if (result.noStore)
|
|
867
873
|
frame.noStore = true;
|
|
874
|
+
if (result.errorCaught)
|
|
875
|
+
frame.errorCaught = true;
|
|
868
876
|
if (page.serverComponents && frame.status >= 500)
|
|
869
877
|
frame.fatal = true;
|
|
870
878
|
// The page's <Head> children (title, meta, link, script) render in place;
|
package/dist/suspense.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* content keeps showing it when a transition update suspends it, and the
|
|
24
24
|
* transition stays pending until that work and any async action settle.
|
|
25
25
|
*/
|
|
26
|
-
import { createSignal, createEffect, onCleanup, krateGetOwner, krateSetOwner } from './signal.js';
|
|
26
|
+
import { createSignal, createEffect, onCleanup, krateGetOwner, krateSetOwner, krateOnDispose, krateCurrentScope } from './signal.js';
|
|
27
27
|
const tracked = new WeakSet();
|
|
28
28
|
export function isThenable(value) {
|
|
29
29
|
return (value != null &&
|
|
@@ -369,6 +369,9 @@ class BoundaryController {
|
|
|
369
369
|
this.pending = new Set();
|
|
370
370
|
this.holds = 0;
|
|
371
371
|
this.scheduled = false;
|
|
372
|
+
/** Route scope the boundary belongs to, and whether its page is gone. */
|
|
373
|
+
this.route = krateCurrentScope();
|
|
374
|
+
this.dead = false;
|
|
372
375
|
this.throttle = null;
|
|
373
376
|
this.id = id;
|
|
374
377
|
this.anchor = anchor;
|
|
@@ -420,6 +423,10 @@ class BoundaryController {
|
|
|
420
423
|
});
|
|
421
424
|
}
|
|
422
425
|
update() {
|
|
426
|
+
// A boundary of a page that was navigated away from must not touch the DOM
|
|
427
|
+
// or the slot state of the page that replaced it.
|
|
428
|
+
if (this.dead)
|
|
429
|
+
return;
|
|
423
430
|
const want = this.pending.size === 0 && this.holds === 0;
|
|
424
431
|
if (want === this.content)
|
|
425
432
|
return;
|
|
@@ -609,6 +616,23 @@ export function registerBoundary(boundary) {
|
|
|
609
616
|
export function resetBoundaries() {
|
|
610
617
|
boundaries.clear();
|
|
611
618
|
}
|
|
619
|
+
// Suspended component runs and compiled boundaries are retried when their
|
|
620
|
+
// promise settles, which can be after the user left the page: a retry would
|
|
621
|
+
// mount the effects of a page that is gone. A page teardown (soft navigation)
|
|
622
|
+
// marks the ones it removed dead.
|
|
623
|
+
const liveRuns = new Set();
|
|
624
|
+
krateOnDispose((gone) => {
|
|
625
|
+
for (const run of liveRuns) {
|
|
626
|
+
if (gone === null || gone(run.route))
|
|
627
|
+
run.dead = true;
|
|
628
|
+
}
|
|
629
|
+
for (const [id, b] of Array.from(boundaries)) {
|
|
630
|
+
if (b instanceof BoundaryController && (gone === null || gone(b.route))) {
|
|
631
|
+
b.dead = true;
|
|
632
|
+
boundaries.delete(id);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
});
|
|
612
636
|
/**
|
|
613
637
|
* Suspends `boundary` on `t`. Inside a transition an already revealed
|
|
614
638
|
* boundary keeps its content and the transition waits instead; with no
|
|
@@ -634,10 +658,15 @@ export function currentBoundary() {
|
|
|
634
658
|
*/
|
|
635
659
|
export function __krateBoundary(id, fn) {
|
|
636
660
|
const boundary = id ? getBoundary(id) : null;
|
|
637
|
-
const state = { boundary, scope: { list: [], i: 0 }, disposers: [] };
|
|
661
|
+
const state = { boundary, scope: { list: [], i: 0 }, disposers: [], route: krateCurrentScope(), dead: false };
|
|
638
662
|
const errOwner = errorOwner();
|
|
639
663
|
boundary?.hold();
|
|
640
664
|
const attempt = () => {
|
|
665
|
+
// The page was left while the promise was pending: do not mount it now.
|
|
666
|
+
if (state.dead) {
|
|
667
|
+
liveRuns.delete(state);
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
641
670
|
state.scope.i = 0;
|
|
642
671
|
const prev = currentRun;
|
|
643
672
|
currentRun = state;
|
|
@@ -649,6 +678,7 @@ export function __krateBoundary(id, fn) {
|
|
|
649
678
|
withReadScope(state.scope, fn);
|
|
650
679
|
currentRun = prev;
|
|
651
680
|
krateSetOwner(owner);
|
|
681
|
+
liveRuns.delete(state);
|
|
652
682
|
boundary?.release();
|
|
653
683
|
}
|
|
654
684
|
catch (error) {
|
|
@@ -657,9 +687,11 @@ export function __krateBoundary(id, fn) {
|
|
|
657
687
|
for (const dispose of state.disposers.splice(0))
|
|
658
688
|
dispose();
|
|
659
689
|
if (isSuspenseSignal(error)) {
|
|
690
|
+
liveRuns.add(state);
|
|
660
691
|
error.thenable.then(attempt, attempt);
|
|
661
692
|
return;
|
|
662
693
|
}
|
|
694
|
+
liveRuns.delete(state);
|
|
663
695
|
boundary?.release();
|
|
664
696
|
reportSuspenseError(error, boundary, errOwner);
|
|
665
697
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test helpers, exported from `@krate/runtime/testing`. They call an API route
|
|
3
|
+
* module or a server action in-process, without a running server. Node only
|
|
4
|
+
* (it uses AsyncLocalStorage); import it from your test files, never from app
|
|
5
|
+
* code.
|
|
6
|
+
*/
|
|
7
|
+
import type { KrateRequest } from "./after.js";
|
|
8
|
+
export type RouteMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
|
9
|
+
export type RouteHandler = (request: KrateRequest, context: {
|
|
10
|
+
params: Record<string, string>;
|
|
11
|
+
}) => Response | Promise<Response>;
|
|
12
|
+
/** An imported `src/api/*.ts` module: named method exports and/or a default Web handler. */
|
|
13
|
+
export type RouteModule = Partial<Record<RouteMethod, RouteHandler>> & {
|
|
14
|
+
default?: unknown;
|
|
15
|
+
};
|
|
16
|
+
export interface CallRouteOptions {
|
|
17
|
+
/** Dynamic segments of the route (`[id]` -> `{ id: "7" }`). */
|
|
18
|
+
params?: Record<string, string>;
|
|
19
|
+
headers?: HeadersInit;
|
|
20
|
+
/** A JSON body; sets `content-type: application/json`. */
|
|
21
|
+
json?: unknown;
|
|
22
|
+
/** A raw body (string, FormData, ...). Ignored when `json` is set. */
|
|
23
|
+
body?: BodyInit | null;
|
|
24
|
+
/** The site base path, reported by request.nextUrl.basePath. */
|
|
25
|
+
basePath?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Calls a route module the way the server does: the named export for `method`
|
|
29
|
+
* (HEAD falls back to GET without a body, OPTIONS answers `Allow`), else a
|
|
30
|
+
* default Web-style handler, else a 405 with `Allow`. `target` is a path
|
|
31
|
+
* (`"/api/users/7?x=1"`), an absolute URL, or a ready `Request`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function callRoute(mod: RouteModule, method: RouteMethod, target: string | Request, options?: CallRouteOptions): Promise<Response>;
|
|
34
|
+
export interface ActionCallOptions {
|
|
35
|
+
/** Request headers the action sees through `headers()`. */
|
|
36
|
+
headers?: HeadersInit;
|
|
37
|
+
/** Cookies the request carried; the action reads them with `cookies()`. */
|
|
38
|
+
cookies?: Record<string, string>;
|
|
39
|
+
/** The page URL path the action was submitted from. */
|
|
40
|
+
url?: string;
|
|
41
|
+
/** The action id; only visible through `getActionContext()`. */
|
|
42
|
+
actionId?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface SetCookieCall {
|
|
45
|
+
name: string;
|
|
46
|
+
/** Empty string for a delete. */
|
|
47
|
+
value: string;
|
|
48
|
+
options?: Record<string, unknown>;
|
|
49
|
+
deleted: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface ActionCallResult<T> {
|
|
52
|
+
/** What the action returned. A thrown error (including `redirect()`) rejects instead. */
|
|
53
|
+
result: T;
|
|
54
|
+
/** Every `cookies().set()` / `delete()` call, in order. */
|
|
55
|
+
setCookies: SetCookieCall[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Runs a server action function with the request context a real call has, so
|
|
59
|
+
* `cookies()`, `headers()` and `getActionContext()` from `@krate/runtime/server`
|
|
60
|
+
* work. The action is the plain exported function you imported from the module.
|
|
61
|
+
*/
|
|
62
|
+
export declare function runAction<T>(action: () => T | Promise<T>, options?: ActionCallOptions): Promise<ActionCallResult<T>>;
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test helpers, exported from `@krate/runtime/testing`. They call an API route
|
|
3
|
+
* module or a server action in-process, without a running server. Node only
|
|
4
|
+
* (it uses AsyncLocalStorage); import it from your test files, never from app
|
|
5
|
+
* code.
|
|
6
|
+
*/
|
|
7
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
|
+
import { attachCookies } from "./request-extras.js";
|
|
9
|
+
const METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
|
|
10
|
+
/**
|
|
11
|
+
* Calls a route module the way the server does: the named export for `method`
|
|
12
|
+
* (HEAD falls back to GET without a body, OPTIONS answers `Allow`), else a
|
|
13
|
+
* default Web-style handler, else a 405 with `Allow`. `target` is a path
|
|
14
|
+
* (`"/api/users/7?x=1"`), an absolute URL, or a ready `Request`.
|
|
15
|
+
*/
|
|
16
|
+
export async function callRoute(mod, method, target, options = {}) {
|
|
17
|
+
// The server hands routes a Request with request.cookies and request.nextUrl.
|
|
18
|
+
const request = attachCookies(toRequest(method, target, options), options.basePath ?? "");
|
|
19
|
+
const context = { params: options.params ?? {} };
|
|
20
|
+
const named = (m) => (typeof mod[m] === "function" ? mod[m] : undefined);
|
|
21
|
+
const fallback = typeof mod.default === "function" ? mod.default : undefined;
|
|
22
|
+
if (fallback && fallback.length >= 2) {
|
|
23
|
+
throw new TypeError("callRoute: a default export with a (req, res) signature is the legacy Node style and is not supported; export named GET/POST handlers instead");
|
|
24
|
+
}
|
|
25
|
+
const direct = named(method);
|
|
26
|
+
if (direct)
|
|
27
|
+
return direct(request, context);
|
|
28
|
+
if (method === "HEAD" && named("GET")) {
|
|
29
|
+
const res = await named("GET")(request, context);
|
|
30
|
+
return new Response(null, { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
31
|
+
}
|
|
32
|
+
if (fallback && !METHODS.some((m) => named(m)))
|
|
33
|
+
return (await fallback(request, context));
|
|
34
|
+
const allow = METHODS.filter((m) => named(m) || (m === "HEAD" && named("GET")));
|
|
35
|
+
if (!allow.includes("OPTIONS"))
|
|
36
|
+
allow.push("OPTIONS");
|
|
37
|
+
if (method === "OPTIONS")
|
|
38
|
+
return new Response(null, { status: 204, headers: { Allow: allow.join(", ") } });
|
|
39
|
+
return new Response("Method Not Allowed", { status: 405, headers: { Allow: allow.join(", ") } });
|
|
40
|
+
}
|
|
41
|
+
function toRequest(method, target, options) {
|
|
42
|
+
if (typeof target !== "string")
|
|
43
|
+
return target;
|
|
44
|
+
const url = /^https?:\/\//i.test(target) ? target : "http://localhost" + (target.startsWith("/") ? target : "/" + target);
|
|
45
|
+
const headers = new Headers(options.headers);
|
|
46
|
+
let body = options.body;
|
|
47
|
+
if (options.json !== undefined) {
|
|
48
|
+
body = JSON.stringify(options.json);
|
|
49
|
+
if (!headers.has("content-type"))
|
|
50
|
+
headers.set("content-type", "application/json");
|
|
51
|
+
}
|
|
52
|
+
const hasBody = method !== "GET" && method !== "HEAD" && body !== undefined && body !== null;
|
|
53
|
+
return new Request(url, { method, headers, body: hasBody ? body : undefined });
|
|
54
|
+
}
|
|
55
|
+
const ACTION_STORE = Symbol.for("krate.action.store");
|
|
56
|
+
const als = new AsyncLocalStorage();
|
|
57
|
+
/**
|
|
58
|
+
* Runs a server action function with the request context a real call has, so
|
|
59
|
+
* `cookies()`, `headers()` and `getActionContext()` from `@krate/runtime/server`
|
|
60
|
+
* work. The action is the plain exported function you imported from the module.
|
|
61
|
+
*/
|
|
62
|
+
export async function runAction(action, options = {}) {
|
|
63
|
+
const jar = new Map(Object.entries(options.cookies ?? {}));
|
|
64
|
+
const setCookies = [];
|
|
65
|
+
const cookies = {
|
|
66
|
+
get: (name) => jar.get(name),
|
|
67
|
+
getAll: () => Array.from(jar, ([name, value]) => ({ name, value })),
|
|
68
|
+
has: (name) => jar.has(name),
|
|
69
|
+
set: (name, value, opts) => {
|
|
70
|
+
setCookies.push({ name, value: String(value), options: opts, deleted: false });
|
|
71
|
+
jar.set(name, String(value));
|
|
72
|
+
},
|
|
73
|
+
delete: (name, opts) => {
|
|
74
|
+
setCookies.push({ name, value: "", options: opts, deleted: true });
|
|
75
|
+
jar.delete(name);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
const context = {
|
|
79
|
+
actionId: options.actionId ?? "test-action",
|
|
80
|
+
url: options.url ?? "/",
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: new Headers(options.headers),
|
|
83
|
+
cookies,
|
|
84
|
+
};
|
|
85
|
+
// Published once and left in place: concurrent runAction calls share it, and
|
|
86
|
+
// each call's context lives in its own async scope.
|
|
87
|
+
globalThis[ACTION_STORE] = als;
|
|
88
|
+
const result = await als.run(context, async () => action());
|
|
89
|
+
return { result, setCookies };
|
|
90
|
+
}
|
package/dist/use-id.js
CHANGED
|
@@ -11,7 +11,7 @@ const encoder = typeof TextEncoder !== 'undefined' ? new TextEncoder() : null;
|
|
|
11
11
|
*/
|
|
12
12
|
function idSafe(s) {
|
|
13
13
|
return s.replace(/[^A-Za-z0-9_.:$-]/gu, (c) => {
|
|
14
|
-
const bytes = encoder ? Array.from(encoder.encode(c)) : [c.charCodeAt(0) &
|
|
14
|
+
const bytes = encoder ? Array.from(encoder.encode(c)) : [c.charCodeAt(0) & 0xFF];
|
|
15
15
|
return bytes.map((b) => '%' + b.toString(16).toUpperCase().padStart(2, '0')).join('');
|
|
16
16
|
});
|
|
17
17
|
}
|