BrowserSync / browser-sync

Keep multiple browsers & devices in sync when building websites. https://browsersync.io
https://discord.gg/2d2xUThp
Apache License 2.0
12.18k stars 758 forks source link

2.18.13: editing `content.php` causes browsers to reload, without any matching watcher #1469

Open lkraav opened 6 years ago

lkraav commented 6 years ago

Issue details

bs-config.js only defines watching a specific set of style.css files.

module.exports = {                                                                                                                                                                                                   
    "files": [                                                                                                                                                                                                       
        "wp-content/themes/*/style.css"                                                                                                                                                                     
    ],                                                                                                                                                                                                               
    "watchOptions": {                                                                                                                                                                                                
        ignoreInitial: true,                                                                                                                                                                                         
        ignored: "*.php"                                                                                                                                                                                             
    },
...

But for some strange reason, editing wp-content/themes/something/content/content.php causes browsers to reload the page. I want this to stop.

No match "file change" event is listed in debug log, just says "Reloading Browsers..."

dets  19 16:32:32 conversionready browser-sync[9082]: [BS] Reloading Browsers...
dets  19 16:32:34 conversionready browser-sync[9082]: [BS] Browser Connected: Firefox, version: 57.0

I'm confused about why this is happening. It has started happening recently, maybe in the minor updates of the last couple of months?

The only connecting piece I'm able to detect is the watcher's list also including ...content/ path as part of wp-content/, but no idea if this plays any part here.

Steps to reproduce/test case

Description above.

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

Affected platforms

Browsersync use-case

If CLI, please paste the entire command below

node_modules/.bin/browser-sync start --config bs-config.js

XhmikosR commented 6 years ago

I confirm this happens with other file types too. Started to happen after 2.18.3.

It doesn't happen with all text/code editors though. For example with Notepad++ it doesn't happen.

I'm on Windows and I'm using browser-sync via gulp.

EDIT: Oh, and it seems, it reloads only the first time I open the file; if I close and re-open the same file, it doesn't have the bogus reload.

lkraav commented 6 years ago

@XhmikosR oh, interesting. I'm on Linux + vim.

Can you add a few details about what you're seeing: what are your specific file names causing bogus reloads?

XhmikosR commented 6 years ago

The filenames don't seem to matter. I can't find something common. Only thing I know for sure is that it doesn't happen with all editors.

shakyShane commented 6 years ago

@lkraav sounds like it could be because of swap files, try something like

module.exports = {                                                                                                                                                                                                   
    "files": [                                                                                                                                                                                                       
        "wp-content/themes/*/style.css"                                                                                                                                                                     
    ],                                                                                                                                                                                                               
    "watchOptions": {                                                                                                                                                                                                
        ignoreInitial: true,                                                                                                                                                                                         
        ignored: ["*.php", "**/*.swp"]                                                                                                                                                                                             
    }
}
lkraav commented 6 years ago

So the trick seems to be about properly globbing ignored **/*.php, like @shakyShane suggested for *.swp. I'm not getting reloads anymore.

It is still a mystery why ignored has to be used, and why content.php specifically triggers a reload. There are other .php files in that same directory, they don't cause a reload.

XhmikosR commented 6 years ago

I personally don't have any of those set. My config is this:

snippetOptions: {
    // Provide a custom Regex for inserting the snippet.
    rule: {
        match: /<\/body>/i,
        fn(snippet, match) {
            return snippet + match;
        }
    }
},
server: {
    baseDir: buildDir
}
XhmikosR commented 6 years ago

@shakyShane @lkraav: it seems the issue is fixed, at least for me on Windows with 2.23.2.

lkraav commented 6 years ago

@XhmikosR thanks for reporting. Any thoughts on which commit may have fixed it?

XhmikosR commented 6 years ago

No idea which commit fixed, but it is fixed for me :)

XhmikosR commented 6 years ago

Hmm, spoke too soon. It still happens for some file types.