From cc1a1e751b893143ac61a74c18c84a1b46cdc9fc Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Tue, 3 Aug 2021 18:37:48 +0200 Subject: [PATCH] Add some additional HMR cleanup for dev --- src/vector/devcss.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/vector/devcss.ts b/src/vector/devcss.ts index 1937ca949d..75ce2b2af2 100644 --- a/src/vector/devcss.ts +++ b/src/vector/devcss.ts @@ -28,6 +28,19 @@ limitations under the License. * For more details, see webpack.config.js:184 (string-replace-loader) */ if (process.env.NODE_ENV === 'development') { - "use theming"; + ("use theming"); + /** + * Clean up old hot-module script injections as they hog up memory + * and anything other than the newest one is really not needed at all. + * We don't need to do it more frequently than every half a minute or so, + * but it's done to delay full page reload due to app slowness. + */ + setInterval(() => { + const elements = Array.from(document.querySelectorAll("script[src*=hot-update]")); + if (elements.length > 1) { + const oldInjects = elements.slice(0, elements.length - 1); + oldInjects.forEach(e => e.remove()); + } + }, 1000); }