From e1ca5bd2531c16a8ff854abed0b08893cc52d532 Mon Sep 17 00:00:00 2001 From: Tim Fischbach Date: Tue, 17 Oct 2023 14:08:17 +0200 Subject: [PATCH] Fix SSR webpack-dev-server client code removal for Webpack 5 REDMINE-19438 --- .../react_server_side_rendering_helper.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/entry_types/scrolled/app/helpers/pageflow_scrolled/react_server_side_rendering_helper.rb b/entry_types/scrolled/app/helpers/pageflow_scrolled/react_server_side_rendering_helper.rb index fda63d7e6a..d497ccfdd2 100644 --- a/entry_types/scrolled/app/helpers/pageflow_scrolled/react_server_side_rendering_helper.rb +++ b/entry_types/scrolled/app/helpers/pageflow_scrolled/react_server_side_rendering_helper.rb @@ -32,6 +32,9 @@ def asset_container_class # see https://github.com/reactjs/react-rails/issues/970#issuecomment-476338244 class WebpackerSplitChunksManifestContainer < React::ServerRendering::WebpackerManifestContainer + CLIENT_EXEC = + %r{__webpack_exec__\("./node_modules/webpack-dev-server\/client\/index\.js[^"]*"\),} + def find_asset(logical_path) asset_paths = manifest.lookup_pack_with_chunks(logical_path, type: :javascript) @@ -46,7 +49,12 @@ def find_asset(logical_path) asset_path.slice!("#{ds.protocol}://#{ds.host_with_port}") dev_server_asset = URI.open("#{ds.protocol}://#{ds.host_with_port}#{asset_path}").read - dev_server_asset.sub!(CLIENT_REQUIRE, '//\0') + + # Remove webpack-dev-server client code that tries to + # interact with browser globals: + dev_server_asset.sub!(CLIENT_REQUIRE, '//\0') # for Webpack 4 + dev_server_asset.sub!(CLIENT_EXEC, '/*\0*/') # for Webpack 5 + dev_server_asset end else