Skip to content

Commit

Permalink
Fix SSR webpack-dev-server client code removal for Webpack 5
Browse files Browse the repository at this point in the history
REDMINE-19438
  • Loading branch information
tf committed Oct 17, 2023
1 parent ee947d4 commit e1ca5bd
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit e1ca5bd

Please sign in to comment.