dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Git version of dioxus fails to load collected assets using the Desktop template

Open JustSimplyKyle opened this issue 1 year ago • 5 comments

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: image

Steps To Reproduce

Steps to reproduce the behavior:

  • dx new test-case -o styling=Vanilla -o router=false --subtemplate Desktop
  • cd test-case
  • cargo add dioxus --features desktop --git https://github.com/DioxusLabs/dioxus
  • cargo install --git https://github.com/DioxusLabs/dioxus dioxus-cli
  • dx serve

Expected behavior

To launch correctly with assets loading.

Temporary fix

  • dx build
  • cd 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

JustSimplyKyle avatar Jun 16 '24 11:06 JustSimplyKyle

Additionally, if we compile to web instead, it works flawlessly.

JustSimplyKyle avatar Jul 19 '24 05:07 JustSimplyKyle

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

ealmloff avatar Jul 19 '24 17:07 ealmloff

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

JustSimplyKyle avatar Jul 20 '24 04:07 JustSimplyKyle

Hi, I've also had this issue and found something:

  • I believe the issue is in the function running_in_dev_mode which decides by checking the CARGO environmental 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, CARGO is not set
  • therefore get_asset_root returns None (it should return a bundled path but it is not implemented for windows yet)
  • and finally get_asset_root_or_default defaults 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())
}

i123iu avatar Jul 26 '24 12:07 i123iu

This is because of #232 and should be fixed shortly :)

jkelleyrtp avatar Aug 03 '24 01:08 jkelleyrtp

Should be fixed in #2779

jkelleyrtp avatar Oct 26 '24 00:10 jkelleyrtp