@timber-js/app 0.2.0-alpha.241 → 0.2.0-alpha.242
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/_chunks/{actions-BCYVyoFl.js → actions-BkwgRwCl.js} +37 -9
- package/dist/_chunks/actions-BkwgRwCl.js.map +1 -0
- package/dist/_chunks/{als-registry-fabsRnPY.js → als-registry-C-iwbtvI.js} +1 -2
- package/dist/_chunks/{als-registry-fabsRnPY.js.map → als-registry-C-iwbtvI.js.map} +1 -1
- package/dist/_chunks/{cache-api-n5FL4wFs.js → cache-api-BGA7c5qJ.js} +5 -5
- package/dist/_chunks/{cache-api-n5FL4wFs.js.map → cache-api-BGA7c5qJ.js.map} +1 -1
- package/dist/_chunks/{chains-IswOWMnq.js → chains-Cuwwjv6T.js} +2 -2
- package/dist/_chunks/{chains-IswOWMnq.js.map → chains-Cuwwjv6T.js.map} +1 -1
- package/dist/_chunks/chains-LGjBHfSN.js +1 -0
- package/dist/_chunks/{classify-B08RCF6s.js → classify-Y8S9C0Na.js} +2 -2
- package/dist/_chunks/{classify-B08RCF6s.js.map → classify-Y8S9C0Na.js.map} +1 -1
- package/dist/_chunks/{cli-check-tpFb6pBU.js → cli-check-KeE1QaIx.js} +3 -3
- package/dist/_chunks/{cli-check-tpFb6pBU.js.map → cli-check-KeE1QaIx.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-DRNJutey.js → cli-schema-sync-DZEF31wd.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-DRNJutey.js.map → cli-schema-sync-DZEF31wd.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-C0pXBtzG.js → cli-schema-sync-_y5O6MIg.js} +1 -1
- package/dist/_chunks/{client-dep-entries-Dw5Dvatr.js → client-dep-entries-DpiwvoDi.js} +2 -2
- package/dist/_chunks/{client-dep-entries-Dw5Dvatr.js.map → client-dep-entries-DpiwvoDi.js.map} +1 -1
- package/dist/_chunks/{convention-lint-BfC_dAhZ.js → convention-lint-0AEsPK2T.js} +19 -5
- package/dist/_chunks/convention-lint-0AEsPK2T.js.map +1 -0
- package/dist/_chunks/dev-server-CboXr8zX.js +1 -0
- package/dist/_chunks/{dev-server-3R6Bl9_R.js → dev-server-DYDr8KIc.js} +2 -3
- package/dist/_chunks/dev-server-DYDr8KIc.js.map +1 -0
- package/dist/_chunks/{error-boundary-Dfhxigko.js → error-boundary-wuNvAJ4n.js} +8 -15
- package/dist/_chunks/error-boundary-wuNvAJ4n.js.map +1 -0
- package/dist/_chunks/{flight-source-node-QOpWZATb.js → flight-source-node-KQsX_OhS.js} +4 -7
- package/dist/_chunks/flight-source-node-KQsX_OhS.js.map +1 -0
- package/dist/_chunks/{json-lossy-check-5KFcC1yt.js → json-lossy-check-BVDALqMf.js} +2 -2
- package/dist/_chunks/{json-lossy-check-5KFcC1yt.js.map → json-lossy-check-BVDALqMf.js.map} +1 -1
- package/dist/_chunks/key-headers-uIig1_mU.js +40 -0
- package/dist/_chunks/key-headers-uIig1_mU.js.map +1 -0
- package/dist/_chunks/{live-graph-D1dfVqoT.js → live-graph-VhzO7Ol9.js} +4 -4
- package/dist/_chunks/{live-graph-D1dfVqoT.js.map → live-graph-VhzO7Ol9.js.map} +1 -1
- package/dist/_chunks/{logger-BvGxPd1e.js → logger-C4m8rfMy.js} +2 -2
- package/dist/_chunks/{logger-BvGxPd1e.js.map → logger-C4m8rfMy.js.map} +1 -1
- package/dist/_chunks/metadata-routes-MXNjWOt5.js.map +1 -1
- package/dist/_chunks/{node-response-D5cfiyWP.js → node-response-8Vz29cGS.js} +2 -2
- package/dist/_chunks/{node-response-D5cfiyWP.js.map → node-response-8Vz29cGS.js.map} +1 -1
- package/dist/_chunks/{poison-scan-CX02ilxN.js → poison-scan-Dpl3ibG-.js} +2 -2
- package/dist/_chunks/{poison-scan-CX02ilxN.js.map → poison-scan-Dpl3ibG-.js.map} +1 -1
- package/dist/_chunks/{scanner-DneYxQoY.js → scanner-CCEHN9Jg.js} +2 -2
- package/dist/_chunks/{scanner-DneYxQoY.js.map → scanner-CCEHN9Jg.js.map} +1 -1
- package/dist/_chunks/{sizeof-BtQ3ErLf.js → sizeof-CIF7fwSJ.js} +2 -2
- package/dist/_chunks/{sizeof-BtQ3ErLf.js.map → sizeof-CIF7fwSJ.js.map} +1 -1
- package/dist/_chunks/{walkers-C9R2A4jN.js → walkers-BbotBhNG.js} +3 -3
- package/dist/_chunks/{walkers-C9R2A4jN.js.map → walkers-BbotBhNG.js.map} +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/analyze/crawl-entry.js +3 -3
- package/dist/analyze/graph-command.js +2 -2
- package/dist/cache/index.js +2 -2
- package/dist/cache/stores/memory.js +1 -1
- package/dist/cdn/workers-cache-purge.js +1 -1
- package/dist/cli.js +3 -3
- package/dist/client/browser-entry/router-init.d.ts +0 -1
- package/dist/client/browser-entry/router-init.d.ts.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/internal.js +3 -5
- package/dist/client/internal.js.map +1 -1
- package/dist/client/navigation-commit.d.ts +0 -7
- package/dist/client/navigation-commit.d.ts.map +1 -1
- package/dist/client/outlet-content-cache.d.ts +16 -42
- package/dist/client/outlet-content-cache.d.ts.map +1 -1
- package/dist/client/outlet-scope-context.d.ts +4 -4
- package/dist/client/outlet-scope-context.d.ts.map +1 -1
- package/dist/client/params-context.d.ts +1 -1
- package/dist/client/router-types.d.ts +3 -13
- package/dist/client/router-types.d.ts.map +1 -1
- package/dist/client/router.d.ts.map +1 -1
- package/dist/client/segment-cache.d.ts +2 -2
- package/dist/client/segment-outlet.d.ts +12 -15
- package/dist/client/segment-outlet.d.ts.map +1 -1
- package/dist/client/stale-segment.d.ts +2 -2
- package/dist/config-types.d.ts +0 -17
- package/dist/config-types.d.ts.map +1 -1
- package/dist/config-validation.d.ts.map +1 -1
- package/dist/index.js +7 -8
- package/dist/index.js.map +1 -1
- package/dist/native/rsc/manifest.json +2 -4
- package/dist/native/rsc/routing/segment-keys.js.map +1 -1
- package/dist/native/rsc/server/als-registry.js +1 -2
- package/dist/native/rsc/server/als-registry.js.map +1 -1
- package/dist/native/rsc/server/client-state-tree.js +1 -5
- package/dist/native/rsc/server/client-state-tree.js.map +1 -1
- package/dist/native/rsc/server/flight-source-node.js +2 -5
- package/dist/native/rsc/server/flight-source-node.js.map +1 -1
- package/dist/native/rsc/server/flight-source.js +6 -41
- package/dist/native/rsc/server/flight-source.js.map +1 -1
- package/dist/native/rsc/server/framework-stack-frames.js.map +1 -1
- package/dist/native/rsc/server/request-context.js +3 -3
- package/dist/native/rsc/server/request-context.js.map +1 -1
- package/dist/native/rsc/server/route-element-builder.js +5 -5
- package/dist/native/rsc/server/route-element-builder.js.map +1 -1
- package/dist/native/rsc/server/rsc-entry/render-route.js +4 -30
- package/dist/native/rsc/server/rsc-entry/render-route.js.map +1 -1
- package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js +0 -2
- package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js.map +1 -1
- package/dist/native/rsc/server/rsc-entry/rsc-stream.js +2 -5
- package/dist/native/rsc/server/rsc-entry/rsc-stream.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/outlet-gate.js +44 -0
- package/dist/native/rsc/server/segment-lifetime/outlet-gate.js.map +1 -0
- package/dist/native/rsc/server/segment-lifetime/read-rule.js +25 -3
- package/dist/native/rsc/server/segment-lifetime/read-rule.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/read-scope.js +3 -2
- package/dist/native/rsc/server/segment-lifetime/read-scope.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/segment-key.js +17 -3
- package/dist/native/rsc/server/segment-lifetime/segment-key.js.map +1 -1
- package/dist/native/rsc/server/segment-lifetime/slot-outlets.js +4 -4
- package/dist/native/rsc/server/segment-lifetime/slot-outlets.js.map +1 -1
- package/dist/native/rsc/server/slot-resolver.js +3 -3
- package/dist/native/rsc/server/slot-resolver.js.map +1 -1
- package/dist/native/rsc/server/vite-handoff-rsc.js.map +1 -1
- package/dist/native/rsc/shared/key-headers.js +20 -0
- package/dist/native/rsc/shared/key-headers.js.map +1 -0
- package/dist/native/rsc/shared/outlet-decision.js.map +1 -1
- package/dist/native/ssr/client/outlet-content-cache.js +6 -26
- package/dist/native/ssr/client/outlet-content-cache.js.map +1 -1
- package/dist/native/ssr/client/outlet-scope-context.js.map +1 -1
- package/dist/native/ssr/client/segment-outlet.js +6 -19
- package/dist/native/ssr/client/segment-outlet.js.map +1 -1
- package/dist/native/ssr/manifest.json +1 -1
- package/dist/native/ssr/server/als-registry.js +0 -1
- package/dist/native/ssr/server/als-registry.js.map +1 -1
- package/dist/native/ssr/server/client-state-tree.js +1 -5
- package/dist/native/ssr/server/client-state-tree.js.map +1 -1
- package/dist/native/ssr/server/flight-source-node.js +2 -5
- package/dist/native/ssr/server/flight-source-node.js.map +1 -1
- package/dist/native/ssr/server/flight-source.js +0 -1
- package/dist/native/ssr/server/flight-source.js.map +1 -1
- package/dist/native/ssr/server/framework-stack-frames.js.map +1 -1
- package/dist/native/ssr/server/request-context.js +3 -3
- package/dist/native/ssr/server/request-context.js.map +1 -1
- package/dist/native/ssr/server/segment-lifetime/read-rule.js +25 -3
- package/dist/native/ssr/server/segment-lifetime/read-rule.js.map +1 -1
- package/dist/native/ssr/server/vite-handoff-rsc.js.map +1 -1
- package/dist/native/ssr/shared/key-headers.js +13 -0
- package/dist/native/ssr/shared/key-headers.js.map +1 -0
- package/dist/plugins/entries.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/routing/route-options.d.ts.map +1 -1
- package/dist/routing/segment-keys.d.ts +3 -4
- package/dist/routing/segment-keys.d.ts.map +1 -1
- package/dist/server/als-registry.d.ts +2 -16
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/client-state-tree.d.ts +5 -11
- package/dist/server/client-state-tree.d.ts.map +1 -1
- package/dist/server/flight-source-node.d.ts +1 -6
- package/dist/server/flight-source-node.d.ts.map +1 -1
- package/dist/server/flight-source.d.ts +0 -27
- package/dist/server/flight-source.d.ts.map +1 -1
- package/dist/server/framework-stack-frames.d.ts +1 -4
- package/dist/server/framework-stack-frames.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/internal.js +13 -23
- package/dist/server/internal.js.map +1 -1
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts +2 -2
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/rsc-entry/helpers.d.ts +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/rsc-entry/render-route.d.ts +0 -1
- package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
- package/dist/server/rsc-entry/revalidate-renderer.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-stream.d.ts +2 -11
- package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
- package/dist/server/segment-lifetime/outlet-gate.d.ts +58 -0
- package/dist/server/segment-lifetime/outlet-gate.d.ts.map +1 -0
- package/dist/server/segment-lifetime/read-rule.d.ts +13 -3
- package/dist/server/segment-lifetime/read-rule.d.ts.map +1 -1
- package/dist/server/segment-lifetime/read-scope.d.ts +2 -1
- package/dist/server/segment-lifetime/read-scope.d.ts.map +1 -1
- package/dist/server/segment-lifetime/segment-key.d.ts +3 -0
- package/dist/server/segment-lifetime/segment-key.d.ts.map +1 -1
- package/dist/server/segment-lifetime/slot-outlets.d.ts +2 -2
- package/dist/server/segment-lifetime/slot-outlets.d.ts.map +1 -1
- package/dist/server/slot-resolver.d.ts +5 -5
- package/dist/server/slot-resolver.d.ts.map +1 -1
- package/dist/server/types.d.ts +8 -2
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/vite-handoff-rsc.d.ts +1 -10
- package/dist/server/vite-handoff-rsc.d.ts.map +1 -1
- package/dist/shared/key-headers.d.ts +13 -0
- package/dist/shared/key-headers.d.ts.map +1 -0
- package/dist/shared/outlet-decision.d.ts +13 -44
- package/dist/shared/outlet-decision.d.ts.map +1 -1
- package/dist/shared/payload-root.d.ts +1 -1
- package/dist/shared/segment-info.d.ts +3 -7
- package/dist/shared/segment-info.d.ts.map +1 -1
- package/docs/api/30-api-server.mdx +1 -1
- package/package.json +1 -1
- package/src/client/browser-entry/index.ts +0 -2
- package/src/client/browser-entry/router-init.ts +2 -4
- package/src/client/error-boundary.tsx +1 -1
- package/src/client/navigation-commit.ts +4 -18
- package/src/client/outlet-content-cache.ts +24 -62
- package/src/client/outlet-scope-context.ts +5 -5
- package/src/client/params-context.ts +1 -1
- package/src/client/router-types.ts +3 -14
- package/src/client/router.ts +0 -2
- package/src/client/rsc-fetch.ts +1 -1
- package/src/client/segment-cache.ts +2 -2
- package/src/client/segment-outlet.tsx +19 -51
- package/src/client/stale-segment.ts +2 -2
- package/src/config-types.ts +0 -17
- package/src/config-validation.ts +0 -1
- package/src/plugins/entries.ts +0 -1
- package/src/routing/route-options.ts +20 -4
- package/src/routing/scanner.ts +1 -1
- package/src/routing/segment-keys.ts +3 -4
- package/src/rsc-runtime/vendor-types.d.ts +1 -1
- package/src/server/als-registry.ts +2 -23
- package/src/server/client-state-tree.ts +7 -18
- package/src/server/flight-source-node.ts +1 -5
- package/src/server/flight-source.ts +1 -81
- package/src/server/framework-stack-frames.ts +1 -4
- package/src/server/request-context.ts +6 -5
- package/src/server/route-element-builder.ts +13 -14
- package/src/server/rsc-entry/helpers.ts +1 -1
- package/src/server/rsc-entry/index.ts +0 -3
- package/src/server/rsc-entry/render-route.ts +7 -54
- package/src/server/rsc-entry/revalidate-renderer.ts +0 -2
- package/src/server/rsc-entry/rsc-stream.ts +3 -23
- package/src/server/segment-lifetime/outlet-gate.ts +102 -0
- package/src/server/segment-lifetime/read-rule.ts +63 -6
- package/src/server/segment-lifetime/read-scope.ts +4 -2
- package/src/server/segment-lifetime/segment-key.ts +31 -3
- package/src/server/segment-lifetime/slot-outlets.ts +5 -5
- package/src/server/slot-resolver.ts +8 -8
- package/src/server/types.ts +8 -2
- package/src/server/vite-handoff-rsc.ts +1 -12
- package/src/shared/key-headers.ts +42 -0
- package/src/shared/outlet-decision.ts +13 -48
- package/src/shared/payload-root.ts +1 -1
- package/src/shared/segment-info.ts +3 -7
- package/dist/_chunks/actions-BCYVyoFl.js.map +0 -1
- package/dist/_chunks/chains-DPZAMMav.js +0 -1
- package/dist/_chunks/convention-lint-BfC_dAhZ.js.map +0 -1
- package/dist/_chunks/dev-server-3DNTXQV-.js +0 -1
- package/dist/_chunks/dev-server-3R6Bl9_R.js.map +0 -1
- package/dist/_chunks/error-boundary-Dfhxigko.js.map +0 -1
- package/dist/_chunks/flight-source-node-QOpWZATb.js.map +0 -1
- package/dist/native/rsc/server/segment-hash/capture.js +0 -107
- package/dist/native/rsc/server/segment-hash/capture.js.map +0 -1
- package/dist/native/rsc/server/segment-hash/outlet.js +0 -101
- package/dist/native/rsc/server/segment-hash/outlet.js.map +0 -1
- package/dist/native/rsc/server/segment-hash/stream-tap.js +0 -139
- package/dist/native/rsc/server/segment-hash/stream-tap.js.map +0 -1
- package/dist/native/rsc/server/segment-hash/value-hash.js +0 -171
- package/dist/native/rsc/server/segment-hash/value-hash.js.map +0 -1
- package/dist/native/ssr/server/segment-hash/value-hash.js +0 -162
- package/dist/native/ssr/server/segment-hash/value-hash.js.map +0 -1
- package/dist/server/segment-hash/capture.d.ts +0 -77
- package/dist/server/segment-hash/capture.d.ts.map +0 -1
- package/dist/server/segment-hash/outlet.d.ts +0 -93
- package/dist/server/segment-hash/outlet.d.ts.map +0 -1
- package/dist/server/segment-hash/stream-tap.d.ts +0 -49
- package/dist/server/segment-hash/stream-tap.d.ts.map +0 -1
- package/dist/server/segment-hash/value-hash.d.ts +0 -70
- package/dist/server/segment-hash/value-hash.d.ts.map +0 -1
- package/src/server/segment-hash/capture.ts +0 -232
- package/src/server/segment-hash/outlet.ts +0 -229
- package/src/server/segment-hash/stream-tap.ts +0 -244
- package/src/server/segment-hash/value-hash.ts +0 -338
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The hash of a segment: a canonical walk over the values React's own Flight
|
|
3
|
-
* client decoded — never over the wire format.
|
|
4
|
-
*
|
|
5
|
-
* Both sides of the comparison are decoded by React (`createFromReadableStream`
|
|
6
|
-
* in the RSC environment): the capture of a segment, and the segment's rows in
|
|
7
|
-
* the response the client received. So everything about how Flight encodes a
|
|
8
|
-
* value — which markers mean references, how objects are outlined or deduped,
|
|
9
|
-
* which rows carry debug info — is interpreted by the code that defines it,
|
|
10
|
-
* and a React upgrade that changes the encoding changes nothing here.
|
|
11
|
-
*
|
|
12
|
-
* What is hashed is what a client can observe:
|
|
13
|
-
*
|
|
14
|
-
* - **Identity.** Every object is a node, numbered on first visit; a later
|
|
15
|
-
* visit writes `alias(n)`. Objects are the decoded objects themselves, so
|
|
16
|
-
* sharing, cycles and promise identity are exactly what the client gets —
|
|
17
|
-
* and a shared subgraph is written once.
|
|
18
|
-
* - **An allowlist of value kinds**: primitives, plain objects (own keys, in
|
|
19
|
-
* order), arrays, React elements, client and server references, promises,
|
|
20
|
-
* lazy elements, Dates, Maps, Sets, binary data and errors. Anything else —
|
|
21
|
-
* a stream, an async iterator, a class instance — makes the segment
|
|
22
|
-
* unhashable, which means it is always sent: a value kind this code does
|
|
23
|
-
* not know costs bytes, never correctness.
|
|
24
|
-
* - **Holes.** A nested `SegmentOutlet` element is `hole(segmentPath, key)`;
|
|
25
|
-
* its decision — and the nested segment's content — is not visited.
|
|
26
|
-
*
|
|
27
|
-
* The hash is SHA-256, truncated to 132 bits (22 base64url characters).
|
|
28
|
-
*
|
|
29
|
-
* See design/52-segment-hash-dedupe.md §"The hash is over a canonical form".
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
import { createHash } from 'node:crypto';
|
|
33
|
-
|
|
34
|
-
export const SEGMENT_HASH_LENGTH = 22;
|
|
35
|
-
|
|
36
|
-
export type ValueHashOutcome =
|
|
37
|
-
/** Every value the subgraph reaches is settled. */
|
|
38
|
-
| { status: 'complete'; hash: string; streaming: boolean }
|
|
39
|
-
/** Some promises or lazy elements are still pending; wait for them. */
|
|
40
|
-
| { status: 'pending'; streaming: boolean; waitFor: PromiseLike<unknown>[] }
|
|
41
|
-
/** A value of a kind not on the allowlist, or over budget: always sent. */
|
|
42
|
-
| { status: 'unhashable' };
|
|
43
|
-
|
|
44
|
-
export interface ValueHashOptions {
|
|
45
|
-
/** Whether an element type is timber's `SegmentOutlet` client reference. */
|
|
46
|
-
isOutlet(type: unknown): boolean;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const ELEMENT = new Set([Symbol.for('react.transitional.element'), Symbol.for('react.element')]);
|
|
50
|
-
const LAZY = Symbol.for('react.lazy');
|
|
51
|
-
const CLIENT_REFERENCE = Symbol.for('react.client.reference');
|
|
52
|
-
const SERVER_REFERENCE = Symbol.for('react.server.reference');
|
|
53
|
-
const SUSPENSE = Symbol.for('react.suspense');
|
|
54
|
-
|
|
55
|
-
/** Thrown inside the walk for a value kind not on the allowlist. */
|
|
56
|
-
const UNHASHABLE = Symbol('unhashable');
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Upper bound on a canonical form, in characters. Far above any segment a
|
|
60
|
-
* page sends; it exists so that no value graph can make the synchronous walk
|
|
61
|
-
* do unbounded work.
|
|
62
|
-
*/
|
|
63
|
-
const BUDGET = 32 * 1024 * 1024;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Upper bound on how deeply objects nest, so the recursive walk never
|
|
67
|
-
* reaches the engine's stack limit: an element costs about three levels
|
|
68
|
-
* (element, props, children), so this is some 330 levels of markup. A
|
|
69
|
-
* deeper graph is unhashable — sent, never skipped.
|
|
70
|
-
*/
|
|
71
|
-
const MAX_DEPTH = 1000;
|
|
72
|
-
|
|
73
|
-
export function hashCanonical(canonical: string): string {
|
|
74
|
-
return createHash('sha256').update(canonical).digest('base64url').slice(0, SEGMENT_HASH_LENGTH);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* In dev, @vitejs/plugin-rsc appends `$$cache=<random>` to every reference
|
|
79
|
-
* id, freshly per render, so the browser re-imports a module after HMR. Two
|
|
80
|
-
* renders of the same tree name the same module with different ids; the tag
|
|
81
|
-
* is not part of what the module is.
|
|
82
|
-
*/
|
|
83
|
-
export function stripReferenceCacheTag(id: string): string {
|
|
84
|
-
return id.replace(/\$\$cache=[^#]*/, '');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** A React Flight chunk or any thenable a decoded value may hold. */
|
|
88
|
-
interface Thenable {
|
|
89
|
-
then: (onFulfilled: (value: unknown) => void, onRejected: (reason: unknown) => void) => unknown;
|
|
90
|
-
status?: string;
|
|
91
|
-
value?: unknown;
|
|
92
|
-
reason?: unknown;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function isThenable(value: object): value is Thenable {
|
|
96
|
-
return typeof (value as { then?: unknown }).then === 'function';
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Hash the value graph rooted at `root`. */
|
|
100
|
-
export function hashValue(root: unknown, options: ValueHashOptions): ValueHashOutcome {
|
|
101
|
-
const nodes = new Map<object, number>();
|
|
102
|
-
const waitFor: PromiseLike<unknown>[] = [];
|
|
103
|
-
let size = 0;
|
|
104
|
-
let depth = 0;
|
|
105
|
-
let streaming = false;
|
|
106
|
-
|
|
107
|
-
const emit = (text: string): string => {
|
|
108
|
-
size += text.length;
|
|
109
|
-
if (size > BUDGET) throw UNHASHABLE;
|
|
110
|
-
return text;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const node = (object: object, write: () => string): string => {
|
|
114
|
-
const seen = nodes.get(object);
|
|
115
|
-
if (seen !== undefined) return emit('alias(' + seen + ')');
|
|
116
|
-
nodes.set(object, nodes.size);
|
|
117
|
-
if (++depth > MAX_DEPTH) throw UNHASHABLE;
|
|
118
|
-
const out = write();
|
|
119
|
-
depth--;
|
|
120
|
-
return out;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/** A settled promise's value, or `pending` with the walk going on past it. */
|
|
124
|
-
const settled = (thenable: Thenable): { value: unknown } | { error: unknown } | null => {
|
|
125
|
-
if (thenable.status === 'fulfilled') return { value: thenable.value };
|
|
126
|
-
if (thenable.status === 'rejected') return { error: thenable.reason };
|
|
127
|
-
waitFor.push(thenable as PromiseLike<unknown>);
|
|
128
|
-
return null;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const value = (v: unknown): string => {
|
|
132
|
-
switch (typeof v) {
|
|
133
|
-
case 'undefined':
|
|
134
|
-
return emit('u');
|
|
135
|
-
case 'boolean':
|
|
136
|
-
return emit(v ? 't' : 'f');
|
|
137
|
-
case 'number':
|
|
138
|
-
return emit(Object.is(v, -0) ? 'n(-0)' : 'n(' + String(v) + ')');
|
|
139
|
-
case 'bigint':
|
|
140
|
-
return emit('big(' + v.toString() + ')');
|
|
141
|
-
case 'string':
|
|
142
|
-
return emit(JSON.stringify(v));
|
|
143
|
-
case 'symbol': {
|
|
144
|
-
const key = Symbol.keyFor(v);
|
|
145
|
-
if (key === undefined) throw UNHASHABLE;
|
|
146
|
-
if (v === SUSPENSE) streaming = true;
|
|
147
|
-
return emit('sym(' + JSON.stringify(key) + ')');
|
|
148
|
-
}
|
|
149
|
-
case 'function':
|
|
150
|
-
return reference(v);
|
|
151
|
-
case 'object':
|
|
152
|
-
return v === null ? emit('null') : object(v);
|
|
153
|
-
}
|
|
154
|
-
throw UNHASHABLE;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const reference = (fn: object): string => {
|
|
158
|
-
const ref = fn as { $$typeof?: unknown; $$id?: unknown; $$bound?: unknown };
|
|
159
|
-
const id = ref.$$id;
|
|
160
|
-
if (typeof id !== 'string') throw UNHASHABLE;
|
|
161
|
-
if (ref.$$typeof === CLIENT_REFERENCE) {
|
|
162
|
-
return emit('client(' + JSON.stringify(stripReferenceCacheTag(id)) + ')');
|
|
163
|
-
}
|
|
164
|
-
if (ref.$$typeof === SERVER_REFERENCE) {
|
|
165
|
-
return node(
|
|
166
|
-
fn,
|
|
167
|
-
() =>
|
|
168
|
-
emit('server(' + JSON.stringify(stripReferenceCacheTag(id)) + ',') +
|
|
169
|
-
value(ref.$$bound ?? null) +
|
|
170
|
-
emit(')')
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
throw UNHASHABLE;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const object = (o: object): string => {
|
|
177
|
-
const tagged = o as { $$typeof?: unknown };
|
|
178
|
-
if (tagged.$$typeof !== undefined && ELEMENT.has(tagged.$$typeof as symbol)) return element(o);
|
|
179
|
-
if (tagged.$$typeof === LAZY) {
|
|
180
|
-
const payload = (o as { _payload?: unknown })._payload;
|
|
181
|
-
if (!payload || typeof payload !== 'object' || !isThenable(payload)) throw UNHASHABLE;
|
|
182
|
-
// A lazy element is its chunk's value, rendered in place.
|
|
183
|
-
return node(o, () => {
|
|
184
|
-
const result = settled(payload);
|
|
185
|
-
if (result === null) return emit('pending');
|
|
186
|
-
return 'error' in result ? error(result.error) : value(result.value);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
if (tagged.$$typeof === CLIENT_REFERENCE || tagged.$$typeof === SERVER_REFERENCE) {
|
|
190
|
-
return reference(o);
|
|
191
|
-
}
|
|
192
|
-
if (isThenable(o)) {
|
|
193
|
-
// A promise prop — the client receives it as a thenable. Waiting on it
|
|
194
|
-
// is streaming, the same as a Suspense boundary.
|
|
195
|
-
streaming = true;
|
|
196
|
-
return node(o, () => {
|
|
197
|
-
const result = settled(o);
|
|
198
|
-
if (result === null) return emit('promise(pending)');
|
|
199
|
-
return 'error' in result
|
|
200
|
-
? emit('promise(') + error(result.error) + emit(')')
|
|
201
|
-
: emit('promise(') + value(result.value) + emit(')');
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
if (Array.isArray(o)) {
|
|
205
|
-
return node(o, () => emit('[') + o.map((item) => value(item)).join(',') + emit(']'));
|
|
206
|
-
}
|
|
207
|
-
if (o instanceof Date) return node(o, () => emit('date(' + String(o.getTime()) + ')'));
|
|
208
|
-
if (o instanceof Map) {
|
|
209
|
-
return node(
|
|
210
|
-
o,
|
|
211
|
-
() =>
|
|
212
|
-
emit('map(') +
|
|
213
|
-
[...o].map(([k, item]) => value(k) + emit(':') + value(item)).join(',') +
|
|
214
|
-
emit(')')
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
if (o instanceof Set) {
|
|
218
|
-
return node(o, () => emit('set(') + [...o].map((item) => value(item)).join(',') + emit(')'));
|
|
219
|
-
}
|
|
220
|
-
if (o instanceof ArrayBuffer) {
|
|
221
|
-
return node(o, () => emit('buffer(' + bytes(new Uint8Array(o)) + ')'));
|
|
222
|
-
}
|
|
223
|
-
if (ArrayBuffer.isView(o)) {
|
|
224
|
-
const view = new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
225
|
-
return node(o, () => emit('view(' + o.constructor.name + ',' + bytes(view) + ')'));
|
|
226
|
-
}
|
|
227
|
-
if (o instanceof Error) return node(o, () => error(o));
|
|
228
|
-
const proto = Object.getPrototypeOf(o);
|
|
229
|
-
if (proto !== Object.prototype && proto !== null) throw UNHASHABLE;
|
|
230
|
-
// Own key order, not sorted: a client component that iterates its props
|
|
231
|
-
// (`Object.entries`, a `style` object's shorthand/longhand order) renders
|
|
232
|
-
// differently when it changes.
|
|
233
|
-
return node(
|
|
234
|
-
o,
|
|
235
|
-
() =>
|
|
236
|
-
emit('{') +
|
|
237
|
-
Object.keys(o)
|
|
238
|
-
.map((k) => emit(JSON.stringify(k) + ':') + value((o as Record<string, unknown>)[k]))
|
|
239
|
-
.join(',') +
|
|
240
|
-
emit('}')
|
|
241
|
-
);
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
const element = (el: object): string => {
|
|
245
|
-
const { key, props } = el as { key: unknown; props: unknown };
|
|
246
|
-
// A client component's type arrives as a lazy reference to its module
|
|
247
|
-
// until the module resolves.
|
|
248
|
-
let type = (el as { type: unknown }).type;
|
|
249
|
-
const lazyType = type as { $$typeof?: unknown; _payload?: unknown } | null;
|
|
250
|
-
if (lazyType && typeof lazyType === 'object' && lazyType.$$typeof === LAZY) {
|
|
251
|
-
const payload = lazyType._payload;
|
|
252
|
-
if (!payload || typeof payload !== 'object' || !isThenable(payload)) throw UNHASHABLE;
|
|
253
|
-
const result = settled(payload);
|
|
254
|
-
if (result === null) return emit('pending');
|
|
255
|
-
if ('error' in result) return error(result.error);
|
|
256
|
-
type = result.value;
|
|
257
|
-
}
|
|
258
|
-
if (options.isOutlet(type)) {
|
|
259
|
-
const segmentPath =
|
|
260
|
-
props && typeof props === 'object'
|
|
261
|
-
? (props as { segmentPath?: unknown }).segmentPath
|
|
262
|
-
: undefined;
|
|
263
|
-
// The key stays: a layout that re-keys its children (cloneElement) asks
|
|
264
|
-
// React to remount them, which is a change to the layout's output.
|
|
265
|
-
return emit(
|
|
266
|
-
'hole(' + JSON.stringify(segmentPath ?? null) + ',' + JSON.stringify(key ?? null) + ')'
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
return node(
|
|
270
|
-
el,
|
|
271
|
-
() =>
|
|
272
|
-
emit('el(') +
|
|
273
|
-
value(type) +
|
|
274
|
-
emit(',' + JSON.stringify(key ?? null) + ',') +
|
|
275
|
-
value(props) +
|
|
276
|
-
emit(')')
|
|
277
|
-
);
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* An error, as Flight sends it. Production sends a bare marker the client
|
|
282
|
-
* revives as a generic Error (or a digest on an error row). Development
|
|
283
|
-
* sends name, message, stack and environment, and the `cause` and an
|
|
284
|
-
* AggregateError's `errors` — all of which the client's revived error
|
|
285
|
-
* carries, so all of which are hashed.
|
|
286
|
-
*/
|
|
287
|
-
const error = (e: unknown): string => {
|
|
288
|
-
if (!(e instanceof Error)) return emit('error(') + value(e) + emit(')');
|
|
289
|
-
const fields = e as Error & { digest?: unknown; environmentName?: unknown; errors?: unknown };
|
|
290
|
-
let out = emit(
|
|
291
|
-
'error(' +
|
|
292
|
-
JSON.stringify([
|
|
293
|
-
e.name,
|
|
294
|
-
e.message,
|
|
295
|
-
typeof fields.digest === 'string' ? fields.digest : null,
|
|
296
|
-
typeof e.stack === 'string' ? e.stack : null,
|
|
297
|
-
typeof fields.environmentName === 'string' ? fields.environmentName : null,
|
|
298
|
-
])
|
|
299
|
-
);
|
|
300
|
-
if ('cause' in e) out += emit(',cause:') + value(e.cause);
|
|
301
|
-
if (Array.isArray(fields.errors)) out += emit(',errors:') + value(fields.errors);
|
|
302
|
-
return out + emit(')');
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
try {
|
|
306
|
-
const canonical = value(root);
|
|
307
|
-
if (waitFor.length > 0) return { status: 'pending', streaming, waitFor };
|
|
308
|
-
return { status: 'complete', hash: hashCanonical(canonical), streaming };
|
|
309
|
-
} catch (thrown) {
|
|
310
|
-
if (thrown === UNHASHABLE) return { status: 'unhashable' };
|
|
311
|
-
throw thrown;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
function bytes(view: Uint8Array): string {
|
|
316
|
-
let binary = '';
|
|
317
|
-
for (let i = 0; i < view.length; i++) binary += String.fromCharCode(view[i]);
|
|
318
|
-
return btoa(binary);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Hash `root` once everything it reaches has settled, waiting as needed.
|
|
323
|
-
* Settles to null if it is unhashable or `signal` aborts first.
|
|
324
|
-
*/
|
|
325
|
-
export async function hashSettledValue(
|
|
326
|
-
root: unknown,
|
|
327
|
-
options: ValueHashOptions,
|
|
328
|
-
signal: { aborted: boolean }
|
|
329
|
-
): Promise<string | null> {
|
|
330
|
-
for (;;) {
|
|
331
|
-
if (signal.aborted) return null;
|
|
332
|
-
const outcome = hashValue(root, options);
|
|
333
|
-
if (outcome.status === 'complete') return outcome.hash;
|
|
334
|
-
if (outcome.status === 'unhashable') return null;
|
|
335
|
-
// Rejections are part of the value (`error(...)`), not a reason to stop.
|
|
336
|
-
await Promise.allSettled(outcome.waitFor.map((t) => Promise.resolve(t)));
|
|
337
|
-
}
|
|
338
|
-
}
|