Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
JustSimplyKyle opened this issue Jun 16, 2024 · 6 comments
Assignees
Labels
bug Something isn't working desktop Suggestions related to the desktop renderer needs reproduction An issue that is missing a reproduction
Milestone

Comments

@JustSimplyKyle
Copy link

JustSimplyKyle commented Jun 16, 2024

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
Copy link
Author

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

@ealmloff
Copy link
Member

#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 ealmloff added the desktop Suggestions related to the desktop renderer label Jul 19, 2024
@JustSimplyKyle
Copy link
Author

JustSimplyKyle commented Jul 20, 2024

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

@jkelleyrtp jkelleyrtp added this to the 0.6.0 milestone Jul 25, 2024
@i123iu
Copy link
Contributor

i123iu commented Jul 26, 2024

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())
}

@jkelleyrtp
Copy link
Member

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

@jkelleyrtp
Copy link
Member

Should be fixed in #2779

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working desktop Suggestions related to the desktop renderer needs reproduction An issue that is missing a reproduction
Projects
None yet
Development

No branches or pull requests

4 participants