Description 馃摉
The script module appended by the vite_react_refresh_tag does not consider the base setting in the react preamble code.
Reproduction 馃悶
- Start with the rails example app
- Add the following to
config/environments/development.rb
config.relative_url_root = '/sub'
config.action_controller.relative_url_root = '/sub'
- Map the subpath in your
config.ru
require_relative 'config/environment'
map '/sub' do
run Rails.application
Rails.application.load_server
end
- Add base setting to
config/vite.json
{
"all": {
"base": "/sub",
...
}
}
- Now run the app in development mode with the
/sub path loaded in the browser.
The appended module script will look something like so:
<script type="module">
//<![CDATA[
import RefreshRuntime from '/vite-dev/@react-refresh'
RefreshRuntime.injectIntoGlobalHook(window)
// ...
//]]>
</script>
This leads to a 404 error on the import. The correct import path should be.
<script type="module">
//<![CDATA[
import RefreshRuntime from '/sub/vite-dev/@react-refresh'
RefreshRuntime.injectIntoGlobalHook(window)
// ...
//]]>
</script>
I verified that navigating the correct path returns the module source as expected.
The prefix_asset_with_host method at vite_ruby/manifest.rb#L144 appears to be the issue at first glance. I might be able to use the assetHost setting, but setting it to /sub broke the other imports. Configuring the entire host URL would work, but it is undesirable.
Could config.base be included in this join as well? If desired, I could submit a PR with a test case.
Description 馃摉
The script module appended by the
vite_react_refresh_tagdoes not consider the base setting in the react preamble code.Reproduction 馃悶
config/environments/development.rbconfig.ruconfig/vite.json{ "all": { "base": "/sub", ... } }/subpath loaded in the browser.The appended module script will look something like so:
This leads to a 404 error on the import. The correct import path should be.
I verified that navigating the correct path returns the module source as expected.
The
prefix_asset_with_hostmethod at vite_ruby/manifest.rb#L144 appears to be the issue at first glance. I might be able to use theassetHostsetting, but setting it to/subbroke the other imports. Configuring the entire host URL would work, but it is undesirable.Could
config.basebe included in this join as well? If desired, I could submit a PR with a test case.