Skip to content

Commit ce6fe50

Browse files
authored
Add server-runtime to create Server Blocks (facebook#18392)
This is equivalent to the jsx-runtime in that this is what the compiled output on the server is supposed to target. It's really just the same code for all the different Flights, but they have different types in their arguments so each one gets their own entry point. We might use this to add runtime warnings per entry point. Unlike the client-side React.block call this doesn't provide the factory function that curries the load function. The compiler is expected to wrap this call in the currying factory.
1 parent 64ed221 commit ce6fe50

22 files changed

+181
-25
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ let act;
1616
let React;
1717
let ReactNoop;
1818
let ReactNoopFlightServer;
19+
let ReactNoopFlightServerRuntime;
1920
let ReactNoopFlightClient;
2021

2122
describe('ReactFlight', () => {
@@ -25,19 +26,22 @@ describe('ReactFlight', () => {
2526
React = require('react');
2627
ReactNoop = require('react-noop-renderer');
2728
ReactNoopFlightServer = require('react-noop-renderer/flight-server');
29+
ReactNoopFlightServerRuntime = require('react-noop-renderer/flight-server-runtime');
2830
ReactNoopFlightClient = require('react-noop-renderer/flight-client');
2931
act = ReactNoop.act;
3032
});
3133

3234
function block(render, load) {
35+
if (load === undefined) {
36+
return () => {
37+
return ReactNoopFlightServerRuntime.serverBlockNoData(render);
38+
};
39+
}
3340
return function(...args) {
34-
if (load === undefined) {
35-
return [Symbol.for('react.server.block'), render];
36-
}
3741
let curriedLoad = () => {
3842
return load(...args);
3943
};
40-
return [Symbol.for('react.server.block'), render, curriedLoad];
44+
return ReactNoopFlightServerRuntime.serverBlock(render, curriedLoad);
4145
};
4246
}
4347

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
export * from 'react-server/src/ReactFlightServerRuntime';

packages/react-flight-dom-relay/src/ReactFlightDOMRelayServerHostConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export type {
3131

3232
export type BundlerConfig = void;
3333

34-
export function resolveModuleMetaData(
34+
export function resolveModuleMetaData<T>(
3535
config: BundlerConfig,
36-
resource: ModuleReference,
36+
resource: ModuleReference<T>,
3737
): ModuleMetaData {
3838
return resolveModuleMetaDataImpl(resource);
3939
}

packages/react-flight-dom-relay/src/__tests__/ReactFlightDOMRelay-test.internal.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ let act;
1111
let React;
1212
let ReactDOM;
1313
let ReactDOMFlightRelayServer;
14+
let ReactDOMFlightRelayServerRuntime;
1415
let ReactDOMFlightRelayClient;
1516

1617
describe('ReactFlightDOMRelay', () => {
@@ -21,6 +22,7 @@ describe('ReactFlightDOMRelay', () => {
2122
React = require('react');
2223
ReactDOM = require('react-dom');
2324
ReactDOMFlightRelayServer = require('react-flight-dom-relay/server');
25+
ReactDOMFlightRelayServerRuntime = require('react-flight-dom-relay/server-runtime');
2426
ReactDOMFlightRelayClient = require('react-flight-dom-relay');
2527
});
2628

@@ -45,14 +47,14 @@ describe('ReactFlightDOMRelay', () => {
4547
}
4648

4749
function block(render, load) {
50+
if (load === undefined) {
51+
return ReactDOMFlightRelayServerRuntime.serverBlock(render);
52+
}
4853
return function(...args) {
49-
if (load === undefined) {
50-
return [Symbol.for('react.server.block'), render];
51-
}
5254
let curriedLoad = () => {
5355
return load(...args);
5456
};
55-
return [Symbol.for('react.server.block'), render, curriedLoad];
57+
return ReactDOMFlightRelayServerRuntime.serverBlock(render, curriedLoad);
5658
};
5759
}
5860

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
module.exports = require('./cjs/react-flight-dom-webpack-server-runtime.production.min.js');
5+
} else {
6+
module.exports = require('./cjs/react-flight-dom-webpack-server-runtime.development.js');
7+
}

packages/react-flight-dom-webpack/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"server.js",
1717
"server.browser.js",
1818
"server.node.js",
19+
"server-runtime.js",
1920
"cjs/",
2021
"umd/"
2122
],
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
export * from 'react-server/src/ReactFlightServerRuntime';

packages/react-flight-dom-webpack/src/ReactFlightServerWebpackBundlerConfig.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ type WebpackMap = {
1313

1414
export type BundlerConfig = WebpackMap;
1515

16-
export type ModuleReference = string;
16+
// eslint-disable-next-line no-unused-vars
17+
export type ModuleReference<T> = string;
1718

1819
export type ModuleMetaData = {
1920
id: string,
2021
chunks: Array<string>,
2122
name: string,
2223
};
2324

24-
export function resolveModuleMetaData(
25+
export function resolveModuleMetaData<T>(
2526
config: BundlerConfig,
26-
modulePath: ModuleReference,
27+
modulePath: ModuleReference<T>,
2728
): ModuleMetaData {
2829
return config[modulePath];
2930
}

packages/react-flight-dom-webpack/src/__tests__/ReactFlightDOM-test.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ let Stream;
2929
let React;
3030
let ReactDOM;
3131
let ReactFlightDOMServer;
32+
let ReactFlightDOMServerRuntime;
3233
let ReactFlightDOMClient;
3334

3435
describe('ReactFlightDOM', () => {
@@ -41,6 +42,7 @@ describe('ReactFlightDOM', () => {
4142
React = require('react');
4243
ReactDOM = require('react-dom');
4344
ReactFlightDOMServer = require('react-flight-dom-webpack/server');
45+
ReactFlightDOMServerRuntime = require('react-flight-dom-webpack/server-runtime');
4446
ReactFlightDOMClient = require('react-flight-dom-webpack');
4547
});
4648

@@ -72,14 +74,19 @@ describe('ReactFlightDOM', () => {
7274
chunks: [],
7375
name: 'd',
7476
};
77+
if (load === undefined) {
78+
return () => {
79+
return ReactFlightDOMServerRuntime.serverBlockNoData('path/' + idx);
80+
};
81+
}
7582
return function(...args) {
76-
if (load === undefined) {
77-
return [Symbol.for('react.server.block'), render];
78-
}
7983
let curriedLoad = () => {
8084
return load(...args);
8185
};
82-
return [Symbol.for('react.server.block'), 'path/' + idx, curriedLoad];
86+
return ReactFlightDOMServerRuntime.serverBlock(
87+
'path/' + idx,
88+
curriedLoad,
89+
);
8390
};
8491
}
8592

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
export * from 'react-server/flight-server-runtime';

0 commit comments

Comments
 (0)