NekR / offline-plugin

Offline plugin (ServiceWorker, AppCache) for webpack (https://webpack.js.org/)
MIT License
4.52k stars 295 forks source link

prevent setAssets from modifying original externals array #450

Closed ahlec closed 5 years ago

ahlec commented 5 years ago

When using this plugin with wds and hot reloading, we noticed that as we reloaded, we'd receive an increasing number of warnings from the plugin with every reload. There'd be no warnings at first, then the first reload, there'd be one warning about how we should put a resource into externals, then a second reload there'd be warnings about all of our external resources.

I tracked it down to setAssets, which is being modified as it checks the externals to ensure they're defined. However, that means that multiple entries into this function destroy the original array, and produce these warnings. During the initial build, we'd have our array full; first reload, we'd have it slightly empty; second reload and forward, the externals array would be empty.

The change here seems like the simplest fix to the problem, and I don't believe should introduce any unexpected issues. I've confirmed that it does resolve the problem on our end.

NekR commented 5 years ago

Hey @ahlec. Thanks for the PR and sorry for delay.

It indeed seems to be working fine as all the tests pass. I'm going to go ahead and merge this. Hopefully will be able to cut a new release soon. Thanks again.