@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/dom.d.ts
CHANGED
|
@@ -68,6 +68,10 @@ export interface KrateVNode {
|
|
|
68
68
|
tag: string;
|
|
69
69
|
props: Record<string, unknown> | null;
|
|
70
70
|
children: unknown[];
|
|
71
|
+
/** Effect owner current when h() ran: the component the element belongs to. */
|
|
72
|
+
o?: unknown;
|
|
73
|
+
/** Components this element is the root of; unmounted with the element. */
|
|
74
|
+
u?: unknown[];
|
|
71
75
|
}
|
|
72
76
|
/** A value that knows how to mount itself or adopt server-rendered DOM. */
|
|
73
77
|
export interface KrateAdoptable {
|
package/dist/dom.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createEffect, onCleanup } from './signal.js';
|
|
1
|
+
import { createEffect, onCleanup, krateGetOwner, krateSetOwner } from './signal.js';
|
|
2
2
|
import { krateWithOwner, krateUnmount } from './effects.js';
|
|
3
3
|
import { krateSanitizeAttr } from './slots.js';
|
|
4
4
|
import { krateOn, krateControl, krateSetControl } from './events.js';
|
|
5
5
|
import { krateAttachRef } from './refs.js';
|
|
6
|
+
import { withBase } from './base-path.js';
|
|
6
7
|
export { krateOn, krateControl, krateSetControl, krateSynthetic, krateEventRoot, krateEventName, krateMountFields, } from './events.js';
|
|
7
8
|
export { krateAttachRef, krateSetRef, krateRefsEnter, krateRefsLeave, krateRefsFlush, krateRefsHold } from './refs.js';
|
|
8
9
|
// per-node effect tracking
|
|
@@ -37,6 +38,16 @@ function trackOwner(value, owner) {
|
|
|
37
38
|
for (const v of value)
|
|
38
39
|
trackOwner(v, owner);
|
|
39
40
|
}
|
|
41
|
+
else if (isVNode(value)) {
|
|
42
|
+
// Not mounted yet: the unmount is registered on the element it becomes.
|
|
43
|
+
(value.u || (value.u = [])).push(owner);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Registers the unmounts of the components a vnode is the root of.
|
|
47
|
+
function trackVNodeOwners(v, el) {
|
|
48
|
+
if (v.u)
|
|
49
|
+
for (const o of v.u)
|
|
50
|
+
trackEffect(el, () => krateUnmount(o));
|
|
40
51
|
}
|
|
41
52
|
/**
|
|
42
53
|
* Binds the ref returned by `get` to `el` (hydration `ref={...}`). The ref is
|
|
@@ -126,7 +137,7 @@ export function insert(parent, value, startMarker) {
|
|
|
126
137
|
function insertBefore(parent, value, before) {
|
|
127
138
|
if (value == null || value === false || value === true)
|
|
128
139
|
return;
|
|
129
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
140
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint') {
|
|
130
141
|
parent.insertBefore(document.createTextNode(String(value)), before);
|
|
131
142
|
}
|
|
132
143
|
else if (value instanceof Node) {
|
|
@@ -197,7 +208,7 @@ export function krateApplyStyle(el, style) {
|
|
|
197
208
|
* accessor is not shadowed by the early own property.
|
|
198
209
|
*/
|
|
199
210
|
export function krateCustomProp(el, key, value) {
|
|
200
|
-
if (el.localName.indexOf('-') < 1 || key.
|
|
211
|
+
if (el.localName.indexOf('-') < 1 || key.includes('-'))
|
|
201
212
|
return false;
|
|
202
213
|
const complex = (typeof value === 'object' && value !== null) || typeof value === 'function';
|
|
203
214
|
if (!complex && !(key in el))
|
|
@@ -265,7 +276,9 @@ function setAttr(el, key, value) {
|
|
|
265
276
|
// aria-* and data-* stringify booleans (aria-selected={false} renders
|
|
266
277
|
// "false"), as in React.
|
|
267
278
|
const stringly = /^(aria|data)-/.test(name);
|
|
268
|
-
|
|
279
|
+
// A function (or symbol) is not an attribute value: React drops it rather
|
|
280
|
+
// than writing its source, e.g. a signal getter inside a spread object.
|
|
281
|
+
if (value === null || value === undefined || typeof value === 'function' || typeof value === 'symbol' || (value === false && !stringly)) {
|
|
269
282
|
if (el.hasAttribute(name))
|
|
270
283
|
el.removeAttribute(name);
|
|
271
284
|
}
|
|
@@ -276,9 +289,22 @@ function setAttr(el, key, value) {
|
|
|
276
289
|
}
|
|
277
290
|
}
|
|
278
291
|
}
|
|
292
|
+
/** A built-in <Link> lowers to these props; plain anchors are left as written. */
|
|
293
|
+
function isLinkProps(props) {
|
|
294
|
+
if ('data-krate-no-base' in props)
|
|
295
|
+
return false;
|
|
296
|
+
return 'data-krate-link' in props || 'data-krate-external' in props;
|
|
297
|
+
}
|
|
298
|
+
function linkHref(href) {
|
|
299
|
+
if (typeof href === 'string')
|
|
300
|
+
return withBase(href);
|
|
301
|
+
if (typeof href === 'function')
|
|
302
|
+
return () => linkHref(href());
|
|
303
|
+
return href;
|
|
304
|
+
}
|
|
279
305
|
function applyProps(el, props) {
|
|
280
306
|
for (const key in props) {
|
|
281
|
-
const value = props[key];
|
|
307
|
+
const value = key === 'href' && isLinkProps(props) ? linkHref(props[key]) : props[key];
|
|
282
308
|
if (typeof value === 'function' && (key === 'value' || key === 'checked')) {
|
|
283
309
|
trackEffect(el, krateControl(el, key, value));
|
|
284
310
|
}
|
|
@@ -311,7 +337,8 @@ export function krateSpread(el, get) {
|
|
|
311
337
|
if (key === 'children' || key === 'key' || key === 'dangerouslySetInnerHTML')
|
|
312
338
|
continue;
|
|
313
339
|
next.add(key);
|
|
314
|
-
|
|
340
|
+
const isLink = key === 'href' && (isLinkProps(props) || (el.hasAttribute('data-krate-link') && !('data-krate-no-base' in props)));
|
|
341
|
+
setAttr(el, key, isLink ? linkHref(props[key]) : props[key]);
|
|
315
342
|
}
|
|
316
343
|
const prev = spreadKeys.get(el);
|
|
317
344
|
if (prev) {
|
|
@@ -327,6 +354,20 @@ export function krateSpread(el, get) {
|
|
|
327
354
|
spreadKeys.set(el, next);
|
|
328
355
|
}));
|
|
329
356
|
}
|
|
357
|
+
// Runs fn with the vnode's component as the current effect owner, so the
|
|
358
|
+
// effects and components created when the vnode is adopted or materialized
|
|
359
|
+
// (later, outside the component's own call) are its children.
|
|
360
|
+
function withOwner(owner, fn) {
|
|
361
|
+
if (owner === undefined)
|
|
362
|
+
return fn();
|
|
363
|
+
const prev = krateSetOwner(owner);
|
|
364
|
+
try {
|
|
365
|
+
return fn();
|
|
366
|
+
}
|
|
367
|
+
finally {
|
|
368
|
+
krateSetOwner(prev);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
330
371
|
let vnodeDepth = 0;
|
|
331
372
|
/** Evaluate `fn` with h() producing virtual nodes (see KrateVNode). */
|
|
332
373
|
export function withVNodes(fn) {
|
|
@@ -402,7 +443,9 @@ function buildElement(tag, props, children) {
|
|
|
402
443
|
return el;
|
|
403
444
|
}
|
|
404
445
|
function materialize(v) {
|
|
405
|
-
|
|
446
|
+
const el = withOwner(v.o, () => withDOM(() => buildElement(v.tag, v.props, v.children)));
|
|
447
|
+
trackVNodeOwners(v, el);
|
|
448
|
+
return el;
|
|
406
449
|
}
|
|
407
450
|
function isTextLike(v) {
|
|
408
451
|
return v == null || typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean' || typeof v === 'bigint';
|
|
@@ -558,14 +601,17 @@ function adoptElement(v, c) {
|
|
|
558
601
|
if (n && n.nodeType === 1 && n.localName.toLowerCase() === v.tag.toLowerCase()) {
|
|
559
602
|
c.next = n.nextSibling;
|
|
560
603
|
const el = n;
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
604
|
+
trackVNodeOwners(v, el);
|
|
605
|
+
withOwner(v.o, () => {
|
|
606
|
+
if (v.props)
|
|
607
|
+
applyProps(el, v.props);
|
|
608
|
+
if (!v.props || !v.props.dangerouslySetInnerHTML) {
|
|
609
|
+
const inner = { parent: el, next: el.firstChild };
|
|
610
|
+
for (const child of v.children)
|
|
611
|
+
adoptValue(child, inner);
|
|
612
|
+
removeRest(inner, null);
|
|
613
|
+
}
|
|
614
|
+
});
|
|
569
615
|
return;
|
|
570
616
|
}
|
|
571
617
|
insertAt(c, materialize(v));
|
|
@@ -633,7 +679,7 @@ export function h(tag, props, ...children) {
|
|
|
633
679
|
return value;
|
|
634
680
|
}
|
|
635
681
|
if (vnodeDepth > 0) {
|
|
636
|
-
return { __kv: 1, tag, props, children };
|
|
682
|
+
return { __kv: 1, tag, props, children, o: krateGetOwner() };
|
|
637
683
|
}
|
|
638
684
|
return buildElement(tag, props, children);
|
|
639
685
|
}
|
package/dist/effects.js
CHANGED
|
@@ -144,7 +144,7 @@ export function krateUnmount(value) {
|
|
|
144
144
|
if (owner.parent) {
|
|
145
145
|
const list = owner.parent.children;
|
|
146
146
|
const i = list.indexOf(owner);
|
|
147
|
-
if (i
|
|
147
|
+
if (i !== -1)
|
|
148
148
|
list.splice(i, 1);
|
|
149
149
|
}
|
|
150
150
|
if (passive.length) {
|
|
@@ -169,7 +169,7 @@ function disposeTree(owner, active, passive) {
|
|
|
169
169
|
continue;
|
|
170
170
|
}
|
|
171
171
|
if (hook.phase === 'passive') {
|
|
172
|
-
const c =
|
|
172
|
+
const c = takePassiveCleanup(hook);
|
|
173
173
|
if (c)
|
|
174
174
|
passive.push(c);
|
|
175
175
|
}
|
|
@@ -320,7 +320,7 @@ function hideTree(owner, passive) {
|
|
|
320
320
|
for (const hook of owner.hooks) {
|
|
321
321
|
dirty.delete(hook);
|
|
322
322
|
if (hook.phase === 'passive') {
|
|
323
|
-
const c =
|
|
323
|
+
const c = takePassiveCleanup(hook);
|
|
324
324
|
if (c)
|
|
325
325
|
passive.push(c);
|
|
326
326
|
}
|
|
@@ -485,6 +485,12 @@ function runCleanup(hook) {
|
|
|
485
485
|
if (c)
|
|
486
486
|
runGuarded(c, hook.owner);
|
|
487
487
|
}
|
|
488
|
+
// A passive cleanup detached for the passive phase; its errors go to the
|
|
489
|
+
// owner's error boundary like a layout cleanup's.
|
|
490
|
+
function takePassiveCleanup(hook) {
|
|
491
|
+
const c = takeCleanup(hook);
|
|
492
|
+
return c ? () => runGuarded(c, hook.owner) : null;
|
|
493
|
+
}
|
|
488
494
|
function pruneSnapshots() {
|
|
489
495
|
let min = krateEpoch();
|
|
490
496
|
for (const e of liveEpochs.keys())
|
|
@@ -571,7 +577,7 @@ function commit() {
|
|
|
571
577
|
for (const h of hooks) {
|
|
572
578
|
if (h.phase !== 'passive')
|
|
573
579
|
continue;
|
|
574
|
-
const c =
|
|
580
|
+
const c = takePassiveCleanup(h);
|
|
575
581
|
if (c)
|
|
576
582
|
passiveCleanups.push(c);
|
|
577
583
|
passiveSetups.push([h, at]);
|
|
@@ -600,6 +606,17 @@ export function flushPassive() {
|
|
|
600
606
|
clearTimeout(passiveTimer);
|
|
601
607
|
passiveTimer = null;
|
|
602
608
|
}
|
|
609
|
+
let failed = false;
|
|
610
|
+
let first;
|
|
611
|
+
const remember = (err) => {
|
|
612
|
+
if (!failed) {
|
|
613
|
+
failed = true;
|
|
614
|
+
first = err;
|
|
615
|
+
}
|
|
616
|
+
else if (typeof console !== 'undefined') {
|
|
617
|
+
console.error(err);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
603
620
|
// Loop: a passive cleanup or setup may unmount components, queueing more.
|
|
604
621
|
while (passiveCleanups.length || passiveSetups.length) {
|
|
605
622
|
const cleanups = passiveCleanups;
|
|
@@ -607,18 +624,34 @@ export function flushPassive() {
|
|
|
607
624
|
passiveCleanups = [];
|
|
608
625
|
passiveSetups = [];
|
|
609
626
|
krateCommitting(true);
|
|
627
|
+
// An error with no boundary to take it must not drop the cleanups and
|
|
628
|
+
// setups queued behind it: run them all, then rethrow the first.
|
|
610
629
|
try {
|
|
611
|
-
for (const c of cleanups)
|
|
612
|
-
|
|
630
|
+
for (const c of cleanups) {
|
|
631
|
+
try {
|
|
632
|
+
c();
|
|
633
|
+
}
|
|
634
|
+
catch (err) {
|
|
635
|
+
remember(err);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
613
638
|
for (const [h, at] of setups) {
|
|
614
|
-
if (isActive(h.owner))
|
|
639
|
+
if (!isActive(h.owner))
|
|
640
|
+
continue;
|
|
641
|
+
try {
|
|
615
642
|
runSetup(h, at);
|
|
643
|
+
}
|
|
644
|
+
catch (err) {
|
|
645
|
+
remember(err);
|
|
646
|
+
}
|
|
616
647
|
}
|
|
617
648
|
}
|
|
618
649
|
finally {
|
|
619
650
|
krateCommitting(false);
|
|
620
651
|
}
|
|
621
652
|
}
|
|
653
|
+
if (failed)
|
|
654
|
+
throw first;
|
|
622
655
|
}
|
|
623
656
|
/**
|
|
624
657
|
* React's useMemo with a dependency array: the getter recomputes
|
|
@@ -700,7 +733,7 @@ function unmountExcept(gone) {
|
|
|
700
733
|
continue;
|
|
701
734
|
disposeTree(child, child.shown, passive);
|
|
702
735
|
const i = root.children.indexOf(child);
|
|
703
|
-
if (i
|
|
736
|
+
if (i !== -1)
|
|
704
737
|
root.children.splice(i, 1);
|
|
705
738
|
}
|
|
706
739
|
const keptHooks = [];
|
|
@@ -712,7 +745,7 @@ function unmountExcept(gone) {
|
|
|
712
745
|
hook.stop();
|
|
713
746
|
dirty.delete(hook);
|
|
714
747
|
if (hook.phase === 'passive') {
|
|
715
|
-
const c =
|
|
748
|
+
const c = takePassiveCleanup(hook);
|
|
716
749
|
if (c)
|
|
717
750
|
passive.push(c);
|
|
718
751
|
}
|
|
@@ -764,7 +797,7 @@ function unmountAll(gone) {
|
|
|
764
797
|
for (const hook of root.hooks) {
|
|
765
798
|
hook.stop();
|
|
766
799
|
if (hook.phase === 'passive') {
|
|
767
|
-
const c =
|
|
800
|
+
const c = takePassiveCleanup(hook);
|
|
768
801
|
if (c)
|
|
769
802
|
passive.push(c);
|
|
770
803
|
}
|
package/dist/events.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export declare function krateSynthetic<E extends Event>(native: E, type?: string
|
|
|
26
26
|
* to on it.
|
|
27
27
|
*/
|
|
28
28
|
export declare function krateEventRoot(node: Node): void;
|
|
29
|
+
/** Runs fn with delegated and direct handlers silenced (internal). */
|
|
30
|
+
export declare function krateMuteEvents<T>(fn: () => T): T;
|
|
29
31
|
/** Splits a React prop (`onClickCapture`) into its event name and phase. */
|
|
30
32
|
export declare function krateEventName(prop: string): [name: string, capture: boolean];
|
|
31
33
|
/**
|
package/dist/events.js
CHANGED
|
@@ -187,7 +187,23 @@ function onRootCapture(native) {
|
|
|
187
187
|
function onRootBubble(native) {
|
|
188
188
|
dispatchRoot(native, false);
|
|
189
189
|
}
|
|
190
|
+
// React turns its event system off while it commits: the blur and focus a
|
|
191
|
+
// browser fires when a focused node is moved or removed must not reach
|
|
192
|
+
// handlers. Keyed list updates run their DOM moves inside this.
|
|
193
|
+
let muted = 0;
|
|
194
|
+
/** Runs fn with delegated and direct handlers silenced (internal). */
|
|
195
|
+
export function krateMuteEvents(fn) {
|
|
196
|
+
muted++;
|
|
197
|
+
try {
|
|
198
|
+
return fn();
|
|
199
|
+
}
|
|
200
|
+
finally {
|
|
201
|
+
muted--;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
190
204
|
function dispatchRoot(native, capture) {
|
|
205
|
+
if (muted > 0)
|
|
206
|
+
return;
|
|
191
207
|
// Several roots can be on the path (a portal inside the root); the first
|
|
192
208
|
// listener to see the event handles the whole path.
|
|
193
209
|
const flag = capture ? '__kdc' : '__kdb';
|
|
@@ -219,6 +235,8 @@ function onDirectCapture(native) {
|
|
|
219
235
|
directDispatch(this, native, true);
|
|
220
236
|
}
|
|
221
237
|
function directDispatch(el, native, capture) {
|
|
238
|
+
if (muted > 0)
|
|
239
|
+
return;
|
|
222
240
|
const m = el.__kh;
|
|
223
241
|
const h = m && m[native.type + (capture ? '$' : '')];
|
|
224
242
|
if (!h)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type FlightHooks = {
|
|
2
|
+
isAction(v: unknown): string | undefined;
|
|
3
|
+
isJSX(v: unknown): boolean;
|
|
4
|
+
fail(path: string, what: string, hint?: string): Error;
|
|
5
|
+
};
|
|
6
|
+
export declare function describeValue(v: unknown): string;
|
|
7
|
+
export declare function encodeProp(v: unknown, path: string, hooks: FlightHooks): unknown;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Encoding of plain-data props crossing from a server component to a client
|
|
2
|
+
// component, in the spirit of React Flight. JSON carries strings, finite
|
|
3
|
+
// numbers, booleans, null, arrays and plain objects as themselves; every other
|
|
4
|
+
// supported value becomes a tagged object { __krateT: <tag>, v: <payload> }
|
|
5
|
+
// that the client reviver (clientReviveJS in the compiler) turns back into the
|
|
6
|
+
// real value. A plain object that could be mistaken for a tag or a marker is
|
|
7
|
+
// wrapped in an "O" tag so user data can never collide with the encoding.
|
|
8
|
+
const RESERVED = ["__krateT", "__krateAction", "__krateSlotHTML", "__krateSlotTree", "__krateChildren", "__krateTree"];
|
|
9
|
+
const TYPED_ARRAYS = {
|
|
10
|
+
Int8Array: true, Uint8Array: true, Uint8ClampedArray: true, Int16Array: true, Uint16Array: true,
|
|
11
|
+
Int32Array: true, Uint32Array: true, Float32Array: true, Float64Array: true, BigInt64Array: true, BigUint64Array: true,
|
|
12
|
+
};
|
|
13
|
+
function tag(t, v) {
|
|
14
|
+
return v === undefined ? { __krateT: t } : { __krateT: t, v };
|
|
15
|
+
}
|
|
16
|
+
function toBase64(bytes) {
|
|
17
|
+
let s = "";
|
|
18
|
+
for (let i = 0; i < bytes.length; i += 0x8000)
|
|
19
|
+
s += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
|
|
20
|
+
return btoa(s);
|
|
21
|
+
}
|
|
22
|
+
function bytesOf(buf, off = 0, len = buf.byteLength - off) {
|
|
23
|
+
return toBase64(new Uint8Array(buf, off, len));
|
|
24
|
+
}
|
|
25
|
+
export function describeValue(v) {
|
|
26
|
+
if (typeof v === "function")
|
|
27
|
+
return "a function";
|
|
28
|
+
if (typeof v === "symbol")
|
|
29
|
+
return "a symbol that is not registered with Symbol.for";
|
|
30
|
+
if (v && typeof v === "object") {
|
|
31
|
+
const ctor = Object.getPrototypeOf(v)?.constructor?.name;
|
|
32
|
+
return ctor ? `an instance of ${ctor}` : "a non-plain object";
|
|
33
|
+
}
|
|
34
|
+
return typeof v;
|
|
35
|
+
}
|
|
36
|
+
// encodeProp converts one prop value. A top-level undefined is dropped by the
|
|
37
|
+
// caller (an absent prop); nested ones are kept as an "U" tag.
|
|
38
|
+
export function encodeProp(v, path, hooks) {
|
|
39
|
+
if (v === null || typeof v === "string" || typeof v === "boolean")
|
|
40
|
+
return v;
|
|
41
|
+
if (typeof v === "number") {
|
|
42
|
+
if (Object.is(v, -0))
|
|
43
|
+
return tag("N", "-0");
|
|
44
|
+
if (Number.isNaN(v))
|
|
45
|
+
return tag("N", "NaN");
|
|
46
|
+
if (v === Infinity)
|
|
47
|
+
return tag("N", "Infinity");
|
|
48
|
+
if (v === -Infinity)
|
|
49
|
+
return tag("N", "-Infinity");
|
|
50
|
+
return v;
|
|
51
|
+
}
|
|
52
|
+
if (typeof v === "bigint")
|
|
53
|
+
return tag("B", v.toString());
|
|
54
|
+
if (v === undefined)
|
|
55
|
+
return tag("U");
|
|
56
|
+
if (typeof v === "symbol") {
|
|
57
|
+
const key = Symbol.keyFor(v);
|
|
58
|
+
if (key === undefined)
|
|
59
|
+
throw hooks.fail(path, describeValue(v));
|
|
60
|
+
return tag("Y", key);
|
|
61
|
+
}
|
|
62
|
+
const action = hooks.isAction(v);
|
|
63
|
+
if (action !== undefined)
|
|
64
|
+
return { __krateAction: action };
|
|
65
|
+
if (Array.isArray(v))
|
|
66
|
+
return v.map((x, i) => encodeProp(x, `${path}[${i}]`, hooks));
|
|
67
|
+
if (typeof v === "object") {
|
|
68
|
+
if (hooks.isJSX(v)) {
|
|
69
|
+
throw hooks.fail(path, "JSX", "pass JSX as a prop value, an array of JSX, or as children; JSX nested inside an object cannot be sent to a client component");
|
|
70
|
+
}
|
|
71
|
+
const proto = Object.getPrototypeOf(v);
|
|
72
|
+
if (proto === Date.prototype) {
|
|
73
|
+
const t = v.getTime();
|
|
74
|
+
return tag("D", Number.isNaN(t) ? null : t);
|
|
75
|
+
}
|
|
76
|
+
if (proto === Map.prototype) {
|
|
77
|
+
const entries = [];
|
|
78
|
+
let i = 0;
|
|
79
|
+
for (const [k, x] of v) {
|
|
80
|
+
entries.push([encodeProp(k, `${path}.keys[${i}]`, hooks), encodeProp(x, `${path}.get(${i})`, hooks)]);
|
|
81
|
+
i++;
|
|
82
|
+
}
|
|
83
|
+
return tag("M", entries);
|
|
84
|
+
}
|
|
85
|
+
if (proto === Set.prototype) {
|
|
86
|
+
return tag("S", [...v].map((x, i) => encodeProp(x, `${path}.values[${i}]`, hooks)));
|
|
87
|
+
}
|
|
88
|
+
if (proto === ArrayBuffer.prototype)
|
|
89
|
+
return tag("A", bytesOf(v));
|
|
90
|
+
if (ArrayBuffer.isView(v)) {
|
|
91
|
+
if (v instanceof DataView)
|
|
92
|
+
return tag("V", bytesOf(v.buffer, v.byteOffset, v.byteLength));
|
|
93
|
+
const name = v[Symbol.toStringTag];
|
|
94
|
+
if (TYPED_ARRAYS[name])
|
|
95
|
+
return tag("T", { n: name, b: bytesOf(v.buffer, v.byteOffset, v.byteLength) });
|
|
96
|
+
}
|
|
97
|
+
if (proto !== Object.prototype && proto !== null)
|
|
98
|
+
throw hooks.fail(path, describeValue(v));
|
|
99
|
+
const out = {};
|
|
100
|
+
for (const [k, x] of Object.entries(v))
|
|
101
|
+
out[k] = encodeProp(x, `${path}.${k}`, hooks);
|
|
102
|
+
return RESERVED.some((k) => Object.prototype.hasOwnProperty.call(out, k)) ? tag("O", out) : out;
|
|
103
|
+
}
|
|
104
|
+
throw hooks.fail(path, describeValue(v));
|
|
105
|
+
}
|
package/dist/handler-html.js
CHANGED
|
@@ -19,7 +19,7 @@ export function parseRegionShell(shell) {
|
|
|
19
19
|
const id = o[2];
|
|
20
20
|
const openEnd = o.index + o[0].length;
|
|
21
21
|
const rel = shell.indexOf("<!--/" + kind + ":" + id + "-->", openEnd);
|
|
22
|
-
if (rel
|
|
22
|
+
if (rel === -1) {
|
|
23
23
|
e.ok = false;
|
|
24
24
|
e.roots = [];
|
|
25
25
|
e.all = [];
|
|
@@ -50,13 +50,13 @@ export function allSuspense(all) {
|
|
|
50
50
|
export function splitBodyScripts(shell) {
|
|
51
51
|
const lower = shell.toLowerCase();
|
|
52
52
|
const body = lower.indexOf("<body");
|
|
53
|
-
if (body
|
|
53
|
+
if (body !== -1) {
|
|
54
54
|
const rel = lower.indexOf("<script", body);
|
|
55
|
-
if (rel
|
|
55
|
+
if (rel !== -1)
|
|
56
56
|
return [shell.slice(0, rel), shell.slice(rel)];
|
|
57
57
|
}
|
|
58
58
|
const at = lower.lastIndexOf("</body>");
|
|
59
|
-
if (at
|
|
59
|
+
if (at !== -1)
|
|
60
60
|
return [shell.slice(0, at), shell.slice(at)];
|
|
61
61
|
return [shell, ""];
|
|
62
62
|
}
|
|
@@ -37,29 +37,6 @@ export declare function isInternalOutputPath(urlPath: string): boolean;
|
|
|
37
37
|
export declare function isHiddenName(name: string): boolean;
|
|
38
38
|
/** True when any segment of a (decoded) URL path is a dotfile name. */
|
|
39
39
|
export declare function isHiddenPath(urlPath: string): boolean;
|
|
40
|
-
export interface RuleMatch {
|
|
41
|
-
params: Record<string, string>;
|
|
42
|
-
mods: Record<string, string>;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Matches a request path against a redirect/rewrite source: exact, a trailing
|
|
46
|
-
* "/*" wildcard (param "splat"), or named segments with the "*", "+" and "?"
|
|
47
|
-
* modifiers.
|
|
48
|
-
*/
|
|
49
|
-
export declare function matchRedirectParamsMods(path: string, source: string): RuleMatch | null;
|
|
50
|
-
export declare function matchRedirect(path: string, source: string): boolean;
|
|
51
|
-
/** url.PathEscape of Go: segment-escapes everything but unreserved and $&+=:@. */
|
|
52
|
-
export declare function pathEscape(s: string): string;
|
|
53
|
-
/** Percent-encodes a matched (decoded) value segment by segment, keeping "/" between segments. */
|
|
54
|
-
export declare function escapeRedirectValue(v: string): string;
|
|
55
|
-
/** Keeps a substituted path destination on-site (no "//host" or "/\\host" results). */
|
|
56
|
-
export declare function sanitizeRedirectTarget(configured: string, out: string): string;
|
|
57
|
-
/** Fills ":splat" and ":name" placeholders of a destination from the matched path. */
|
|
58
|
-
export declare function rewriteDestination(path: string, source: string, destination: string): string;
|
|
59
|
-
/** path.Match for slash paths: "*" and "?" do not cross "/", "[...]" classes. */
|
|
60
|
-
export declare function pathMatch(pattern: string, name: string): boolean;
|
|
61
|
-
/** Exact path, trailing "*" prefix, or path.Match glob (config `headers[].source`). */
|
|
62
|
-
export declare function headerSourceMatches(pattern: string, p: string): boolean;
|
|
63
40
|
export declare const DYNAMIC_PARAM_PREFIX = "__KRATE_PARAM_";
|
|
64
41
|
export declare function dynamicParamSentinel(name: string): string;
|
|
65
42
|
/** Go's html.EscapeString (used for dynamic template params). */
|
|
@@ -73,6 +50,8 @@ export declare function escapeHTML(s: string): string;
|
|
|
73
50
|
export declare function applyDynamicRouteParams(templateHTML: string, params: Record<string, string>): string;
|
|
74
51
|
/** json.Marshal of a string map: sorted keys, HTML-significant characters escaped. */
|
|
75
52
|
export declare function goJSON(obj: Record<string, string>): string;
|
|
53
|
+
/** Cache-Control of a content-hashed asset; a user headers rule never replaces it. */
|
|
54
|
+
export declare const IMMUTABLE_CACHE_CONTROL = "public, max-age=31536000, immutable";
|
|
76
55
|
export declare function staticCacheControl(urlPath: string, hashed: ReadonlySet<string>): string;
|
|
77
56
|
export declare function compileMatcher(src: unknown): RegExp;
|
|
78
57
|
/**
|