@krate/runtime 0.5.0-rc.1 → 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 +470 -77
- package/dist/dom.js +18 -3
- package/dist/effects.js +2 -2
- 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 +385 -66
- 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 +454 -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/list.d.ts +14 -4
- package/dist/list.js +4 -5
- 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 +628 -98
- 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 +0 -6
- 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/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 -165
- 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 -39
- package/dist/effect-errors.test.d.ts +0 -1
- package/dist/effect-errors.test.js +0 -199
- 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 -435
- 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 -125
- 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 -133
- 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 -559
- 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 -187
- 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 -556
package/dist/server-renderer.js
CHANGED
|
@@ -9,6 +9,7 @@ import { pathToFileURL } from "node:url";
|
|
|
9
9
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
10
|
import { createHash, timingSafeEqual } from "node:crypto";
|
|
11
11
|
import { createSSRCore, MemoryIsrStore, } from "./ssr-core.js";
|
|
12
|
+
import { encodeFrame, REGION_FRAMES_TYPE, wantsRegionFrames } from "./region-wire.js";
|
|
12
13
|
import { installRenderStore, patchFetch } from "./cache-scope.js";
|
|
13
14
|
import { cacheSpecFromEnv } from "./cache-adapter.js";
|
|
14
15
|
import { isrStoreFor } from "./shared-isr.js";
|
|
@@ -245,7 +246,7 @@ const { findPage, renderPage, renderRegion, renderPageRegion } = core;
|
|
|
245
246
|
// ISR cache persistence - survives renderer restarts so a bounce doesn't
|
|
246
247
|
// cold-render every ISR variant. Written debounced (coalesced) to the build
|
|
247
248
|
// output dir (.krate/isr-cache.json), overridable via KRATE_ISR_CACHE.
|
|
248
|
-
|
|
249
|
+
const isrCacheFile = process.env.KRATE_ISR_CACHE || "";
|
|
249
250
|
let persistTimer = null;
|
|
250
251
|
function isrCachePath() {
|
|
251
252
|
return isrCacheFile || path.join(OUT_DIR, ".krate", "isr-cache.json");
|
|
@@ -320,6 +321,13 @@ async function applyInternalOp(op, payload) {
|
|
|
320
321
|
function writeJsonLine(res, obj) {
|
|
321
322
|
res.write(JSON.stringify(obj) + "\n");
|
|
322
323
|
}
|
|
324
|
+
// writeFrame writes one region frame in the format the client asked for.
|
|
325
|
+
function writeFrame(res, binary, frame) {
|
|
326
|
+
if (binary)
|
|
327
|
+
res.write(encodeFrame(frame));
|
|
328
|
+
else
|
|
329
|
+
writeJsonLine(res, frame);
|
|
330
|
+
}
|
|
323
331
|
// Cluster fan-out (worker side). broadcastInternalOp resolves with one result
|
|
324
332
|
// per live worker once every worker applied the operation.
|
|
325
333
|
let broadcastSeq = 0;
|
|
@@ -430,8 +438,9 @@ const server = http.createServer(async (req, res) => {
|
|
|
430
438
|
res.end(JSON.stringify({ error: "forbidden" }));
|
|
431
439
|
return;
|
|
432
440
|
}
|
|
441
|
+
const binary = wantsRegionFrames(req.headers.accept);
|
|
433
442
|
res.writeHead(200, {
|
|
434
|
-
"Content-Type": "application/x-ndjson; charset=utf-8",
|
|
443
|
+
"Content-Type": binary ? REGION_FRAMES_TYPE : "application/x-ndjson; charset=utf-8",
|
|
435
444
|
"Cache-Control": "no-store",
|
|
436
445
|
"X-Content-Type-Options": "nosniff",
|
|
437
446
|
});
|
|
@@ -450,8 +459,8 @@ const server = http.createServer(async (req, res) => {
|
|
|
450
459
|
};
|
|
451
460
|
const page = findPage(renderReq.route);
|
|
452
461
|
if (!page) {
|
|
453
|
-
|
|
454
|
-
|
|
462
|
+
writeFrame(res, binary, { type: "error", status: 404, error: "no such page" });
|
|
463
|
+
writeFrame(res, binary, { type: "end", count: 0 });
|
|
455
464
|
res.end();
|
|
456
465
|
return;
|
|
457
466
|
}
|
|
@@ -474,12 +483,12 @@ const server = http.createServer(async (req, res) => {
|
|
|
474
483
|
});
|
|
475
484
|
// Write each frame as soon as it resolves. Async server components finish
|
|
476
485
|
// out of document order, and the Go host inserts each chunk at its marker.
|
|
477
|
-
await Promise.all(pending.map(async (p) =>
|
|
478
|
-
|
|
486
|
+
await Promise.all(pending.map(async (p) => writeFrame(res, binary, await p)));
|
|
487
|
+
writeFrame(res, binary, { type: "end", count: regions.length });
|
|
479
488
|
}
|
|
480
489
|
catch (err) {
|
|
481
490
|
console.error("[krate-ssr] Error in /__krate/regions:", err.message);
|
|
482
|
-
|
|
491
|
+
writeFrame(res, binary, { type: "error", status: 500, error: err.message });
|
|
483
492
|
}
|
|
484
493
|
res.end();
|
|
485
494
|
return;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export { getActionContext, headers, cookies, redirect } from './action-context.js';
|
|
2
2
|
export type { ActionContext, ActionCookies, ActionCookieOptions } from './action-context.js';
|
|
3
3
|
export { revalidatePath, revalidateTag, unstable_cache, unstable_noStore } from './cache.js';
|
|
4
|
+
export { after } from './after.js';
|
|
5
|
+
export { getPlatform, getCloudflareContext } from './platform.js';
|
|
6
|
+
export type { PlatformContext, PlatformTarget, PlatformExecutionContext, CloudflareContext, KrateCloudflareEnv } from './platform.js';
|
|
7
|
+
export type { AfterTask, KrateRequest, KrateRequestCookies, KrateNextURL } from './after.js';
|
|
4
8
|
export type { RevalidatePathType, UnstableCacheOptions } from './cache.js';
|
|
5
9
|
export { getRequestContext, notFound, forbidden, unauthorized } from './request-context.js';
|
|
6
10
|
export { usePathname, useSearchParams, useParams, useRouter, useSelectedLayoutSegment, useSelectedLayoutSegments, permanentRedirect, } from './navigation-server.js';
|
|
@@ -26,15 +30,45 @@ interface RawHTML {
|
|
|
26
30
|
export declare function goComponent(name: string, tier: string, baked: Record<string, string> | null | undefined, props: Record<string, any> | undefined, revalidate?: number): JSXNode;
|
|
27
31
|
type JSXNode = string | number | boolean | null | undefined | JSXNode[] | JSXElement | RawHTML;
|
|
28
32
|
interface JSXElement {
|
|
29
|
-
type: string | Function;
|
|
33
|
+
type: string | Function | object | symbol;
|
|
30
34
|
props: Record<string, any>;
|
|
31
35
|
children: JSXNode[];
|
|
32
36
|
}
|
|
33
37
|
export declare function Fragment(_props: {
|
|
34
38
|
children?: JSXNode;
|
|
35
39
|
}): JSXNode;
|
|
36
|
-
export declare function jsx(type: string | Function, props: Record<string, any>, _key?: string): JSXElement;
|
|
40
|
+
export declare function jsx(type: string | Function | object | symbol, props: Record<string, any>, _key?: string): JSXElement;
|
|
37
41
|
export declare const jsxs: typeof jsx;
|
|
42
|
+
/**
|
|
43
|
+
* ServerErrorBoundary is the request-time form of a segment's error.tsx under
|
|
44
|
+
* an async layout: it renders `children`, and when rendering them throws it
|
|
45
|
+
* renders `<fallback error={{ name, message, digest }} />` in their place.
|
|
46
|
+
* notFound(), forbidden(), unauthorized() and redirect() signals pass through.
|
|
47
|
+
* The visitor sees a generic message and a digest; the real error is logged
|
|
48
|
+
* with the same digest. The render's scope records the catch, so the host
|
|
49
|
+
* answers 500 with no-store instead of a cacheable 200.
|
|
50
|
+
*/
|
|
51
|
+
export declare class ServerErrorBoundary {
|
|
52
|
+
props: {
|
|
53
|
+
fallback: any;
|
|
54
|
+
children?: JSXNode;
|
|
55
|
+
};
|
|
56
|
+
state: {
|
|
57
|
+
error: unknown;
|
|
58
|
+
};
|
|
59
|
+
constructor(props: {
|
|
60
|
+
fallback: any;
|
|
61
|
+
children?: JSXNode;
|
|
62
|
+
});
|
|
63
|
+
static getDerivedStateFromError(error: unknown): {
|
|
64
|
+
error: {
|
|
65
|
+
name: string;
|
|
66
|
+
message: string;
|
|
67
|
+
digest: string;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
render(): JSXNode;
|
|
71
|
+
}
|
|
38
72
|
export declare function renderToString(node: JSXNode): string;
|
|
39
73
|
/**
|
|
40
74
|
* renderToStringAsync renders a tree that may contain async (server)
|
|
@@ -53,27 +87,50 @@ interface SuspenseProps {
|
|
|
53
87
|
children: JSXNode;
|
|
54
88
|
}
|
|
55
89
|
export declare function Suspense(props: SuspenseProps): JSXNode;
|
|
56
|
-
type ClientRender = (component: unknown, props: Record<string, unknown>, childrenHTML: string | null) => string;
|
|
57
90
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* serialized props; the per-module client chunk at src hydrates it in the
|
|
62
|
-
* browser. Children are rendered on the server and passed as HTML.
|
|
91
|
+
* lazy() in a server tree: the loader's module is imported while the page
|
|
92
|
+
* renders and its component renders in place. Nothing is code-split to the
|
|
93
|
+
* browser, so a server-only module can be loaded this way.
|
|
63
94
|
*/
|
|
64
|
-
export declare function
|
|
95
|
+
export declare function lazy<P = Record<string, any>>(loader: () => Promise<{
|
|
96
|
+
default: (props: P) => unknown;
|
|
97
|
+
} | ((props: P) => unknown)>): (props: P & {
|
|
98
|
+
children?: JSXNode;
|
|
99
|
+
}) => Promise<JSXNode>;
|
|
100
|
+
type ClientRender = (component: unknown, props: Record<string, unknown>, childrenHTML: string | null, fwd?: SlotValues, capture?: Record<string, SlotValues>) => string;
|
|
101
|
+
type SlotValues = {
|
|
102
|
+
k: string;
|
|
103
|
+
v: unknown;
|
|
104
|
+
}[];
|
|
105
|
+
export declare const ISLAND_OPEN = "krate-island:";
|
|
106
|
+
export declare const ISLAND_CLOSE = "<!--/krate-island-->";
|
|
107
|
+
/**
|
|
108
|
+
* clientBoundary wraps an export of a `"use client"` module, or a component
|
|
109
|
+
* of a React package, for the server bundle of a page that renders server
|
|
110
|
+
* components. The server renders the component's initial HTML (render) and,
|
|
111
|
+
* when it hydrates, puts it between <!--krate-island:{...}--> (module,
|
|
112
|
+
* export, chunk and serialized props) and <!--/krate-island--> with no
|
|
113
|
+
* element around it; the per-module client chunk at src hydrates those nodes
|
|
114
|
+
* in the browser. A real-React island (flight) gets a <krate-island> element
|
|
115
|
+
* instead, preceded by a JSON script with its props, because createRoot needs
|
|
116
|
+
* a container. A component without state or effects (hydrate
|
|
117
|
+
* false, an icon) is plain HTML. Children are rendered on the server into the
|
|
118
|
+
* component's HTML and adopted there by the browser (see DeferredSlot), or,
|
|
119
|
+
* when they hold client components of their own, sent as a tree that keeps
|
|
120
|
+
* those components in the same Preact tree. The children of an asChild component
|
|
121
|
+
* always travel as a tree, with a server component at the top of a child run
|
|
122
|
+
* to the element it renders, so the component's Slot can clone it. A
|
|
123
|
+
* namespace export (Radix's Dialog) is wrapped member by member. With `flight` the children always travel as a
|
|
124
|
+
* tree (a real-React island rebuilds them as elements, not HTML).
|
|
125
|
+
*/
|
|
126
|
+
export declare function clientBoundary(moduleId: string, exportName: string, src: string, impl: unknown, render: ClientRender, hydrate?: boolean, flight?: boolean): unknown;
|
|
65
127
|
export declare const HEAD_OPEN = "<!--krate-head-->";
|
|
66
128
|
export declare const HEAD_CLOSE = "<!--/krate-head-->";
|
|
67
129
|
export declare function Head(props: {
|
|
68
130
|
children?: JSXNode;
|
|
69
131
|
}): JSXNode;
|
|
70
|
-
export declare function Script(props:
|
|
71
|
-
|
|
72
|
-
children?: string;
|
|
73
|
-
}): JSXNode;
|
|
74
|
-
export declare function Style(props: {
|
|
75
|
-
children?: string;
|
|
76
|
-
}): JSXNode;
|
|
132
|
+
export declare function Script(props: Record<string, any>): JSXNode;
|
|
133
|
+
export declare function Style(props: Record<string, any>): JSXNode;
|
|
77
134
|
export declare function Link(props: {
|
|
78
135
|
href?: string;
|
|
79
136
|
prefetch?: boolean;
|