From 7122e187d83682402ce7b0f167e2c02b135c6b30 Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Tue, 31 Oct 2023 13:16:14 +0100 Subject: [PATCH] Merge pull request #15514 from overleaf/jpa-single-webpack-runtime [web] enable webpack option runtimeChunk=single in dev-env GitOrigin-RevId: 905b362496fc5df896632db920c91aee75c30b46 --- services/web/app/src/infrastructure/ExpressLocals.js | 10 +++++++++- services/web/webpack.config.dev.js | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/services/web/app/src/infrastructure/ExpressLocals.js b/services/web/app/src/infrastructure/ExpressLocals.js index b3fc7772da..f758ecb519 100644 --- a/services/web/app/src/infrastructure/ExpressLocals.js +++ b/services/web/app/src/infrastructure/ExpressLocals.js @@ -171,8 +171,16 @@ module.exports = function (webRouter, privateApiRouter, publicApiRouter) { return staticFilesBase + (webpackManifest[jsFile] || '/' + jsFile) } + let runtimeEmitted = false + const runtimeChunk = webpackManifest['runtime.js'] res.locals.entrypointScripts = function (entrypoint) { - const chunks = getWebpackAssets(entrypoint, 'js') + // Each "entrypoint" contains the runtime chunk as imports. + // Loading the entrypoint twice results in broken execution. + let chunks = getWebpackAssets(entrypoint, 'js') + if (runtimeEmitted) { + chunks = chunks.filter(chunk => chunk !== runtimeChunk) + } + runtimeEmitted = true return chunks.map(chunk => staticFilesBase + chunk) } diff --git a/services/web/webpack.config.dev.js b/services/web/webpack.config.dev.js index d7282bbc9a..c6da294e2d 100644 --- a/services/web/webpack.config.dev.js +++ b/services/web/webpack.config.dev.js @@ -93,6 +93,8 @@ module.exports = merge(base, { }, optimization: { - runtimeChunk: process.env.WEBPACK_RUNTIME_CHUNK || false, + runtimeChunk: { + name: 'runtime', + }, }, })