Server actions are not progressively enhanced if imported from a client component #52137
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.
Verify 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
Increment counter
next toServer form
, you will see that it work and browser gets reloadedIncrement counter
next toClient form
, it won't workDescribe 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 :
Here is the html generated for the client component :
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 ofnext@13.4.8-canary.1
as the generated HTML for the client component is the same for13.4.8-canary.1
: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
The text was updated successfully, but these errors were encountered: