Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SSR webpack-dev-server client code removal for Webpack 5 #2018

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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