[Ledgers] Scaffold Flight Ledgers behind a flag (#37588)

Sets up a feature flag for an upcoming experiment in Flight (RSC) called
Ledgers. A Ledger is an accumulated value determined as an effect of
rendering, representing some fact about the components that were
rendered. For example, a practical use case is tracking which route
parameters were accessed by the components in a response; every time a
component accesses a param, a ledger is updated. The result of a ledger
can only be read by the Flight client, and only once the stream has
closed.

Additional details will be shared in subsequent PRs.
This commit is contained in:
Andrew Clark authored and GitHub committed 2026-11-18 14:00:37 -05:00
1 parent 6ff257439b
commit 452c22cae1
11 files changed
+66

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
// TODO: Only the mask kind exists yet; the other kinds land in a later PR.
export const MASK_LEDGER = 1;
export type LedgerKind = 1;
// A ledger identifies which writes a capture should collect. Each capture
// computes its own accumulated value.
// eslint-disable-next-line no-unused-vars
export type Ledger<-E> = {
+kind: LedgerKind,
};
+31
View File
@@ -0,0 +1,31 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import type {Ledger, LedgerKind} from 'react-server/src/ReactFlightLedgers';
import {MASK_LEDGER} from 'react-server/src/ReactFlightLedgers';
function createLedger<E>(kind: LedgerKind): Ledger<E> {
const type = {
kind,
};
if (__DEV__) {
if (Object.freeze) {
Object.freeze(type);
}
}
return type;
}
export function createMaskLedger(): Ledger<number> {
return createLedger(MASK_LEDGER);
}
// TODO: Record entries during a Flight render.
export function addToLedger<E>(ledger: Ledger<E>, entry: E): void {}
@@ -38,6 +38,7 @@ import {forwardRef} from './ReactForwardRef';
import {lazy} from './ReactLazy';
import {memo} from './ReactMemo';
import {cache, cacheSignal} from './ReactCacheServer';
import {createMaskLedger, addToLedger} from './ReactLedgers';
import {startTransition} from './ReactStartTransition';
import {captureOwnerStack} from './ReactOwnerStack';
import version from 'shared/ReactVersion';
@@ -74,6 +75,8 @@ export {
memo,
cache,
cacheSignal,
createMaskLedger,
addToLedger,
startTransition,
getCacheForType as unstable_getCacheForType,
useId,
@@ -38,6 +38,7 @@ import {forwardRef} from './ReactForwardRef';
import {lazy} from './ReactLazy';
import {memo} from './ReactMemo';
import {cache, cacheSignal} from './ReactCacheServer';
import {createMaskLedger, addToLedger} from './ReactLedgers';
import {startTransition} from './ReactStartTransition';
import version from 'shared/ReactVersion';
@@ -73,6 +74,8 @@ export {
memo,
cache,
cacheSignal,
createMaskLedger,
addToLedger,
startTransition,
getCacheForType as unstable_getCacheForType,
useId,
+3
View File
@@ -90,6 +90,9 @@ export const enableFlightWeakThenables = __EXPERIMENTAL__;
// where it resolves via the manifest.
export const enableFlightObjectReferences = __EXPERIMENTAL__;
// Track metadata such as cache lifetimes and tags during a Flight render.
export const enableFlightLedgers = __EXPERIMENTAL__;
export const enableTaint = __EXPERIMENTAL__;
export const enableViewTransition: boolean = true;
@@ -38,6 +38,7 @@ export const disableTextareaChildren: boolean = false;
export const enableAsyncIterableChildren: boolean = false;
export const enableFlightWeakThenables: boolean = false;
export const enableFlightObjectReferences: boolean = false;
export const enableFlightLedgers: boolean = false;
export const enableCPUSuspense: boolean = true;
export const enableCreateEventHandleAPI: boolean = false;
export const enableMoveBefore: boolean = true;
@@ -27,6 +27,7 @@ export const disableTextareaChildren: boolean = false;
export const enableAsyncIterableChildren: boolean = false;
export const enableFlightWeakThenables: boolean = false;
export const enableFlightObjectReferences: boolean = false;
export const enableFlightLedgers: boolean = false;
export const enableCPUSuspense: boolean = false;
export const enableCreateEventHandleAPI: boolean = false;
export const enableMoveBefore: boolean = true;
@@ -21,6 +21,7 @@ export const enableLegacyCache: boolean = __EXPERIMENTAL__;
export const enableAsyncIterableChildren: boolean = false;
export const enableFlightWeakThenables: boolean = false;
export const enableFlightObjectReferences: boolean = false;
export const enableFlightLedgers: boolean = false;
export const enableTaint: boolean = true;
export const disableCommentsAsDOMContainers: boolean = true;
export const disableInputAttributeSyncing: boolean = false;
@@ -22,6 +22,7 @@ export const disableTextareaChildren = false;
export const enableAsyncIterableChildren = false;
export const enableFlightWeakThenables = false;
export const enableFlightObjectReferences = false;
export const enableFlightLedgers = false;
export const enableCPUSuspense = true;
export const enableCreateEventHandleAPI = false;
export const enableMoveBefore = false;
@@ -21,6 +21,7 @@ export const enableLegacyCache: boolean = true;
export const enableAsyncIterableChildren: boolean = false;
export const enableFlightWeakThenables: boolean = false;
export const enableFlightObjectReferences: boolean = false;
export const enableFlightLedgers: boolean = false;
export const enableTaint: boolean = true;
export const disableCommentsAsDOMContainers: boolean = true;
export const disableInputAttributeSyncing: boolean = false;
@@ -68,6 +68,7 @@ export const enableLegacyCache: boolean = true;
export const enableAsyncIterableChildren: boolean = false;
export const enableFlightWeakThenables: boolean = false;
export const enableFlightObjectReferences: boolean = false;
export const enableFlightLedgers: boolean = false;
export const enableTaint: boolean = false;