Menu

The Server Action That Ran Twice, but Only on localhost
πŸ“°

The Server Action That Ran Twice, but Only on localhost

DEV Community: reactΒ·Mohsen FallahnejadΒ·7 days ago
#5GKrApnX
#devtoreact#devto#dev#call#next
Reading 0:00
15s threshold

Picture a "mark as read" feature. Open a notification, and a Server Action flips it to read in the database and bumps a counter. You add a console.log to the action to watch it work, open the page in next dev , and the terminal prints:

[markAsRead] call #1 [markAsRead] call #2

Enter fullscreen mode

Exit fullscreen mode

One page load, two calls. Every time.

I rebuilt that exact setup on this blog's codebase (Next.js 16.4, React 19) as a ten-line test page, and got the same thing: two POST requests with the same next-action id in the network tab, two log lines on the server.

The wrong turn: blaming Next.js

Two calls from one load looks like a framework bug. Maybe Next.js retries actions. Maybe the page renders twice on the server and each render fires the action. Maybe HMR left an old copy of the component mounted.

None of those hold up.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.