Skip to content

Commit

Permalink
useFormState: Compare action signatures when reusing form state (#27370)
Browse files Browse the repository at this point in the history
During an MPA form submission, useFormState should only reuse the form
state if same action is passed both times. (We also compare the key
paths.)

We compare the identity of the inner closure function, disregarding the
value of the bound arguments. That way you can pass an inline Server
Action closure:

```js
function FormContainer({maxLength}) {
  function submitAction(prevState, formData) {
    'use server'
    if (formData.get('field').length > maxLength) {
      return { errorMsg: 'Too many characters' };
    }
    // ...
  }
  return <Form submitAction={submitAction} />
}
```

DiffTrain build for commit 95c9554.
  • Loading branch information
acdlite committed Sep 14, 2023
1 parent fc5a146 commit 320e7a7
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23998,7 +23998,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-canary-612b2b660-20230913";
var ReactVersion = "18.3.0-canary-95c9554bc-20230913";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8620,7 +8620,7 @@ var devToolsConfig$jscomp$inline_1028 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-612b2b660-20230913",
version: "18.3.0-canary-95c9554bc-20230913",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1227 = {
Expand Down Expand Up @@ -8651,7 +8651,7 @@ var internals$jscomp$inline_1227 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-612b2b660-20230913"
reconcilerVersion: "18.3.0-canary-95c9554bc-20230913"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1228 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9046,7 +9046,7 @@ var devToolsConfig$jscomp$inline_1070 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-612b2b660-20230913",
version: "18.3.0-canary-95c9554bc-20230913",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1268 = {
Expand Down Expand Up @@ -9077,7 +9077,7 @@ var internals$jscomp$inline_1268 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-612b2b660-20230913"
reconcilerVersion: "18.3.0-canary-95c9554bc-20230913"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1269 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-canary-612b2b660-20230913";
var ReactVersion = "18.3.0-canary-95c9554bc-20230913";

// ATTENTION
// When adding new symbols to this file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,4 +616,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-612b2b660-20230913";
exports.version = "18.3.0-canary-95c9554bc-20230913";
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-612b2b660-20230913";
exports.version = "18.3.0-canary-95c9554bc-20230913";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
612b2b6601abb844248c384d1e288bb824b180b7
95c9554bc72813b0ee2b028774bb7cf0482887ba

0 comments on commit 320e7a7

Please sign in to comment.