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

API being called twice #37715

Closed
1 task done
YasminCastro opened this issue Jun 15, 2022 · 4 comments
Closed
1 task done

API being called twice #37715

YasminCastro opened this issue Jun 15, 2022 · 4 comments
Labels
bug Issue was opened via the bug report template.

Comments

@YasminCastro
Copy link

Verify canary release

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

Provide environment information

Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
Binaries:
Node: 16.15.1
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 12.1.6
react: 18.1.0
react-dom: 18.1.0

What browser are you using? (if relevant)

Chrome 102.0.5005.63

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

I'm building an application with Next Js, and I'm creating API's for it. But there's a bug that I can't solve. When I make a call to the API within the project itself or using webhooks the api is called twice. I tried to create a new project, change the version of next but it keeps making the API request twice. Here I took a print of the request being called twice Snipaste_2022-06-14_17-33-00

I don't know if this is just happening with my projects, or if it's a bug outside of next...

Expected Behavior

API running only one time when is call.

To Reproduce

Make a simple endpoint and call it within the application itself or via webhooks.

@YasminCastro YasminCastro added the bug Issue was opened via the bug report template. label Jun 15, 2022
@awareness481
Copy link
Contributor

This is change in React 18 dev mode, where useEffect will run twice if you re using Strictmode.

https://reactjs.org/blog/2022/03/29/react-v18.html#:~:text=To%20help%20surface%20these%20issues%2C%20React%2018%20introduces%20a%20new%20development%2Donly%20check%20to%20Strict%20Mode.%20This%20new%20check%20will%20automatically%20unmount%20and%20remount%20every%20component%2C%20whenever%20a%20component%20mounts%20for%20the%20first%20time%2C%20restoring%20the%20previous%20state%20on%20the%20second%20mount.

@SukkaW
Copy link
Contributor

SukkaW commented Jun 15, 2022

#35822
#36920
#37274

@YasminCastro
Copy link
Author

Thank you so much, I managed to fix it with your guys help :D

@github-actions
Copy link
Contributor

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 locked as resolved and limited conversation to collaborators Jul 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

3 participants