msw: Using MSW with Next.js causes stopping HMR/Fast Refresh

Describe the bug

Using MSW with Next.js causes stopping HMR/Fast Refresh because of unclosed SSE connections.

Environment

  • msw: 0.26.2
  • nodejs: 14.14.0
  • yarn: 2.4.1
  • Browser: Chromium 89.0.4389.82

To Reproduce

Steps to reproduce the behavior:

  1. Clone https://github.com/tkamenoko/msw-nextjs-hmr .
  2. Install deps: yarn .
  3. Start dev server: yarn dev .
  4. Open localhost:3000 in your browser.
  5. Show Network tab in DevTools.
  6. Click rendered links, and you will find that SSE connections between MSW and the dev server are not closed.
  7. After the number of connections reaches the limit, HMR will not work.
  8. Reload the page, but it will not complete: Waiting for available sockets

Expected behavior

A browser should receive changes and refresh the page. SSE connections between MSW and the dev server should be closed when connections between browser and MSW are closed.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 18 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Having the same Issue

  • msw v0.28.2
  • next v10.1.2

@kettanaito I think what @tkamenoko and I mean is that this issue is tracking HMR issue, not the solved cookies issue which maybe not related to this one.😂 So we can still discuss here.

I’ve created a simpler repo to reproduce the issue: https://github.com/saintwinkle/with-msw-next-app .

And here’s the process:

https://user-images.githubusercontent.com/4580163/112440392-3720df00-8d85-11eb-9646-9b8df73879ef.mov

If i’m missing something, let me know. Thanks!

Hey, @tkamenoko. Thanks for the follow-up. No need to raise an issue, this will be fixed with #649.

Hello, sorry to bother. This issue hasn’t been fixed, I’m suffering the same issue as above.

And not noly React fast refresh, other tools using HMR may have this issue too (Nuxt.js for sure). Better to reopen 😃

  • msw: 0.27.1
  • node: 14.16.0
  • npm: 7.6.3
  • browser: Chrome 89.0.4389.90

I have same problem with MSW + Next.js. Can we please reopen this issue?

Getting the same problem as well.