webpack-livereload-plugin icon indicating copy to clipboard operation
webpack-livereload-plugin copied to clipboard

too many reloads, is my delay ignored?

Open anvlkv opened this issue 5 years ago • 17 comments

I've set a delay already

new LiveReloadPlugin({
            appendScriptTag: true,
            delay: 3000
        })

and

watchOptions: {
        aggregateTimeout: 300,
        ignored: ['node_modules']
    },

Still my browser tries to reload 30 times and cancels the request.

anvlkv avatar Nov 26 '19 10:11 anvlkv

What do you mean by "cancels the request"?

Could you make an example repo with the issue?

statianzo avatar Jan 09 '20 15:01 statianzo

Same here

infabo avatar Jan 20 '20 13:01 infabo

What do you mean by "cancels the request"?

open network panel in chromium and there you can see these cancelled requests.

infabo avatar Jan 20 '20 13:01 infabo

I got the same problem. But the delay is working. It just notifies once after delay but the assets are getting reloaded multiple times with a new ?livereload= get parameter. Maybe the appendScriptTag option is the problem? Tried without appendScriptTag and got the same error.

web-mi avatar Feb 14 '20 13:02 web-mi

If you could share an example repository with the problem, I'd be glad to take a look.

statianzo avatar Feb 14 '20 15:02 statianzo

I digged into it and found the problem. Every file which is not a css or image file will trigger a browser reload in tiny-lr. (Note: for every single file)

If you add the following configuration to your LiveReloadPlugin options it will trigger a reload for every file changed expecting css and image files:

new LiveReloadPlugin({
    liveCSS: false,
    liveImg: false,
})

The problem happens if you build multiple files in your webpack configuration:

module.exports = {
    entry: {
        first: [
            './js/first.js',
            './js/first.css',
        ],
        second: [
            './js/second.js',
            './js/second.css',
        ],
        third: [
            './js/third.js',
            './js/third.css',
        ],
    },
    // ...
};

This will create/renew the following assets at once and will trigger them as changed in webpack watch: (Don't know why it rebuilds everything if i just changing first.js for example) assets/first.js assets/first.css assets/first.js.map assets/second.js assets/second.css assets/second.js.map assets/third.js assets/third.css assets/third.js.map

Every single file will now trigger a file reload or page reload depending on the configuration. And every new request will kill the previous one which will result in the high load and the failing requests in the console.

Currently i don't know a good solution. notifyClients needs any files to trigger a reload. For js you could just always give a non existing .js file and it will reload but thats a really bad solution. There is a open PR for just sending changed files. Maybe this will work with this webpack configuration?

web-mi avatar Feb 14 '20 22:02 web-mi

I found this issue for multiple files rebuilds so maybe the first solution will be fixing the multiple created files. https://github.com/webpack/webpack/issues/7007

web-mi avatar Feb 14 '20 22:02 web-mi

#59 Should add the ablity to fix all problems by setting useSourceHash to true

web-mi avatar Feb 16 '20 03:02 web-mi

@web-mi please can you merge the change in webpack 5.

vishal9p avatar Aug 04 '21 11:08 vishal9p

@vishal9p Everything should already been merged into the latest version.

web-mi avatar Aug 04 '21 11:08 web-mi

@vishal9p Everything should already been merged into the latest version.

@web-mi still i can see the issue i am using latest webpack 5

You mentioned there is one open PR which is for just sending changed files.please can you share it

And for me i cannot use useSourceHash facing some other issue saying content and map not valid

vishal9p avatar Aug 04 '21 11:08 vishal9p

I think i mean the #33 but it should be required anymore. Maybe with the latest changes useShourceHash gets broken? Could you share your error?

And could you try useSouceSize instead?

web-mi avatar Aug 04 '21 11:08 web-mi

I think i mean the #33 but it should be required anymore. Maybe with the latest changes useShourceHash gets broken? Could you share your error?

And could you try useSouceSize instead?

@web-mi it worked with useSouceSize. But this changes are not present in 3.0.1 so please can you publish your changes with new version maybe 3.0.2

vishal9p avatar Aug 04 '21 12:08 vishal9p

You mean the changes from #33 are not present in 3.0.1? These changes are not required anymore because of the new options useSourceHash and useSourceSize.

web-mi avatar Aug 04 '21 12:08 web-mi

useSourceHash

In 3.0.1 in index.js we are not seeing useSourceSize prop.but this is present in master.I think you need to publish a newer version

vishal9p avatar Aug 04 '21 12:08 vishal9p

Ahh sorry. You are right. The latest change not published. Maybe in the latest version useSouceHash is already working again.

@statianzo Could you publish a new version with the latest changes?

web-mi avatar Aug 04 '21 13:08 web-mi

Released as 3.0.2

https://unpkg.com/browse/[email protected]/index.js

statianzo avatar Aug 04 '21 13:08 statianzo