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

WebSocket connection to 'ws://localhost:3000/_next/webpack-hmr' failed: init @ websocket.js?a9be:46 #34342

Closed
slemac opened this issue Feb 14, 2022 · 2 comments · Fixed by #34352
Labels
Webpack Related to Webpack with Next.js.

Comments

@slemac
Copy link

slemac commented Feb 14, 2022

What example does this report relate to?

GetServerSideProps axios and return notFound: true,

What version of Next.js are you using?

12.0.10

What version of Node.js are you using?

16.13.0

What browser are you using?

Chrome

What operating system are you using?

Windows

How are you deploying your application?

next dev

Describe the Bug

On the client side, in the browser it shows me the following error repeatedly without stopping:
WebSocket connection to 'ws://localhost:3093/_next/webpack-hmr' failed:
init @ websocket.js?a9be:46

and in the powershell it shows me the following message repeatedly without stopping:
Error: Request failed with status code 404
at createError (C:\Users\slema\source\repos\upfuller-client\node_modules\axios\lib\core\createError.js:16:15)
at settle (C:\Users\slema\source\repos\upfuller-client\node_modules\axios\lib\core\settle.js:17:12)
at IncomingMessage.handleStreamEnd (C:\Users\slema\source\repos\upfuller-client\node_modules\axios\lib\adapters\http.js:322:11)
at IncomingMessage.emit (node:events:402:35)
at IncomingMessage.emit (node:domain:475:12)
at endReadableNT (node:internal/streams/readable:1343:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)

Expected Behavior

that errors are not repeated many times. It seems that it enters an infinite loop of errors

To Reproduce

  1. create a project with npx create-next-app@latest --ts
  2. in page/index.tsx is added getServerSideProps:
    export const getServerSideProps: GetServerSideProps = async ({ params, res, locale, }) => { try { const { data } = await axios.get( "https://jsonplaceholder.typicode.com/todos/sppsppspsps" ); console.log(data); return { props: { ...data }, }; } catch (error: any) { res.statusCode = 404; console.log(error); console.log("error"); return { notFound: true, props: {}, }; } };
  3. run next dev and access to http://localhost:300/
    carbon (1)
    err2
    err1

Repository:
https://github.com/slemac/my-app-2

@slemac slemac added the bug Issue was opened via the bug report template. label Feb 14, 2022
@balazsorban44 balazsorban44 added the Webpack Related to Webpack with Next.js. label Feb 15, 2022
@balazsorban44
Copy link
Member

Thank you, I could reproduce it with this simplified code:

//pages/index.js
const Home = () => null
export default Home

export function getServerSideProps() {
  console.log("called")
  return { notFound: true }
}

Two small notes in the meantime, when returning notFound: true, you should not need to return props also, and res.statusCode = 404 is also unnecessary as returning notFound already indicates it.

See https://nextjs.org/docs/api-reference/data-fetching/get-server-side-props#notfound

@balazsorban44 balazsorban44 added kind: bug and removed bug Issue was opened via the bug report template. labels Feb 15, 2022
@kodiakhq kodiakhq bot closed this as completed in #34352 Feb 16, 2022
kodiakhq bot pushed a commit that referenced this issue Feb 16, 2022
…ned (#34352)

Fixes: #34342

Visiting the following page will call gSSP indefinitely in a loop and logs errors from `on-demand-entries-client`:
```js
const Home = () => null
export default Home
        
export function getServerSideProps() {
  console.log("gssp called")
  return { notFound: true }
}
```

We should not keep fetching the page if it returns 404 as  it can introduce unnecessary data requests.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`



Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
@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 Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Webpack Related to Webpack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants