Skip to content

Commit

Permalink
[Flight] Allow custom encoding of the form action (#27563)
Browse files Browse the repository at this point in the history
There are three parts to an RSC set up:

- React
- Bundler
- Endpoints

Most customizability is in the bundler configs. We deal with those as
custom builds.

To create a full set up, you need to also configure ways to expose end
points for example to call a Server Action. That's typically not
something the bundler is responsible for even though it's responsible
for gathering the end points that needs generation. Exposing which
endpoints to generate is a responsibility for the bundler.

Typically a meta-framework is responsible for generating the end points.

There's two ways to "call" a Server Action. Through JS and through a
Form. Through JS we expose the `callServer` callback so that the
framework can call the end point.

Forms by default POST back to the current page with an action serialized
into form data, which we have a decoder helper for. However, this is not
something that React is really opinionated about just like we're not
opinionated about the protocol used by callServer.

This exposes an option to configure the encoding of the form props.
`encodeFormAction` is to the SSR is what `callServer` is to the Browser.

DiffTrain build for [8d48183](8d48183)
  • Loading branch information
sebmarkbage committed Feb 13, 2024
1 parent 56e29e3 commit 69dc39f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3f93ca1c8dec1fd85df4dbb748a2df9438fc699f
8d48183291870898ec42ac1f84482d9d26789424
11 changes: 9 additions & 2 deletions compiled/facebook-www/ReactFlightDOMClient-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ if (__DEV__) {

var knownServerReferences = new WeakMap(); // Serializable values

function registerServerReference(proxy, reference) {
function registerServerReference(proxy, reference, encodeFormAction) {
knownServerReferences.set(proxy, reference);
} // $FlowFixMe[method-unbinding]

Expand Down Expand Up @@ -862,12 +862,19 @@ if (__DEV__) {
);
}

function createResponse(bundlerConfig, moduleLoading, callServer, nonce) {
function createResponse(
bundlerConfig,
moduleLoading,
callServer,
encodeFormAction,
nonce
) {
var chunks = new Map();
var response = {
_bundlerConfig: bundlerConfig,
_moduleLoading: moduleLoading,
_callServer: callServer !== undefined ? callServer : missingCall,
_encodeFormAction: encodeFormAction,
_nonce: nonce,
_chunks: chunks,
_stringDecoder: createStringDecoder(),
Expand Down
1 change: 1 addition & 0 deletions compiled/facebook-www/ReactFlightDOMClient-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ exports.createFromReadableStream = function (stream, options) {
_bundlerConfig: options,
_moduleLoading: null,
_callServer: missingCall,
_encodeFormAction: void 0,
_nonce: void 0,
_chunks: chunks,
_stringDecoder: new TextDecoder(),
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/ReactServer-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -2652,7 +2652,7 @@ if (__DEV__) {
console["error"](error);
};

var ReactVersion = "18.3.0-www-modern-04a3249a";
var ReactVersion = "18.3.0-www-modern-20165ed1";

// Patch fetch
var Children = {
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/ReactServer-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,4 @@ exports.useId = function () {
exports.useMemo = function (create, deps) {
return ReactCurrentDispatcher.current.useMemo(create, deps);
};
exports.version = "18.3.0-www-modern-172d71ec";
exports.version = "18.3.0-www-modern-9683324c";

0 comments on commit 69dc39f

Please sign in to comment.