Skip to content

Commit 45bba0d

Browse files
committed
Add a way to create Server Reference Proxies on the client (#26632)
This lets the client bundle encode Server References without them first being passed from an RSC payload. Like if you just import `"use server"` from the client. A bundler could already emit these proxies to be called on the client but the subtle difference is that those proxies couldn't be passed back into the server by reference. They have to be registered with React. We don't currently implement importing `"use server"` from client components in the reference implementation. It'd need to expand the Webpack plugin with a loader that rewrites files with the `"use server"` in the client bundle. ``` "use server"; export async function action() { ... } ``` -> ``` import {createServerReference} from "react-server-dom-webpack/client"; import {callServer} from "some-router/call-server"; export const action = createServerReference('1234#action', callServer); ``` The technique I use here is that the compiled output has to call `createServerReference(id, callServer)` with the `$$id` and proxy implementation. We then return a proxy function that is registered with a WeakMap to the particular instance of the Flight Client. This might be hard to implement because it requires emitting module imports to a specific stateful runtime module in the compiler. A benefit is that this ensures that this particular reference is locked to a specific client if there are multiple - e.g. talking to different servers. It's fairly arbitrary whether we use a WeakMap technique (like we do on the client) vs an `$$id` (like we do on the server). Not sure what's best overall. The WeakMap is nice because it doesn't leak implementation details that might be abused to consumers. We should probably pick one and unify. DiffTrain build for commit b600620.
1 parent de12cc7 commit 45bba0d

File tree

13 files changed

+19
-19
lines changed

13 files changed

+19
-19
lines changed

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23745,7 +23745,7 @@ function createFiberRoot(
2374523745
return root;
2374623746
}
2374723747

23748-
var ReactVersion = "18.3.0-next-da6c23a45-20230414";
23748+
var ReactVersion = "18.3.0-next-b6006201b-20230414";
2374923749

2375023750
// Might add PROFILE later.
2375123751

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8587,7 +8587,7 @@ var devToolsConfig$jscomp$inline_1023 = {
85878587
throw Error("TestRenderer does not support findFiberByHostInstance()");
85888588
},
85898589
bundleType: 0,
8590-
version: "18.3.0-next-da6c23a45-20230414",
8590+
version: "18.3.0-next-b6006201b-20230414",
85918591
rendererPackageName: "react-test-renderer"
85928592
};
85938593
var internals$jscomp$inline_1206 = {
@@ -8618,7 +8618,7 @@ var internals$jscomp$inline_1206 = {
86188618
scheduleRoot: null,
86198619
setRefreshHandler: null,
86208620
getCurrentFiber: null,
8621-
reconcilerVersion: "18.3.0-next-da6c23a45-20230414"
8621+
reconcilerVersion: "18.3.0-next-b6006201b-20230414"
86228622
};
86238623
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
86248624
var hook$jscomp$inline_1207 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9013,7 +9013,7 @@ var devToolsConfig$jscomp$inline_1065 = {
90139013
throw Error("TestRenderer does not support findFiberByHostInstance()");
90149014
},
90159015
bundleType: 0,
9016-
version: "18.3.0-next-da6c23a45-20230414",
9016+
version: "18.3.0-next-b6006201b-20230414",
90179017
rendererPackageName: "react-test-renderer"
90189018
};
90199019
var internals$jscomp$inline_1247 = {
@@ -9044,7 +9044,7 @@ var internals$jscomp$inline_1247 = {
90449044
scheduleRoot: null,
90459045
setRefreshHandler: null,
90469046
getCurrentFiber: null,
9047-
reconcilerVersion: "18.3.0-next-da6c23a45-20230414"
9047+
reconcilerVersion: "18.3.0-next-b6006201b-20230414"
90489048
};
90499049
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
90509050
var hook$jscomp$inline_1248 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-next-da6c23a45-20230414";
30+
var ReactVersion = "18.3.0-next-b6006201b-20230414";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,4 @@ exports.useSyncExternalStore = function (
639639
);
640640
};
641641
exports.useTransition = useTransition;
642-
exports.version = "18.3.0-next-da6c23a45-20230414";
642+
exports.version = "18.3.0-next-b6006201b-20230414";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ exports.useSyncExternalStore = function (
642642
);
643643
};
644644
exports.useTransition = useTransition;
645-
exports.version = "18.3.0-next-da6c23a45-20230414";
645+
exports.version = "18.3.0-next-b6006201b-20230414";
646646

647647
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
648648
if (
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
da6c23a45c62ac3edabae9b7145b14e35a470480
1+
b6006201b5fdfcc5720160f169b80ddb7b8d7467

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27052,7 +27052,7 @@ function createFiberRoot(
2705227052
return root;
2705327053
}
2705427054

27055-
var ReactVersion = "18.3.0-next-da6c23a45-20230414";
27055+
var ReactVersion = "18.3.0-next-b6006201b-20230414";
2705627056

2705727057
function createPortal$1(
2705827058
children,

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9456,7 +9456,7 @@ var roots = new Map(),
94569456
devToolsConfig$jscomp$inline_1047 = {
94579457
findFiberByHostInstance: getInstanceFromNode,
94589458
bundleType: 0,
9459-
version: "18.3.0-next-da6c23a45-20230414",
9459+
version: "18.3.0-next-b6006201b-20230414",
94609460
rendererPackageName: "react-native-renderer",
94619461
rendererConfig: {
94629462
getInspectorDataForViewTag: function () {
@@ -9498,7 +9498,7 @@ var internals$jscomp$inline_1276 = {
94989498
scheduleRoot: null,
94999499
setRefreshHandler: null,
95009500
getCurrentFiber: null,
9501-
reconcilerVersion: "18.3.0-next-da6c23a45-20230414"
9501+
reconcilerVersion: "18.3.0-next-b6006201b-20230414"
95029502
};
95039503
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
95049504
var hook$jscomp$inline_1277 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10165,7 +10165,7 @@ var roots = new Map(),
1016510165
devToolsConfig$jscomp$inline_1125 = {
1016610166
findFiberByHostInstance: getInstanceFromNode,
1016710167
bundleType: 0,
10168-
version: "18.3.0-next-da6c23a45-20230414",
10168+
version: "18.3.0-next-b6006201b-20230414",
1016910169
rendererPackageName: "react-native-renderer",
1017010170
rendererConfig: {
1017110171
getInspectorDataForViewTag: function () {
@@ -10220,7 +10220,7 @@ var roots = new Map(),
1022010220
scheduleRoot: null,
1022110221
setRefreshHandler: null,
1022210222
getCurrentFiber: null,
10223-
reconcilerVersion: "18.3.0-next-da6c23a45-20230414"
10223+
reconcilerVersion: "18.3.0-next-b6006201b-20230414"
1022410224
});
1022510225
exports.createPortal = function (children, containerTag) {
1022610226
return createPortal$1(

0 commit comments

Comments
 (0)