-
Notifications
You must be signed in to change notification settings - Fork 759
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
Question: Webpacker integration -> using local manifest.json for server-side rendering #739
Comments
This discussion might be related, as Webpacker currently wants hosts in the manifest.json: rails/webpacker#464. I'm trying to get this changed so that React on Rails might depend on Webpacker and not Webpacker Lite. |
thanks, we can close this now, i'll just look forward to the changes and keep a close eye on the repo. |
In case anybody is curious, I'm working on this right now. Stay tuned. |
Do we have any updates on this? This is a relatively recent problem for me that didn't affect me for the last couple of months (since ~August) but suddenly I am having the exact problem described in this issue. |
I'm glad to say React-Rails supports this for Webpacker 3! 🙌
Thanks for having me check @joeyparis, looks like we fixed it when we added Webpacker 3 support. What issue are you having? |
When I am using webpacker's I have traced the problem back to this line in the
The problem is that the I've found that if I manually edit webpacker's From this:
To this:
However, this requires manually editing the file each time I restart I am using Running your provided example returned the following with
and the following without
|
Excellent @joeyparis, I didn't know it's specific to when the dev server is running. Now I can get about fixing this. I'll ping this chat when a fix is inbound 👍 |
Great to hear! Thanks for the quick reply. Let me know if there's any more information I can provide. I'm happy to help you with debugging and testing in my environment if you need anything. |
I'm pretty low on help in this gem at the moment and I'm currently working on .hydrate() #808 tonight. |
Let me see what I can do. I won't be working on this project again until Monday morning, but that's not to say I can't set aside some time this weekend to create a PR for the gem. I can certainly implement a crude check like that pretty quickly until a more elegant solution can be found. I'll keep you updated! |
Didn't get a chance to tackle this issue this weekend, but going to get started on it now. Should have a PR here shortly. |
Issue reactjs#739 In certain circumstances `webpacker-dev-server` includes the full path (protocol and host with port) in the paths generated for the packs/manifest.json file. This addition removes the protocol, host, and port from the asset path when present allowing assets to be correctly loaded.
I've created a crude but quick and easy solution! # Line 41
def find_asset(logical_path)
asset_path = Webpacker.manifest.lookup(logical_path).to_s
if Webpacker.dev_server.running?
ds = Webpacker.dev_server
# Remove the protocol and host from the asset path. Sometimes webpacker includes this, sometimes it does not
asset_path.slice!("#{ds.protocol}://#{ds.host_with_port}")
dev_server_asset = open("#{ds.protocol}://#{ds.host_with_port}#{asset_path}").read
dev_server_asset.sub!(CLIENT_REQUIRE, '//\0')
dev_server_asset
else
File.read(file_path(logical_path))
end
end My solution was simply to remove the protocol and host/port from loaded asset path. If the protocol and host/port aren't included nothing will change, and if they are included they will be removed so that when they are added in the open they aren't duplicated. I hope you find this solution satisfactory. I have submitted Pull Request #834 |
Fixed by #834 Thanks @joeyparis ! 💙 |
It solves encoding issue when polyfill source code is loaded before Encoding.default_external is set
Thank you guys!! |
Hello!
I'm using the most recent version of react-rails (2.2.0) and Webpacker (1.2). One of the issues I ran into this week was server-side rendering, not fetching assets locally, but instead fetches from the remote asset host. I'm curious if this is fixed, if it's a bug (first of all), or if it will be-supported in the future or which gem will support it?
Explanation:
If Webpack detects that there is an asset_host set in a config, it will prepend the asset_host url in the manifest.json file in Webpacker (1.2) when it precompiles assets via rake webpacker:compile
webpacker/lib/install/config/webpack/configuration.js
So when we precompile assets, our manifest.json file will contain, https://asset.host.com
and It will look like this
or like this
So when we server-side render using react ujs, using the web packer manifest container. The container will read from the local manifest.json with the asset host in it and recognize the asset_path that starts with 'http'. And when it does that, it will fetch the assets remotely, when server-side rendering. We don't want that, I think, we should just fetch it locally (since we have the files already)
react-rails/lib/react/server_rendering/webpack_manifest_container.rb
Current Solution
To get around that and solve this issue we will have to create a separate manifest.json file (from Webpack, not Webpacker), which will not include the asset host, so we can locally reference them, without fetching assets remotely.
That, we can do on the Webpacker gem side and add in a separate webpack manifest plugin entry that creates a separate manifest.json for server-side rendering in a separate folder, something like:
webpacker/lib/install/config/webpack/shared.js
Then, after that, we will need to read that server-side manifest json file in
react-rails/lib/react/server_rendering/webpack_manifest_container.rb
so we can use the local assets that are precompiled, for server-side rendering
something like this:
The text was updated successfully, but these errors were encountered: