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

Unexpected Page Reload after Pausing in Debugger #1591

Closed
2 of 5 tasks
janmattfeld opened this issue Aug 15, 2018 · 27 comments · May be fixed by bizoton19/hdwih-hugo-cms#4
Closed
2 of 5 tasks

Unexpected Page Reload after Pausing in Debugger #1591

janmattfeld opened this issue Aug 15, 2018 · 27 comments · May be fixed by bizoton19/hdwih-hugo-cms#4

Comments

@janmattfeld
Copy link

janmattfeld commented Aug 15, 2018

Steps to reproduce/test case

  1. Add a breakpoint in Chrome debugger
  2. Wait until execution stops and hold on for a few seconds
  3. Continue via F8 to or click the play button
  4. Unexpectedly, the entire page is refreshed and the code runs from beginning

Please specify which version of Browsersync, node and npm you're running

  • Browsersync [2.24.6]
  • Node [v10.8.0]
  • Npm [6.2.0]

Affected platforms

  • Windows 10 x64

Browsersync use-case

  • API
  • Gulp
  • Grunt
  • CLI

for all other use-cases, (gulp, grunt etc), please show us exactly how you're using Browsersync

browserSync.init({
  server: ["./webapp/", "./webapp/test", "./"],
  index: "index.html",
  notify: false
});

References

There are already two Stack Overflow posts:

And a message in Slack:

@guifes
Copy link

guifes commented Aug 16, 2018

This is extremely annoying. Can anyone point to the most up-to-date version that does not have this problem?

@singlow
Copy link

singlow commented Aug 16, 2018

I have this problem as well. I have had some success by increasing the client heartbeat timeout:

browserSync.init({
...
    socket: {
        clients: { heartbeatTimeout: 60000 } 
    }
...
});

@shakyShane
Copy link
Contributor

@janmattfeld I'm trying to recreate this, without success - is there any way you could put together a minimal example that shows the bug?

@gama410
Copy link

gama410 commented Aug 28, 2018

I already commented on this issue which seems to be related. After trying several releases, I found out the problem started with 2.24.5.

I "fixed" it the same way @singlow described (although a proper fix would be very appreciated ;) )

@chiplay
Copy link

chiplay commented Sep 5, 2018

We are having the same issue, and heartbeatTimeout didn't seem to do the trick for us. Downgrading to 2.23.7 prevents the reload.

@aj-dev
Copy link

aj-dev commented Sep 6, 2018

Same issue here. Increasing heartbeatTimeout didn't help.

@gama410
Copy link

gama410 commented Sep 6, 2018

Actually, I noticed that increasing heartbeatTimeout didn't really fix the problem either. If I pause on a breakpoint for a few seconds, browsersync seems to reload the page anyway, only it will wait until after heartbeattimeout expires to perform the reload...

@janmattfeld
Copy link
Author

@shakyShane I uploaded the most minimal example I could imagine and attached it to the first post.

npm install
gulp

Then set a breakpoint in the timeout within app.js, wait 20 seconds before continuing and you will (hopefully) experience the same unexpected page reload as we do.

@chiplay
Copy link

chiplay commented Sep 9, 2018

Small update - did some experimentation with proxy.target and socket.domain options and found a combo that seems to prevent the reload from happening. I still get a console error Invalid Frame Header after 60 seconds (the initial websocket connection seems to fail...) but browser-sync continues working just fine in spite of the error.

Not sure how helpful that is, but I figured I'd comment just incase!

EDIT: Still reloads when paused on breakpoints... so probably not a real solution/lead.

CiGit added a commit to Heigvd/Wegas that referenced this issue Sep 10, 2018
page reloads when debugging and stoping on breakpoints.
see : BrowserSync/browser-sync#1591
@axten
Copy link

axten commented Sep 11, 2018

same problem here, downgrade works

@pioug
Copy link

pioug commented Sep 19, 2018

I have no issue with browser-sync@2.24.4, so I digged a bit:

  1. I think the issue started here with the update of socket.io@2.1.1 dd70eba
  2. engine.io has been updated in that version of socket.io socketio/socket.io@b1941d5
  3. Default value for timeout was decreased in engine.io@3.2.0 socketio/engine.io@65b1ad1

Setting heartbeatTimeout: 60000 works also for me 👍

@mpelekh
Copy link

mpelekh commented Sep 23, 2018

Same problem.

I have this problem as well. I have had some success by increasing the client heartbeat timeout:

browserSync.init({
...
    socket: {
        clients: { heartbeatTimeout: 60000 } 
    }
...
});

The increasing of heartbeatTimeout doesn't help in all cases. It just reduces the possibility of the page refreshing.

It works in cases when heartbeatTimeout is not ended. What I mean by that is the following.

Imagine that you have set the timeout to 60000 ms. And just 2 seconds have passed from the beginning of the timeout cycle. And then you stop the application by breakpoint for 10 seconds. 2 + 10 = 12 seconds, so the application will resume work as needed without the page refreshing.

But in case when 58 seconds have passed from the beginning of timeout cycle, for instance, and then the application is stopped by the breakpoint for 10 seconds. 58 + 10 = 68 seconds. It more then heartbeat timeout, so the application will be refreshed by browsersync after resuming.

@chiplay
Copy link

chiplay commented Sep 24, 2018

I can confirm @mpelekh's report as well. Increasing the heartbeatTimeout doesn't prevent the reload, it just delays it. It my case, if I set a breakpoint, hit it, and then immediately resume, then wait until the 60 seconds is up, it will refresh the browser.

@fheidrich
Copy link

Please help, this is very annoying.

@axten
Copy link

axten commented Sep 25, 2018

as mentioned before, a downgrade to 2.23.7 works

@chiplay
Copy link

chiplay commented Sep 25, 2018

FWIW version 2.23.7 has a good number of dependencies that are flagged by npm 6 as security issues. Ideally we can find a fix to prevent the full BrowserReload event when the socket handshake closes/reopens

@maynir
Copy link

maynir commented Sep 26, 2018

This is so annoying, it happens to me too.
The change in heartbeatTimeout helped for a bit longer waiting time, but not too much.
I am using version 2.24.6, should I downgrade browser sync?

@cenfun
Copy link

cenfun commented Sep 27, 2018

Same issue here. I just roll back my browser-sync to version 2.24.1, it works. hope it could helps you fixing it in latest version.

@chiplay
Copy link

chiplay commented Sep 27, 2018

Doing some more sleuthing on this issue, here is what I'm finding:

The reload starts when one of the polling request returns a 400 with this response: {"code":1,"message":"Session ID unknown"}
image

When the new socket is created, this gets called with an index > 0: https://github.com/BrowserSync/browser-sync/blob/master/client/lib/messages/Connection.ts#L24 which triggers the refresh. I removed that last line locally and it prevents the reload and continues to work as expected with the new connection. Going to submit a PR with the change.

@chiplay
Copy link

chiplay commented Sep 27, 2018

That last comment was premature, removing that line from Connection.ts causes other issues.

@scottschafer
Copy link

I also "fixed" the problem by downgrading. This is a severe issue.

@shakyShane
Copy link
Contributor

Hi all, this is being worked on as a priority - thanks for your patience :)

@shakyShane
Copy link
Contributor

Ok I have a fix in place, could anyone in this thread give the alpha release a test-drive?

npm i browser-sync@2.25.1-alpha.0

@shakyShane
Copy link
Contributor

Breakdown of cause + fix:

engine.io (that socket.io uses under the hood) updated some default values - this meant that whilst the debugger was paused inside applications, the connection dropped.

The moment the debugger stops, a new 'connection' event is received via socket.io (as it manages to re-connect imediately) and then some code in the Browsersync client would cause a full-page reload since this re-connection event was not the 'first' one - this was done to allow situtations where a computer is put to sleep, or anything else that could cause a drop in connection.

I'm no longer confident it was a good idea since this bug came around - and it's also not a good idea to increases timeouts etc.

The simple solution is to no-longer reload the page automatically following a re-connection :)

export function incomingConnection(
    xs: Observable<IBrowserSyncOptions>,
    inputs: Inputs
) {
    return xs.pipe(
        withLatestFrom(inputs.option$.pipe(pluck("logPrefix"))),
        mergeMap(([x, logPrefix], index) => {
-            if (index === 0) {
               return of<any>(
                    setOptions(x),
                    Log.overlayInfo(`${logPrefix}: connected`)
                );
-            }
-            return reloadBrowserSafe();
        })
    );
}

@Chandra01B
Copy link

Is this issue is resolved with 2.25.1 ?

@alexpmorris
Copy link

alexpmorris commented Oct 15, 2018

just had to add how happy I am as well that this one was nipped in the bud, it's been driving me bonkers as well! :D lol

@shakyShane
Copy link
Contributor

@alexpmorris glad to hear it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet