form icon indicating copy to clipboard operation
form copied to clipboard

Next Server Actions example does not work

Open rburgst opened this issue 1 year ago • 8 comments

Describe the bug

The next server action example does not work currently

https://tanstack.com/form/latest/docs/framework/react/examples/next-server-actions

<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can't resolve 'tunnel-agent' in '/home/projects/vbwimykwkg.github/node_modules/sharp'
<w> while resolving 'tunnel-agent' in /home/projects/vbwimykwkg.github/node_modules/sharp to a directory
 ✓ Compiled / in 5.9s (534 modules)
 GET / 200 in 6074ms
<w> [webpack.cache.PackFileCacheStrategy]

When submitting the form, the useTransform code blows up.

Your minimal, reproducible example

https://stackblitz.com/github/tanstack/form/tree/main/examples/react/next-server-actions?embed=1&theme=dark&preset=node&file=src/index.tsx

Steps to reproduce

  1. Open the stackblitz
  2. notice the sharp warning about tunnel-agent
  3. submit the form
  4. BOOM

Expected behavior

The example should work and the server action should be invoked.

How often does this bug happen?

Every time

Screenshots or Videos

Image

Platform

  • OS: Mac OSX Sequoia
  • Browser: Arc

TanStack Form adapter

None

TanStack Form version

0.33.0

TypeScript version

5.6.2

Additional context

No response

rburgst avatar Oct 02 '24 06:10 rburgst

In Stackblitz and codesandbox if I press the "Submit" button, I get Image

rburgst avatar Oct 02 '24 06:10 rburgst

ok, I got it to work with the sample: https://stackblitz.com/edit/tanstack-form-bz8cz5?file=README.md

rburgst avatar Oct 02 '24 06:10 rburgst

Am still getting the error and https://github.com/TanStack/form/issues/967#issuecomment-2387745999 this still have the issue , how did you get to work , what is the problem ? Image

anisharaz avatar Oct 03 '24 04:10 anisharaz

@anisharaz see the PR #970

rburgst avatar Oct 03 '24 05:10 rburgst

Also for posterity: I have a next setup where also server side logging is shown in the browser console, however, for unknown reasons the logs from the server action never showed up in my browser console. They did show up in the server console though. Also note that if you dont get your POST values on the action, then your <input> fields are missing the name attribute.

rburgst avatar Oct 03 '24 05:10 rburgst

@rburgst Thankyou that fixed it , but a new problem arised or it exist am not sure, while submitting while the fields are empty the request goes to server and server validation invalidates the and responce with the message and client side validation run too. Does it makes sence to make to send request to server while the client validation is failing Image Image

anisharaz avatar Oct 03 '24 11:10 anisharaz

@anisharaz this looks like a bug in tanstack form to me

rburgst avatar Oct 05 '24 14:10 rburgst

actually, this is due to the fact that if you did not touch the form state then "canSubmit" is true, only once you make any modification then the validation state is updated, see also https://tanstack.com/form/latest/docs/framework/react/guides/validation#preventing-invalid-forms-from-being-submitted

rburgst avatar Oct 05 '24 14:10 rburgst

As far as I can tell, this was fixed in #970, please feel free to open a new issue if there's something I missed

crutchcorn avatar Nov 25 '24 06:11 crutchcorn