Browser-sync: browsersync reloads the browser when connection is restored (even though it doesn't need to reload)

Created on 24 Aug 2018  路  5Comments  路  Source: BrowserSync/browser-sync

Issue details

When a page has a high load (eg it takes 30 seconds to render) browsersync will have lost it's connection and on reconnect it refreshes, this keeps on going until the server is stopped

Steps to reproduce/test case

use browsersync, make a page do some heavy lifting for 30 seconds then watch as the page keeps refreshing just after crunching for a while

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

  • Browsersync [ 2.24.6 ]
  • Node [ 8.11.4 ]
  • Npm [ 5.6.0 ]

Affected platforms

  • [ ] linux
  • [ ] windows
  • [ ] OS X
  • [ ] freebsd
  • [ ] solaris
  • [x] other (android on samsung galaxy tab 3)

Browsersync use-case

  • [ ] API
  • [x] Gulp
  • [ ] Grunt
  • [ ] CLI

If CLI, please paste the entire command below

{cli command here}

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

    .init({
      server: distDir,
      ghostMode: false,
      reloadOnRestart: false,
      port: params.port || config.browserSyncPort || 3000,
      open: (typeof params.openBrowser === 'boolean') && params.openBrowser || config.openBrowser || false,
      middleware: function (req, res, cb) {
        // When using multiple languages, the root does not contain html files
        if (hasMultipleLocales && req.url === '/') {
          res.writeHead(302, { 'Location': `/${config.defaultLanguage || 'en'}/` });
          res.end();
          req.url = `/${config.defaultLanguage || 'en'}/`;
          return;
        }

        if (req.url.indexOf('.') > -1) {
          return cb();
        }

        const uri = url.parse(req.url);

        if (
          uri.pathname.length > 1
          && path.extname(uri.pathname) === ''
          && fs.existsSync(path.join(distDir, uri.pathname + '.html'))
        ) {
          req.url = uri.pathname + '.html' + (uri.search || '');
        }

        cb();
      }
    });

Most helpful comment

fixed in [email protected] :)

All 5 comments

I was experiencing something similar, and seemingly resolved it by increasing the init config object's socketio clients.heartbeatTimeout to be a minute.
e.g:

  ...
  socket: {
    clients: {
      heartbeatTimeout: 60000
    }
  }

Thanks for your quick reply @travomic, this might be exactly what I was looking for. I am currently not at work but I will give this a shot next monday morning and report my findings.

I noticed the same thing starting with 2.24.5 also! For me, it would appear when staying on any breakpoint longer than heartbeatTimeout... Changing the timeout value indeed helped...

I find it strange that the problem didn't occur prior to 2.24.5, actually...

@travomic I just noticed my comment was not sent (tried that a week ago on my phone).

Setting the heartbeatTimeout option actually resolves the issue.

If you want you can close this issue and archive it for future reference since this is not something you can really do much about (browsers dropping sockets because of timeouts).

fixed in [email protected] :)

Was this page helpful?
0 / 5 - 0 ratings