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

[BUG] using notFound() in server action is handled as successful action #325

Open
2 tasks done
maltesa opened this issue Feb 19, 2025 · 3 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@maltesa
Copy link

maltesa commented Feb 19, 2025

Are you using the latest version of this library?

  • I verified that the issue exists in the latest next-safe-action release

Is there an existing issue for this?

  • I have searched the existing issues and found nothing that matches

Describe the bug

The following code logs Success. to the browsers console.

// action.ts
export const userAction  = userActionClient.action(async () => {
  notFound()
})

// Component.tsx
// ...
  const { execute } = useAction(updateAssignmentSettingsAction, {
    onSuccess: () => console.log('Success.'),
    onError: () => console.log('Error'),
  })

Reproduction steps

Call notFound() in a server action.

Expected behavior

I expected the onError callback to fire.

Link to a minimal reproduction of the issue

none

Operating System

macOs

Library version

7.10.4

Next.js version

15.1.5

Node.js version

22

Additional context

No response

@maltesa maltesa added the bug Something isn't working label Feb 19, 2025
@IPJT
Copy link

IPJT commented Feb 20, 2025

Same thing if the device looses network connection. Seems very weird

@TheEdoRan
Copy link
Owner

TheEdoRan commented Mar 3, 2025

This is the correct behavior for all next/navigation functions at the moment, but I can understand that it might be confusing because users expect notFound() and forbidden() to trigger onError() instead. However, I believe redirect() should continue to trigger onSuccess() (as has already been explained in various issues/discussions in the past). What do you think? I could make notFound() and forbidden() trigger onError() in v8, which would be a breaking change.

@maltesa
Copy link
Author

maltesa commented Mar 3, 2025

Yes, right. Didn't think about, that redirect throws too.

What do you think? I could make notFound() and forbidden() trigger onError() in v8, which would be a breaking change.

That sounds sensible to me. I would love to see it in the v8.

Thank you for this great library 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants