Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup enableServerComponentKeys flag #28743

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,6 @@ describe('ReactFlight', () => {
expect(errors).toEqual([]);
});

// @gate enableServerComponentKeys
it('preserves state when keying a server component', async () => {
function StatefulClient({name}) {
const [state] = React.useState(name.toLowerCase());
Expand Down Expand Up @@ -1751,7 +1750,6 @@ describe('ReactFlight', () => {
);
});

// @gate enableServerComponentKeys
it('does not inherit keys of children inside a server component', async () => {
function StatefulClient({name, initial}) {
const [state] = React.useState(initial);
Expand Down Expand Up @@ -1824,7 +1822,6 @@ describe('ReactFlight', () => {
);
});

// @gate enableServerComponentKeys
it('shares state between single return and array return in a parent', async () => {
function StatefulClient({name, initial}) {
const [state] = React.useState(initial);
Expand Down Expand Up @@ -2065,7 +2062,6 @@ describe('ReactFlight', () => {
);
});

// @gate enableServerComponentKeys
it('preserves state with keys split across async work', async () => {
let resolve;
const promise = new Promise(r => (resolve = r));
Expand Down
22 changes: 5 additions & 17 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
enableBinaryFlight,
enablePostpone,
enableTaint,
enableServerComponentKeys,
enableRefAsProp,
enableServerComponentLogs,
} from 'shared/ReactFeatureFlags';
Expand Down Expand Up @@ -993,7 +992,7 @@ function renderFragment(
task: Task,
children: $ReadOnlyArray<ReactClientValue>,
): ReactJSONValue {
if (enableServerComponentKeys && task.keyPath !== null) {
if (task.keyPath !== null) {
// We have a Server Component that specifies a key but we're now splitting
// the tree using a fragment.
const fragment = [
Expand Down Expand Up @@ -1052,7 +1051,7 @@ function renderAsyncFragment(
children: $AsyncIterable<ReactClientValue, ReactClientValue, void>,
getAsyncIterator: () => $AsyncIterator<any, any, any>,
): ReactJSONValue {
if (enableServerComponentKeys && task.keyPath !== null) {
if (task.keyPath !== null) {
// We have a Server Component that specifies a key but we're now splitting
// the tree using a fragment.
const fragment = [
Expand Down Expand Up @@ -1095,11 +1094,6 @@ function renderClientElement(
props: any,
owner: null | ReactComponentInfo, // DEV-only
): ReactJSONValue {
if (!enableServerComponentKeys) {
return __DEV__
? [REACT_ELEMENT_TYPE, type, key, props, owner]
: [REACT_ELEMENT_TYPE, type, key, props];
}
// We prepend the terminal client element that actually gets serialized with
// the keys of any Server Components which are not serialized.
const keyPath = task.keyPath;
Expand Down Expand Up @@ -1266,7 +1260,7 @@ function createTask(
if (typeof model === 'object' && model !== null) {
// If we're about to write this into a new task we can assign it an ID early so that
// any other references can refer to the value we're about to write.
if (enableServerComponentKeys && (keyPath !== null || implicitSlot)) {
if (keyPath !== null || implicitSlot) {
// If we're in some kind of context we can't necessarily reuse this object depending
// what parent components are used.
} else {
Expand Down Expand Up @@ -1756,10 +1750,7 @@ function renderModelDestructive(
const writtenObjects = request.writtenObjects;
const existingId = writtenObjects.get(value);
if (existingId !== undefined) {
if (
enableServerComponentKeys &&
(task.keyPath !== null || task.implicitSlot)
) {
if (task.keyPath !== null || task.implicitSlot) {
// If we're in some kind of context we can't reuse the result of this render or
// previous renders of this element. We only reuse elements if they're not wrapped
// by another Server Component.
Expand Down Expand Up @@ -1889,10 +1880,7 @@ function renderModelDestructive(
// $FlowFixMe[method-unbinding]
if (typeof value.then === 'function') {
if (existingId !== undefined) {
if (
enableServerComponentKeys &&
(task.keyPath !== null || task.implicitSlot)
) {
if (task.keyPath !== null || task.implicitSlot) {
// If we're in some kind of context we can't reuse the result of this render or
// previous renders of this element. We only reuse Promises if they're not wrapped
// by another Server Component.
Expand Down
3 changes: 0 additions & 3 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ export const enableFilterEmptyStringAttributesDOM = true;
// Disabled caching behavior of `react/cache` in client runtimes.
export const disableClientCache = true;

// Changes Server Components Reconciliation when they have keys
export const enableServerComponentKeys = true;

/**
* Enables a new error detection for infinite render loops from updates caused
* by setState or similar outside of the component owning the state.
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export const enableFizzExternalRuntime = true;
export const enableUseDeferredValueInitialArg = true;
export const disableClientCache = true;

export const enableServerComponentKeys = true;
export const enableServerComponentLogs = true;

export const enableReactTestRendererWarning = false;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export const enableUnifiedSyncLane = __NEXT_RN_MAJOR__;
export const enableFizzExternalRuntime = __NEXT_RN_MAJOR__; // DOM-only
export const enableBinaryFlight = __NEXT_RN_MAJOR__; // DOM-only
export const enableFlightReadableStream = __NEXT_RN_MAJOR__; // DOM-only
export const enableServerComponentKeys = __NEXT_RN_MAJOR__;
export const enableServerComponentLogs = __NEXT_RN_MAJOR__;

// DEV-only but enabled in the next RN Major.
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export const passChildrenWhenCloningPersistedNodes = false;
export const enableUseDeferredValueInitialArg = __EXPERIMENTAL__;
export const disableClientCache = true;

export const enableServerComponentKeys = true;
export const enableServerComponentLogs = true;
export const enableInfiniteRenderLoopDetection = false;
export const enableEarlyReturnForPropDiffing = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export const passChildrenWhenCloningPersistedNodes = false;
export const enableUseDeferredValueInitialArg = __EXPERIMENTAL__;
export const disableClientCache = true;

export const enableServerComponentKeys = true;
export const enableServerComponentLogs = true;

export const enableRefAsProp = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const passChildrenWhenCloningPersistedNodes = false;
export const enableUseDeferredValueInitialArg = true;
export const disableClientCache = true;

export const enableServerComponentKeys = true;
export const enableServerComponentLogs = true;
export const enableInfiniteRenderLoopDetection = false;

Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export const passChildrenWhenCloningPersistedNodes = false;
export const enableAsyncDebugInfo = false;
export const disableClientCache = true;

export const enableServerComponentKeys = true;
export const enableServerComponentLogs = true;

export const enableReactTestRendererWarning = false;
Expand Down