Skip to content

Commit

Permalink
Cleanup enableServerComponentKeys flag
Browse files Browse the repository at this point in the history
Flag is `true` everywhere but RN where it doesn't apply.
  • Loading branch information
kassens committed Apr 4, 2024
1 parent 6090cab commit 6a6959b
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 29 deletions.
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 @@ -1609,7 +1609,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 @@ -1666,7 +1665,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 @@ -1739,7 +1737,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 @@ -1980,7 +1977,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
19 changes: 3 additions & 16 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 @@ -681,9 +680,6 @@ function renderFragment(
}
}
}
if (!enableServerComponentKeys) {
return children;
}
if (task.keyPath !== null) {
// We have a Server Component that specifies a key but we're now splitting
// the tree using a fragment.
Expand Down Expand Up @@ -724,9 +720,6 @@ function renderClientElement(
key: null | string,
props: any,
): ReactJSONValue {
if (!enableServerComponentKeys) {
return [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 @@ -875,7 +868,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 @@ -1320,10 +1313,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 @@ -1452,10 +1442,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 @@ -158,9 +158,6 @@ export const enableFilterEmptyStringAttributesDOM = true;
// Disabled caching behavior of `react/cache` in client runtimes.
export const disableClientCache = false;

// 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 @@ -84,7 +84,6 @@ export const enableFizzExternalRuntime = true;
export const enableUseDeferredValueInitialArg = true;
export const disableClientCache = true;

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

// TODO: Roll out with GK. Don't keep as dynamic flag for too long, though,
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 @@ -51,7 +51,6 @@ export const enableTaint = __NEXT_RN_MAJOR__;
export const enableUnifiedSyncLane = __NEXT_RN_MAJOR__;
export const enableFizzExternalRuntime = __NEXT_RN_MAJOR__; // DOM-only
export const enableBinaryFlight = __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 @@ -72,7 +72,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;

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

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

export const enableRefAsProp = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,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 @@ -101,7 +101,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

0 comments on commit 6a6959b

Please sign in to comment.