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

Server actions are not progressively enhanced if imported from a client component #52137

Closed
1 task done
Fredkiss3 opened this issue Jul 3, 2023 · 3 comments
Closed
1 task done
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked Pages Router Related to Pages Router.

Comments

@Fredkiss3
Copy link
Contributor

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:19 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8103
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: 8.6.2
    Relevant Packages:
      next: 13.4.8-canary.15
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Data fetching (gS(S)P, getInitialProps)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/Fredkiss3/next-client-server-action-bug

To Reproduce

  1. clone & start the server
  2. disable JavaScript in the browser and reload the page
  3. click on the button Increment counter next to Server form, you will see that it work and browser gets reloaded
  4. click on the button Increment counter next to Client form, it won't work

Describe the Bug

When importing server actions from a client component, next seems to not initialize them so that they could work without JavaScript enabled or before the JS has finished loading. The generated HTML in SSR is different wether the server action is imported from a server component or a client component.

Here is the html generated for the server component :

<form action="" enctype="multipart/form-data" method="POST">
  <input type="hidden" name="$ACTION_ID_8e9a737600b0f7123502bed2e2e35f84115a82c7" />
  <button> Increment counter </button>
</form>

Here is the html generated for the client component :

<form action="javascript:throw new Error('A React form was unexpectedly submitted.')">
  <button>Increment counter</button>
</form>

We can see clearly that a hidden input indicating the correct action is missing and there are props that are missing on the form.


This bug seems to have been introduced in next@13.4.8-canary.2 as of next@13.4.8-canary.1 as the generated HTML for the client component is the same for 13.4.8-canary.1 :

<form action="" enctype="multipart/form-data" method="POST">
  <input type="hidden" name="$ACTION_ID_8e9a737600b0f7123502bed2e2e35f84115a82c7">
  <button>Increment counter</button>
</form>

i suspect this PR to be the cause : #51723 (though i may be wrong).

Expected Behavior

Server actions in client components should also be progressively enhanced, and the generated HTML in SSR should be the same.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@Fredkiss3 Fredkiss3 added the bug Issue was opened via the bug report template. label Jul 3, 2023
@github-actions github-actions bot added area: app App directory (appDir: true) Pages Router Related to Pages Router. labels Jul 3, 2023
@Fredkiss3
Copy link
Contributor Author

It seems like this issue will be fixed after this PR has been merged : #52005

@shuding
Copy link
Member

shuding commented Jul 4, 2023

Exactly fixed by #52005

@shuding shuding closed this as completed Jul 4, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 3, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Aug 3, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked Pages Router Related to Pages Router.
Projects
None yet
Development

No branches or pull requests

2 participants