Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useFormState: Compare action signatures when reusing form state #27370

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Sep 13, 2023

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:

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

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Sep 13, 2023
@acdlite acdlite force-pushed the useformstate-is-signature-equal branch from 0aaa730 to abbd73a Compare September 13, 2023 20:31
@acdlite acdlite requested a review from sebmarkbage September 13, 2023 20:33
}
// Unwrap the bound arguments array by suspending, if necessary. As with
// encodeFormData, this means isSignatureEqual can only be called while React
// is rendering.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting because we don't actually need the value but just the arity. The main reason this is a Promise is so we can put the bound fields later in the stream etc. and so that we can also decode references. However, we could also make this an array of promises instead. On reason not to do that is that it doesn't allow the bound arguments to be promises themselves since they'd unwrap and would need an extra indirection but that would allow us to get the arity without suspending.

Most of the time this will just be fulfillled though.

@acdlite acdlite force-pushed the useformstate-is-signature-equal branch 2 times, most recently from 27dc59d to 279d0fb Compare September 13, 2023 22:38
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} />
}
```
@acdlite acdlite force-pushed the useformstate-is-signature-equal branch from 279d0fb to cc283ce Compare September 13, 2023 23:59
@react-sizebot
Copy link

Comparing: 612b2b6...cc283ce

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 166.62 kB 166.62 kB = 52.13 kB 52.13 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 176.05 kB 176.05 kB = 54.96 kB 54.96 kB
facebook-www/ReactDOM-prod.classic.js = 571.73 kB 571.73 kB = 100.64 kB 100.64 kB
facebook-www/ReactDOM-prod.modern.js = 555.46 kB 555.46 kB = 97.75 kB 97.75 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.min.js +4.86% 10.96 kB 11.49 kB +3.01% 4.18 kB 4.31 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.min.js +4.86% 10.96 kB 11.49 kB +3.01% 4.18 kB 4.31 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.69% 11.36 kB 11.89 kB +2.94% 4.35 kB 4.48 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.69% 11.36 kB 11.89 kB +2.94% 4.35 kB 4.48 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +4.56% 11.68 kB 12.22 kB +2.83% 4.49 kB 4.62 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +4.56% 11.68 kB 12.22 kB +2.83% 4.49 kB 4.62 kB
oss-stable-semver/react-client/cjs/react-client-flight.production.min.js +4.52% 9.51 kB 9.94 kB +3.14% 3.73 kB 3.84 kB
oss-stable/react-client/cjs/react-client-flight.production.min.js +4.52% 9.51 kB 9.94 kB +3.14% 3.73 kB 3.84 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +4.46% 11.95 kB 12.48 kB +2.80% 4.58 kB 4.70 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +4.46% 11.95 kB 12.48 kB +2.80% 4.58 kB 4.70 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.min.js +4.34% 12.28 kB 12.81 kB +2.72% 4.56 kB 4.68 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.20% 12.68 kB 13.21 kB +2.71% 4.72 kB 4.85 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +4.10% 13.01 kB 13.54 kB +2.59% 4.86 kB 4.98 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +4.02% 13.25 kB 13.79 kB +2.57% 4.94 kB 5.07 kB
oss-experimental/react-client/cjs/react-client-flight.production.min.js +4.02% 10.70 kB 11.13 kB +2.98% 4.05 kB 4.18 kB
oss-stable-semver/react-client/cjs/react-client-flight.development.js +3.54% 49.45 kB 51.20 kB +2.84% 12.35 kB 12.71 kB
oss-stable/react-client/cjs/react-client-flight.development.js +3.54% 49.45 kB 51.20 kB +2.84% 12.35 kB 12.71 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +3.22% 54.31 kB 56.06 kB +2.57% 13.22 kB 13.56 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +3.22% 54.31 kB 56.06 kB +2.57% 13.22 kB 13.56 kB
oss-experimental/react-client/cjs/react-client-flight.development.js +3.21% 54.49 kB 56.24 kB +2.53% 13.38 kB 13.72 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +3.15% 55.60 kB 57.35 kB +2.50% 13.55 kB 13.89 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +3.15% 55.60 kB 57.35 kB +2.50% 13.55 kB 13.89 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +3.08% 56.84 kB 58.59 kB +2.39% 13.94 kB 14.28 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +3.08% 56.84 kB 58.59 kB +2.39% 13.94 kB 14.28 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +3.04% 57.56 kB 59.31 kB +2.33% 14.09 kB 14.42 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +3.04% 57.56 kB 59.31 kB +2.33% 14.09 kB 14.42 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.95% 59.36 kB 61.11 kB +2.37% 14.24 kB 14.57 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.88% 60.65 kB 62.39 kB +2.32% 14.57 kB 14.90 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.83% 61.89 kB 63.63 kB +2.21% 14.96 kB 15.29 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.79% 62.61 kB 64.36 kB +2.18% 15.11 kB 15.44 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.min.js +4.86% 10.96 kB 11.49 kB +3.01% 4.18 kB 4.31 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.min.js +4.86% 10.96 kB 11.49 kB +3.01% 4.18 kB 4.31 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.69% 11.36 kB 11.89 kB +2.94% 4.35 kB 4.48 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.69% 11.36 kB 11.89 kB +2.94% 4.35 kB 4.48 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +4.56% 11.68 kB 12.22 kB +2.83% 4.49 kB 4.62 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +4.56% 11.68 kB 12.22 kB +2.83% 4.49 kB 4.62 kB
oss-stable-semver/react-client/cjs/react-client-flight.production.min.js +4.52% 9.51 kB 9.94 kB +3.14% 3.73 kB 3.84 kB
oss-stable/react-client/cjs/react-client-flight.production.min.js +4.52% 9.51 kB 9.94 kB +3.14% 3.73 kB 3.84 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +4.46% 11.95 kB 12.48 kB +2.80% 4.58 kB 4.70 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +4.46% 11.95 kB 12.48 kB +2.80% 4.58 kB 4.70 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.min.js +4.34% 12.28 kB 12.81 kB +2.72% 4.56 kB 4.68 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.20% 12.68 kB 13.21 kB +2.71% 4.72 kB 4.85 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +4.10% 13.01 kB 13.54 kB +2.59% 4.86 kB 4.98 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +4.02% 13.25 kB 13.79 kB +2.57% 4.94 kB 5.07 kB
oss-experimental/react-client/cjs/react-client-flight.production.min.js +4.02% 10.70 kB 11.13 kB +2.98% 4.05 kB 4.18 kB
oss-stable-semver/react-client/cjs/react-client-flight.development.js +3.54% 49.45 kB 51.20 kB +2.84% 12.35 kB 12.71 kB
oss-stable/react-client/cjs/react-client-flight.development.js +3.54% 49.45 kB 51.20 kB +2.84% 12.35 kB 12.71 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +3.22% 54.31 kB 56.06 kB +2.57% 13.22 kB 13.56 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +3.22% 54.31 kB 56.06 kB +2.57% 13.22 kB 13.56 kB
oss-experimental/react-client/cjs/react-client-flight.development.js +3.21% 54.49 kB 56.24 kB +2.53% 13.38 kB 13.72 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +3.15% 55.60 kB 57.35 kB +2.50% 13.55 kB 13.89 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +3.15% 55.60 kB 57.35 kB +2.50% 13.55 kB 13.89 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +3.08% 56.84 kB 58.59 kB +2.39% 13.94 kB 14.28 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +3.08% 56.84 kB 58.59 kB +2.39% 13.94 kB 14.28 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +3.04% 57.56 kB 59.31 kB +2.33% 14.09 kB 14.42 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +3.04% 57.56 kB 59.31 kB +2.33% 14.09 kB 14.42 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.95% 59.36 kB 61.11 kB +2.37% 14.24 kB 14.57 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.88% 60.65 kB 62.39 kB +2.32% 14.57 kB 14.90 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.83% 61.89 kB 63.63 kB +2.21% 14.96 kB 15.29 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.79% 62.61 kB 64.36 kB +2.18% 15.11 kB 15.44 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +1.21% 97.70 kB 98.88 kB +1.02% 23.34 kB 23.58 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +1.21% 97.70 kB 98.88 kB +1.02% 23.34 kB 23.58 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.min.js +1.19% 24.79 kB 25.09 kB +0.53% 8.63 kB 8.68 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.min.js +1.19% 24.79 kB 25.09 kB +0.53% 8.63 kB 8.68 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +1.17% 101.42 kB 102.60 kB +0.95% 24.54 kB 24.77 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +1.17% 101.42 kB 102.60 kB +0.95% 24.54 kB 24.77 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +1.16% 101.83 kB 103.01 kB +0.95% 24.65 kB 24.88 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +1.16% 101.83 kB 103.01 kB +0.95% 24.65 kB 24.88 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +1.16% 102.11 kB 103.30 kB +0.98% 24.10 kB 24.34 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +1.16% 107.24 kB 108.48 kB +0.96% 24.91 kB 25.15 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +1.16% 107.24 kB 108.48 kB +0.96% 24.91 kB 25.15 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.min.js +1.14% 25.95 kB 26.24 kB +0.52% 8.92 kB 8.96 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +1.13% 26.17 kB 26.47 kB +0.56% 8.92 kB 8.97 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +1.13% 26.17 kB 26.47 kB +0.56% 8.92 kB 8.97 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1.13% 105.13 kB 106.31 kB +0.92% 25.14 kB 25.37 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1.13% 105.13 kB 106.31 kB +0.92% 25.14 kB 25.37 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +1.12% 26.49 kB 26.78 kB +0.54% 9.03 kB 9.08 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +1.12% 26.49 kB 26.78 kB +0.54% 9.03 kB 9.08 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +1.12% 106.28 kB 107.47 kB +0.93% 25.43 kB 25.67 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +1.11% 26.34 kB 26.63 kB +0.59% 9.04 kB 9.10 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +1.11% 26.34 kB 26.63 kB +0.59% 9.04 kB 9.10 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +1.11% 106.69 kB 107.88 kB +0.93% 25.55 kB 25.79 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +1.11% 107.17 kB 108.36 kB +0.96% 25.74 kB 25.99 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +1.11% 107.17 kB 108.36 kB +0.96% 25.74 kB 25.99 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +1.10% 112.34 kB 113.58 kB +0.93% 25.79 kB 26.03 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1.08% 109.54 kB 110.73 kB +0.91% 25.89 kB 26.12 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +1.08% 27.38 kB 27.68 kB +0.54% 9.23 kB 9.28 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +1.08% 27.43 kB 27.72 kB +0.51% 9.37 kB 9.42 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +1.08% 27.43 kB 27.72 kB +0.51% 9.37 kB 9.42 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +1.07% 27.70 kB 28.00 kB +0.56% 9.33 kB 9.39 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +1.06% 27.55 kB 27.85 kB +0.52% 9.35 kB 9.40 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +1.06% 111.59 kB 112.77 kB +0.90% 26.48 kB 26.72 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +1.06% 27.96 kB 28.25 kB +0.55% 9.52 kB 9.58 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +1.06% 27.96 kB 28.25 kB +0.55% 9.52 kB 9.58 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +1.03% 28.59 kB 28.88 kB +0.49% 9.66 kB 9.71 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +1.01% 29.11 kB 29.41 kB +0.50% 9.82 kB 9.87 kB
oss-experimental/react-server/cjs/react-server.production.min.js +0.62% 29.70 kB 29.88 kB +0.51% 9.85 kB 9.90 kB
oss-experimental/react-server/cjs/react-server.development.js +0.42% 168.68 kB 169.38 kB +0.42% 41.43 kB 41.60 kB
facebook-www/ReactDOMServer-prod.modern.js +0.36% 157.04 kB 157.61 kB +0.58% 28.62 kB 28.78 kB
facebook-www/ReactDOMServer-prod.classic.js +0.36% 157.71 kB 158.28 kB +0.53% 28.83 kB 28.98 kB
facebook-www/ReactDOMServerStreaming-prod.modern.js +0.36% 159.14 kB 159.70 kB +0.55% 29.57 kB 29.73 kB
oss-experimental/react-dom/cjs/react-dom-server-legacy.browser.production.min.js +0.28% 66.09 kB 66.27 kB +0.28% 20.13 kB 20.19 kB
oss-experimental/react-dom/umd/react-dom-server-legacy.browser.production.min.js +0.27% 66.25 kB 66.43 kB +0.32% 20.53 kB 20.59 kB
oss-experimental/react-dom/cjs/react-dom-server.browser.production.min.js +0.26% 69.01 kB 69.19 kB +0.25% 21.26 kB 21.31 kB
oss-experimental/react-dom/umd/react-dom-server.browser.production.min.js +0.26% 69.14 kB 69.32 kB +0.27% 21.51 kB 21.57 kB
oss-experimental/react-dom/cjs/react-dom-server.bun.production.min.js +0.26% 69.67 kB 69.86 kB +0.24% 21.52 kB 21.58 kB
oss-experimental/react-dom/cjs/react-dom-server-legacy.node.production.min.js +0.26% 71.22 kB 71.41 kB +0.29% 21.81 kB 21.87 kB
oss-experimental/react-dom/cjs/react-dom-server.edge.production.min.js +0.25% 73.46 kB 73.65 kB +0.25% 22.75 kB 22.81 kB
oss-experimental/react-dom/cjs/react-dom-server.node.production.min.js +0.25% 73.74 kB 73.92 kB +0.26% 22.92 kB 22.98 kB
facebook-www/ReactDOMServerStreaming-dev.modern.js +0.21% 350.21 kB 350.94 kB +0.25% 78.02 kB 78.21 kB
facebook-www/ReactDOMServer-dev.modern.js +0.21% 355.02 kB 355.75 kB +0.24% 79.16 kB 79.36 kB
facebook-www/ReactDOMServer-dev.classic.js +0.20% 362.45 kB 363.17 kB +0.23% 80.81 kB 81.00 kB

Generated by 🚫 dangerJS against cc283ce

@acdlite acdlite merged commit 95c9554 into facebook:main Sep 14, 2023
2 checks passed
github-actions bot pushed a commit that referenced this pull request Sep 14, 2023
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 [95c9554](95c9554)
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
…book#27370)

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} />
}
```
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants