dioxus
dioxus copied to clipboard
Git version of dioxus fails to load collected assets using the Desktop template
Problem
When doing dx serve
Assets are collected to the folder assets
.rw-r--r-- 23k kyle 16 Jun 19:45 -N header.svg
.rw-r--r-- 652 kyle 16 Jun 19:45 -N main.css
But spits out this error.
2024-06-16T11:50:11.217950Z WARN dioxus_desktop::protocol: Assets built with manganis cannot be preloaded (failed to read "/home/kyle/coding/test-case/__assets_head.html"). This warning may occur when you build a desktop application without the dioxus CLI. If you do not use manganis, you can ignore this warning: No such file or directory (os error 2).
and the example comes out like this:
Steps To Reproduce
Steps to reproduce the behavior:
dx new test-case -o styling=Vanilla -o router=false --subtemplate Desktopcd test-casecargo add dioxus --features desktop --git https://github.com/DioxusLabs/dioxuscargo install --git https://github.com/DioxusLabs/dioxus dioxus-clidx serve
Expected behavior
To launch correctly with assets loading.
Temporary fix
dx buildcd dist./test-case
Environment:
- Dioxus version: master, including the cli
- Rust version: 1.78.0
- OS info: Arch Linux 6.9.4
- App platform: Desktop
Additionally, if we compile to web instead, it works flawlessly.
https://github.com/DioxusLabs/dioxus/pull/2258 rewrote large sections of the CLI. With the latest versions of the CLI and dioxus-desktop, I cannot reproduce this issue on macos.
From the error message, it looks like desktop is looking for assets in the root directory instead of the /dist directory. That could happen if the versions of the CLI and desktop were mismatched causing serialization/deserialization to fail
I can still reproduce it on my end, with the CLI and desktop being the latest git version; I have ensured that through this following command:
cargo update && cargo install --git https://github.com/DioxusLabs/dioxus dioxus-cli --force
Hi, I've also had this issue and found something:
- I believe the issue is in the function
running_in_dev_modewhich decides by checking theCARGOenvironmental variable
fn running_in_dev_mode() -> bool {
// If running under cargo, there's no bundle!
// There might be a smarter/more resilient way of doing this
std::env::var_os("CARGO").is_some()
}
- when the project is started using
dx serve,CARGOis not set - therefore
get_asset_rootreturnsNone(it should return a bundled path but it is not implemented for windows yet) - and finally
get_asset_root_or_defaultdefaults to the crate root path
/// Get the asset directory, following tauri/cargo-bundles directory discovery approach
///
/// Defaults to the current directory if no asset directory is found, which is useful for development when the app
/// isn't bundled.
fn get_asset_root_or_default() -> PathBuf {
get_asset_root().unwrap_or_else(|| std::env::current_dir().unwrap())
}
This is because of #232 and should be fixed shortly :)
Should be fixed in #2779