question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SSE Bypass for HMR

See original GitHub issue

Describe the bug

When developing on the Next.js with next dev, No problem for a while, but suddenly the server becomes unresponsive.

Environment

  • msw: 0.29.0
  • nodejs: 14.16.0
  • npm: 0.0.0
  • next: 10.2.3

Please also provide your browser version.

Chrome: Version 91.0.4472.164 (Official Build) (x86_64)

To Reproduce

Steps to reproduce the behavior:

  1. npm run next dev
  2. Edit some code many times.
  3. Suddenly the server becomes unresponsive.

Expected behavior

Server always responds.

Screenshots

The below capture is the Network tab when no response is returned.

image

Workaround

It looks like there is a problem in webpack-hmr?page=xxxx. As a workaround, I added the below SSE Bypass in generated mockServiceWorker.js. Then, I was able to solve the problem that the response did not come back.

self.addEventListener("fetch", function (event) {
  const { request } = event;

  // Bypass server-sent events.
  if (request.headers.get("accept") === "text/event-stream") {
    return;
  }

  // Bypass navigation requests.
  if (request.mode === "navigate") {
    return;
  }
  ...
}

This Bypass is useful to us, but what do you think?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
kettanaitocommented, Jul 28, 2021

Analyzing NextJS

Here’s where the EventSource is being established on the client:

evtSource = getEventSourceWrapper({
  path: `${assetPrefix}/_next/webpack-hmr?page=${currentPage}`,
  timeout: 5000,
})

next.js/packages/next/client/dev/on-demand-entries-utils.js

The server-side of NextJS just bypasses this route:

It appears that the SSE established is not coming from webpack but from NextJS. Huh, so there’s no straightforward way to put this in an integration test in this repo.

2reactions
takefumi-yoshiicommented, Jul 27, 2021

Do you think this may be the root cause for #785 and #788?

I feel that both are related, but I can’t reply without reproduce environment. But I think it’s worth having a reporter try this bypass. The same is true for developer who do not need to intercept SSE.

Please, would you be interested in opening a pull request with your fix?

Of course! I hope it helps until it is fundamentally resolved. Wait a minute. @kettanaito

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blackreach Bypass SSE - Skyrim Special Edition - Nexus Mods
About this mod. Adds a lever that opens the gate at the Tower of Mzark to allow quick access to the Elder Scroll...
Read more >
HMR59.pdf - National Weather Service
HMR 59 PMP estimates for a portion of southern California at 10 mi2 ... or are forced to bypass terrain features that act...
Read more >
Intertidal intercepted sediment at jetties along the Gulf of ...
Sand bypassing is one of the promising solutions to rectify jetty-induced coastal erosion. Estimating alongshore sediment transport rate and ...
Read more >
Techniques for Shared Resource Management in Systems ...
tel MMX [162, 296] and Intel SSE [164] also apply SIMD in order to improve performance. As ... is to bypass the cache...
Read more >
3745 Communication Controller Hardware Maintenance ...
The main storage. • The storage control, equipped with a direct memory access (OMA). 1-6 IBM 3745 Hardware Maintenance Reference (HMR).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found