Open atomiechen opened 8 months ago
Plus: the patch server component needs to execute the nop()
function to make it actually import the server action.
Where you able to fix this?
I'm on "next": "14.2.7". Encountered same problem with data in memory. But can't successfully apply suggested workaround with Nop
component :(
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/next-js-server-action-issue-lxjtkg
To Reproduce
This is a demo that use buttons (client components) to call server actions (from
actions.ts
) to mutate server-side data array (indata.ts
).Steps:
app/page.tsx
source.<Nop />
. It is a patch server component I wrote, which only calls a do-nothing server actionnop()
fromactions.ts
. Firstly keep it commented out.<Nop />
, and again try the buttons. You will see they work magically with UI updates.Relevant code:
Current vs. Expected behavior
Current:
<Nop />
inpage.tsx
: clicking buttons will not update the UI, and will modify an invisible array on server (which can be verified through server log, or clicking remove button multiple times to see an error of empty array).<Nop />
inpage.tsx
: the buttons work as magic.Expected: with or without the patch component
<Nop />
, clicking the buttons (client components) should correctly add or remove items of the correct server-side data array, and the page UI should be updated accordingly.Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure, Dynamic imports (next/dynamic)
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local)
Additional context
Observations:
<Nop />
) to actually import something from the server action file (actions.ts) to make client components have access to the right data array in server's memory.My temp solution: patch such a nop server component that imports from the server action file; or pass the server action as prop to client components.