Skip to content

Commit 56e9fee

Browse files
authored
Remove Blocks (#20138)
* Remove Blocks * Remove Flight Server Runtime There's no need for this now that the JSResource is part of the bundler protocol. Might need something for Webpack plugin specifically later. * Devtools
1 parent 3fbd47b commit 56e9fee

File tree

61 files changed

+39
-1627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+39
-1627
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
import type {Wakeable} from 'shared/ReactTypes';
11-
import type {BlockComponent, BlockRenderFunction} from 'react/src/ReactBlock';
1211
import type {LazyComponent} from 'react/src/ReactLazy';
1312

1413
import type {
@@ -25,11 +24,7 @@ import {
2524
parseModel,
2625
} from './ReactFlightClientHostConfig';
2726

28-
import {
29-
REACT_LAZY_TYPE,
30-
REACT_BLOCK_TYPE,
31-
REACT_ELEMENT_TYPE,
32-
} from 'shared/ReactSymbols';
27+
import {REACT_LAZY_TYPE, REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
3328

3429
export type JSONValue =
3530
| number
@@ -229,15 +224,6 @@ export function reportGlobalError(response: Response, error: Error): void {
229224
});
230225
}
231226

232-
function readMaybeChunk<T>(maybeChunk: SomeChunk<T> | T): T {
233-
if (maybeChunk == null || !(maybeChunk instanceof Chunk)) {
234-
// $FlowFixMe
235-
return maybeChunk;
236-
}
237-
const chunk: SomeChunk<T> = (maybeChunk: any);
238-
return readChunk(chunk);
239-
}
240-
241227
function createElement(type, key, props): React$Element<any> {
242228
const element: any = {
243229
// This tag allows us to uniquely identify this as a React Element
@@ -279,45 +265,6 @@ function createElement(type, key, props): React$Element<any> {
279265
return element;
280266
}
281267

282-
type UninitializedBlockPayload<Data> = [
283-
mixed,
284-
BlockRenderFunction<any, Data> | SomeChunk<BlockRenderFunction<any, Data>>,
285-
Data | SomeChunk<Data>,
286-
Response,
287-
];
288-
289-
function initializeBlock<Props, Data>(
290-
tuple: UninitializedBlockPayload<Data>,
291-
): BlockComponent<Props, Data> {
292-
// Require module first and then data. The ordering matters.
293-
const moduleExport = readMaybeChunk(tuple[1]);
294-
295-
// The ordering here is important because this call might suspend.
296-
// We don't want that to prevent the module graph for being initialized.
297-
const data: Data = readMaybeChunk(tuple[2]);
298-
299-
return {
300-
$$typeof: REACT_BLOCK_TYPE,
301-
_status: -1,
302-
_data: data,
303-
_render: moduleExport,
304-
};
305-
}
306-
307-
function createLazyBlock<Props, Data>(
308-
tuple: UninitializedBlockPayload<Data>,
309-
): LazyComponent<BlockComponent<Props, Data>, UninitializedBlockPayload<Data>> {
310-
const lazyType: LazyComponent<
311-
BlockComponent<Props, Data>,
312-
UninitializedBlockPayload<Data>,
313-
> = {
314-
$$typeof: REACT_LAZY_TYPE,
315-
_payload: tuple,
316-
_init: initializeBlock,
317-
};
318-
return lazyType;
319-
}
320-
321268
function createLazyChunkWrapper<T>(
322269
chunk: SomeChunk<T>,
323270
): LazyComponent<T, SomeChunk<T>> {
@@ -354,25 +301,15 @@ export function parseModelString(
354301
} else {
355302
const id = parseInt(value.substring(1), 16);
356303
const chunk = getChunk(response, id);
357-
if (parentObject[0] === REACT_BLOCK_TYPE) {
358-
// Block types know how to deal with lazy values.
359-
return chunk;
360-
}
361-
// For anything else we must Suspend this block if
362-
// we don't yet have the value.
363304
return readChunk(chunk);
364305
}
365306
}
366307
case '@': {
367-
if (value === '@') {
368-
return REACT_BLOCK_TYPE;
369-
} else {
370-
const id = parseInt(value.substring(1), 16);
371-
const chunk = getChunk(response, id);
372-
// We create a React.lazy wrapper around any lazy values.
373-
// When passed into React, we'll know how to suspend on this.
374-
return createLazyChunkWrapper(chunk);
375-
}
308+
const id = parseInt(value.substring(1), 16);
309+
const chunk = getChunk(response, id);
310+
// We create a React.lazy wrapper around any lazy values.
311+
// When passed into React, we'll know how to suspend on this.
312+
return createLazyChunkWrapper(chunk);
376313
}
377314
}
378315
return value;
@@ -387,9 +324,6 @@ export function parseModelTuple(
387324
// TODO: Consider having React just directly accept these arrays as elements.
388325
// Or even change the ReactElement type to be an array.
389326
return createElement(tuple[1], tuple[2], tuple[3]);
390-
} else if (tuple[0] === REACT_BLOCK_TYPE) {
391-
// TODO: Consider having React just directly accept these arrays as blocks.
392-
return createLazyBlock((tuple: any));
393327
}
394328
return value;
395329
}

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010

1111
'use strict';
1212

13-
const ReactFeatureFlags = require('shared/ReactFeatureFlags');
14-
1513
let act;
1614
let React;
1715
let ReactNoop;
1816
let ReactNoopFlightServer;
19-
let ReactNoopFlightServerRuntime;
2017
let ReactNoopFlightClient;
2118
let ErrorBoundary;
2219

@@ -27,7 +24,6 @@ describe('ReactFlight', () => {
2724
React = require('react');
2825
ReactNoop = require('react-noop-renderer');
2926
ReactNoopFlightServer = require('react-noop-renderer/flight-server');
30-
ReactNoopFlightServerRuntime = require('react-noop-renderer/flight-server-runtime');
3127
ReactNoopFlightClient = require('react-noop-renderer/flight-client');
3228
act = ReactNoop.act;
3329

@@ -60,25 +56,6 @@ describe('ReactFlight', () => {
6056
};
6157
}
6258

63-
function block(render, load) {
64-
if (load === undefined) {
65-
return () => {
66-
return ReactNoopFlightServerRuntime.serverBlockNoData(
67-
moduleReference(render),
68-
);
69-
};
70-
}
71-
return function(...args) {
72-
const curriedLoad = () => {
73-
return load(...args);
74-
};
75-
return ReactNoopFlightServerRuntime.serverBlock(
76-
moduleReference(render),
77-
curriedLoad,
78-
);
79-
};
80-
}
81-
8259
it('can render a server component', () => {
8360
function Bar({text}) {
8461
return text.toUpperCase();
@@ -138,59 +115,6 @@ describe('ReactFlight', () => {
138115
expect(ReactNoop).toMatchRenderedOutput(<span>Hello, Seb Smith</span>);
139116
});
140117

141-
if (ReactFeatureFlags.enableBlocksAPI) {
142-
it('can transfer a Block to the client and render there, without data', () => {
143-
function User(props, data) {
144-
return (
145-
<span>
146-
{props.greeting} {typeof data}
147-
</span>
148-
);
149-
}
150-
const loadUser = block(User);
151-
const model = {
152-
User: loadUser('Seb', 'Smith'),
153-
};
154-
155-
const transport = ReactNoopFlightServer.render(model);
156-
157-
act(() => {
158-
const rootModel = ReactNoopFlightClient.read(transport);
159-
const UserClient = rootModel.User;
160-
ReactNoop.render(<UserClient greeting="Hello" />);
161-
});
162-
163-
expect(ReactNoop).toMatchRenderedOutput(<span>Hello undefined</span>);
164-
});
165-
166-
it('can transfer a Block to the client and render there, with data', () => {
167-
function load(firstName, lastName) {
168-
return {name: firstName + ' ' + lastName};
169-
}
170-
function User(props, data) {
171-
return (
172-
<span>
173-
{props.greeting}, {data.name}
174-
</span>
175-
);
176-
}
177-
const loadUser = block(User, load);
178-
const model = {
179-
User: loadUser('Seb', 'Smith'),
180-
};
181-
182-
const transport = ReactNoopFlightServer.render(model);
183-
184-
act(() => {
185-
const rootModel = ReactNoopFlightClient.read(transport);
186-
const UserClient = rootModel.User;
187-
ReactNoop.render(<UserClient greeting="Hello" />);
188-
});
189-
190-
expect(ReactNoop).toMatchRenderedOutput(<span>Hello, Seb Smith</span>);
191-
});
192-
}
193-
194118
it('should error if a non-serializable value is passed to a host component', () => {
195119
function EventHandlerProp() {
196120
return (

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
SimpleMemoComponent,
3131
ContextProvider,
3232
ForwardRef,
33-
Block,
3433
} from 'react-reconciler/src/ReactWorkTags';
3534

3635
type CurrentDispatcherRef = typeof ReactSharedInternals.ReactCurrentDispatcher;
@@ -667,8 +666,7 @@ export function inspectHooksOfFiber(
667666
if (
668667
fiber.tag !== FunctionComponent &&
669668
fiber.tag !== SimpleMemoComponent &&
670-
fiber.tag !== ForwardRef &&
671-
fiber.tag !== Block
669+
fiber.tag !== ForwardRef
672670
) {
673671
throw new Error(
674672
'Unknown Fiber. Needs to be a function component to inspect hooks.',

packages/react-devtools-shared/src/backend/DevToolsComponentStackFrame.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import type {LazyComponent} from 'react/src/ReactLazy';
1717
import type {CurrentDispatcherRef} from './types';
1818

1919
import {
20-
BLOCK_NUMBER,
21-
BLOCK_SYMBOL_STRING,
2220
FORWARD_REF_NUMBER,
2321
FORWARD_REF_SYMBOL_STRING,
2422
LAZY_NUMBER,
@@ -276,14 +274,6 @@ export function describeUnknownElementTypeFrameInDEV(
276274
ownerFn,
277275
currentDispatcherRef,
278276
);
279-
case BLOCK_NUMBER:
280-
case BLOCK_SYMBOL_STRING:
281-
return describeFunctionComponentFrame(
282-
type._render,
283-
source,
284-
ownerFn,
285-
currentDispatcherRef,
286-
);
287277
case LAZY_NUMBER:
288278
case LAZY_SYMBOL_STRING: {
289279
const lazyComponent: LazyComponent<any, any> = (type: any);

packages/react-devtools-shared/src/backend/DevToolsFiberComponentStack.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ function describeFiber(
3535
IndeterminateComponent,
3636
SimpleMemoComponent,
3737
ForwardRef,
38-
Block,
3938
ClassComponent,
4039
} = workTagMap;
4140

@@ -70,13 +69,6 @@ function describeFiber(
7069
owner,
7170
currentDispatcherRef,
7271
);
73-
case Block:
74-
return describeFunctionComponentFrame(
75-
workInProgress.type._render,
76-
source,
77-
owner,
78-
currentDispatcherRef,
79-
);
8072
case ClassComponent:
8173
return describeClassComponentFrame(
8274
workInProgress.type,

packages/react-devtools-shared/src/backend/ReactSymbols.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
// 2. DevTools must support both Symbol and numeric forms of each symbol;
1414
// Since e.g. standalone DevTools runs in a separate process, it can't rely on its own ES capabilities.
1515

16-
export const BLOCK_NUMBER = 0xead9;
17-
export const BLOCK_SYMBOL_STRING = 'Symbol(react.block)';
18-
1916
export const CONCURRENT_MODE_NUMBER = 0xeacf;
2017
export const CONCURRENT_MODE_SYMBOL_STRING = 'Symbol(react.concurrent_mode)';
2118

@@ -61,9 +58,6 @@ export const PROVIDER_SYMBOL_STRING = 'Symbol(react.provider)';
6158
export const SCOPE_NUMBER = 0xead7;
6259
export const SCOPE_SYMBOL_STRING = 'Symbol(react.scope)';
6360

64-
export const SERVER_BLOCK_NUMBER = 0xeada;
65-
export const SERVER_BLOCK_SYMBOL_STRING = 'Symbol(react.server.block)';
66-
6761
export const STRICT_MODE_NUMBER = 0xeacc;
6862
export const STRICT_MODE_SYMBOL_STRING = 'Symbol(react.strict_mode)';
6963

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ export function getInternalReactConstants(
169169
if (gte(version, '17.0.0-alpha')) {
170170
// TODO (Offscreen) Update the version number above to reflect the first Offscreen alpha/beta release.
171171
ReactTypeOfWork = {
172-
Block: 22,
173172
ClassComponent: 1,
174173
ContextConsumer: 9,
175174
ContextProvider: 10,
@@ -188,7 +187,7 @@ export function getInternalReactConstants(
188187
LazyComponent: 16,
189188
MemoComponent: 14,
190189
Mode: 8,
191-
OffscreenComponent: 23, // Experimental
190+
OffscreenComponent: 22, // Experimental
192191
Profiler: 12,
193192
SimpleMemoComponent: 15,
194193
SuspenseComponent: 13,
@@ -197,7 +196,6 @@ export function getInternalReactConstants(
197196
};
198197
} else if (gte(version, '16.6.0-beta.0')) {
199198
ReactTypeOfWork = {
200-
Block: 22,
201199
ClassComponent: 1,
202200
ContextConsumer: 9,
203201
ContextProvider: 10,
@@ -225,7 +223,6 @@ export function getInternalReactConstants(
225223
};
226224
} else if (gte(version, '16.4.3-alpha')) {
227225
ReactTypeOfWork = {
228-
Block: -1, // Doesn't exist yet
229226
ClassComponent: 2,
230227
ContextConsumer: 11,
231228
ContextProvider: 12,
@@ -253,7 +250,6 @@ export function getInternalReactConstants(
253250
};
254251
} else {
255252
ReactTypeOfWork = {
256-
Block: -1, // Doesn't exist yet
257253
ClassComponent: 2,
258254
ContextConsumer: 12,
259255
ContextProvider: 13,

packages/react-devtools-shared/src/backend/types.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export type WorkFlags = number;
2626
export type ExpirationTime = number;
2727

2828
export type WorkTagMap = {|
29-
Block: WorkTag,
3029
ClassComponent: WorkTag,
3130
ContextConsumer: WorkTag,
3231
ContextProvider: WorkTag,

packages/react-noop-renderer/flight-server-runtime.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/react-noop-renderer/npm/flight-server-runtime.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/react-noop-renderer/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"flight-client.js",
3030
"flight-modules.js",
3131
"flight-server.js",
32-
"flight-server-runtime.js",
3332
"cjs/"
3433
]
3534
}

0 commit comments

Comments
 (0)