Skip to content

Commit 1d38154

Browse files
committed
Set up FB integration with React Flight Server
1 parent d1727fb commit 1d38154

19 files changed

+1818
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and 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 {default as rendererVersion} from 'shared/ReactVersion';
11+
export const rendererPackageName = 'react-flight-server-fb';
12+
13+
export * from 'react-client/src/ReactFlightClientStreamConfigWeb';
14+
export * from 'react-client/src/ReactClientConsoleConfigBrowser';
15+
export * from 'react-client/src/ReactClientDebugConfigBrowser';
16+
export * from 'react-flight-server-fb/src/client/ReactFlightClientConfigBundlerFB';
17+
export * from 'react-flight-server-fb/src/client/ReactFlightClientConfigTargetFBBrowser';
18+
export * from 'react-flight-server-fb/src/client/ReactFlightClientConfigDOMFB';
19+
export const usedWithSSR = false;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and 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 {default as rendererVersion} from 'shared/ReactVersion';
11+
export const rendererPackageName = 'react-flight-server-fb';
12+
13+
export * from 'react-client/src/ReactFlightClientStreamConfigWeb';
14+
export * from 'react-client/src/ReactClientConsoleConfigServer';
15+
export * from 'react-client/src/ReactClientDebugConfigNode';
16+
export * from 'react-flight-server-fb/src/client/ReactFlightClientConfigBundlerFB';
17+
export * from 'react-flight-server-fb/src/client/ReactFlightClientConfigTargetFBBrowser';
18+
export * from 'react-flight-server-fb/src/client/ReactFlightClientConfigDOMFB';
19+
export const usedWithSSR = false;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# react-flight-server-fb
2+
3+
React Flight bindings for DOM using Meta's internal bundler.
4+
5+
**Use it at your own risk.**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and 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 './src/client/ReactFlightDOMClientBrowser';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "react-flight-server-fb",
3+
"description": "React Server Components bindings for DOM using Meta's internal bundler. It is not intended to be imported directly.",
4+
"version": "19.3.0",
5+
"keywords": [
6+
"react"
7+
],
8+
"homepage": "https://react.dev/",
9+
"bugs": "https://github.com/facebook/react/issues",
10+
"license": "MIT",
11+
"files": [
12+
"LICENSE",
13+
"README.md",
14+
"client.browser.js"
15+
],
16+
"exports": {
17+
"./client": "./client.browser.js",
18+
"./client.browser": "./client.browser.js",
19+
"./src/*": "./src/*.js",
20+
"./package.json": "./package.json"
21+
},
22+
"repository": {
23+
"type" : "git",
24+
"url" : "https://github.com/facebook/react.git",
25+
"directory": "packages/react-flight-server-fb"
26+
},
27+
"engines": {
28+
"node": ">=0.10.0"
29+
},
30+
"peerDependencies": {
31+
"react": "^19.0.0",
32+
"react-dom": "^19.0.0"
33+
}
34+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and 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+
import type {ReactClientValue} from 'react-server/src/ReactFlightServer';
11+
12+
export type ServerReference<T: Function> = T & {
13+
$$typeof: symbol,
14+
$$id: string,
15+
$$bound: null | Array<ReactClientValue>,
16+
$$location?: Error,
17+
};
18+
19+
// eslint-disable-next-line no-unused-vars
20+
export type ClientReference<T> = {
21+
$$typeof: symbol,
22+
$$id: string,
23+
$$hblp: mixed,
24+
};
25+
26+
const CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
27+
const SERVER_REFERENCE_TAG = Symbol.for('react.server.reference');
28+
29+
export function isClientReference(reference: Object): boolean {
30+
return reference.$$typeof === CLIENT_REFERENCE_TAG;
31+
}
32+
33+
export function isServerReference(reference: Object): boolean {
34+
return reference.$$typeof === SERVER_REFERENCE_TAG;
35+
}
36+
37+
export function registerClientReference<T>(
38+
proxyImplementation: any,
39+
id: string,
40+
hblp: mixed,
41+
): ClientReference<T> {
42+
return Object.defineProperties(proxyImplementation, {
43+
$$typeof: {value: CLIENT_REFERENCE_TAG},
44+
$$id: {value: id},
45+
$$hblp: {value: hblp},
46+
});
47+
}
48+
49+
// $FlowFixMe[method-unbinding]
50+
const FunctionBind = Function.prototype.bind;
51+
// $FlowFixMe[method-unbinding]
52+
const ArraySlice = Array.prototype.slice;
53+
function bind(this: ServerReference<any>): any {
54+
// $FlowFixMe[incompatible-call]
55+
const newFn = FunctionBind.apply(this, arguments);
56+
if (this.$$typeof === SERVER_REFERENCE_TAG) {
57+
if (__DEV__) {
58+
const thisBind = arguments[0];
59+
if (thisBind != null) {
60+
console.error(
61+
'Cannot bind "this" of a Server Action. Pass null or undefined as the first argument to .bind().',
62+
);
63+
}
64+
}
65+
const args = ArraySlice.call(arguments, 1);
66+
const $$typeof = {value: SERVER_REFERENCE_TAG};
67+
const $$id = {value: this.$$id};
68+
const $$bound = {value: this.$$bound ? this.$$bound.concat(args) : args};
69+
return Object.defineProperties(
70+
(newFn: any),
71+
(__DEV__
72+
? {
73+
$$typeof,
74+
$$id,
75+
$$bound,
76+
$$location: {
77+
value: this.$$location,
78+
configurable: true,
79+
},
80+
bind: {value: bind, configurable: true},
81+
}
82+
: {
83+
$$typeof,
84+
$$id,
85+
$$bound,
86+
bind: {value: bind, configurable: true},
87+
}) as PropertyDescriptorMap,
88+
);
89+
}
90+
return newFn;
91+
}
92+
93+
const serverReferenceToString = {
94+
value: () => 'function () { [omitted code] }',
95+
configurable: true,
96+
writable: true,
97+
};
98+
99+
export function registerServerReference<T: Function>(
100+
reference: T,
101+
id: string,
102+
): ServerReference<T> {
103+
const $$typeof = {value: SERVER_REFERENCE_TAG};
104+
const $$id = {
105+
value: id,
106+
configurable: true,
107+
};
108+
const $$bound = {value: null, configurable: true};
109+
return Object.defineProperties(
110+
(reference: any),
111+
(__DEV__
112+
? {
113+
$$typeof,
114+
$$id,
115+
$$bound,
116+
$$location: {
117+
value: Error('react-stack-top-frame'),
118+
configurable: true,
119+
},
120+
bind: {value: bind, configurable: true},
121+
toString: serverReferenceToString,
122+
}
123+
: {
124+
$$typeof,
125+
$$id,
126+
$$bound,
127+
bind: {value: bind, configurable: true},
128+
toString: serverReferenceToString,
129+
}) as PropertyDescriptorMap,
130+
);
131+
}

0 commit comments

Comments
 (0)