ElMassimo / ElMassimo/vite_ruby
vite_react_refresh_tag does not respect `base` setting
- Dominant language
- Ruby
- Stars
- 1.6k
- Forks
- 149
- Avg merge
- 5h 13m
- Merged PRs (30d)
- 2
Description
### Description 📖
The script module appended by the `vite_react_refresh_tag` does not consider the base setting in the react preamble code.
### Reproduction 🐞
1. Start with the rails example app
2. Add the following to `config/environments/development.rb`
```ruby
config.relative_url_root = '/sub'
config.action_controller.relative_url_root = '/sub'
```
3. Map the subpath in your `config.ru`
```ruby
require_relative 'config/environment'
map '/sub' do
run Rails.application
Rails.application.load_server
end
```
4. Add base setting to `config/vite.json`
```json
{
"all": {
"base": "/sub",
...
}
}
5. Now run the app in development mode with the `/sub` path loaded in the browser.
The appended module script will look something like so:
```html
//<![CDATA[
import RefreshRuntime from '/vite-dev/@react-refresh'
RefreshRuntime.injectIntoGlobalHook(window)
// ...
//]]>
```
This leads to a 404 error on the import. The correct import path should be.
```html
//<![CDATA[
import RefreshRuntime from '/sub/vite-dev/@react-refresh'
RefreshRuntime.injectIntoGlobalHook(window)
// ...
//]]>
```
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](https://github.com/ElMassimo/vite_ruby/blob/main/vite_ruby/lib/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.
Contributor guide
Assessment
This issue has not been assessed yet.