Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Hotreload does not work on Windows desktop #1566

Closed
2 of 3 tasks
felixf4xu opened this issue Oct 23, 2023 · 6 comments · Fixed by #1684
Closed
2 of 3 tasks

Hotreload does not work on Windows desktop #1566

felixf4xu opened this issue Oct 23, 2023 · 6 comments · Fixed by #1684
Labels
blocked Blocked by another PR/Issue bug Something isn't working desktop Suggestions related to the desktop renderer

Comments

@felixf4xu
Copy link
Contributor

felixf4xu commented Oct 23, 2023

Problem

I created a test project by dx and try to run the code on Windows desktop, but when I edit the rsx code, the UI does not change.

Steps To Reproduce

Steps to reproduce the behavior:

Expected behavior

The displaying UI should change automatically

Environment:

  • Dioxus version: 0.4
  • Rust version: 1.73
  • OS info: Windows 11 22H2
  • App platform: desktop

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@felixf4xu
Copy link
Contributor Author

felixf4xu commented Oct 23, 2023

web does work, I created another project by the template but choose web, then dx serve --platform web --hot-reload works.

[INFO] 🔥 Hot Reload WebSocket connected
[INFO] 🔮 Finding updates since last compile...
[INFO] finished

@ealmloff ealmloff added bug Something isn't working desktop Suggestions related to the desktop renderer labels Oct 23, 2023
@ealmloff
Copy link
Member

ealmloff commented Oct 23, 2023

If you are interested in debugging this, I would start by checking if the channel connects and the event is sent correctly by the CLI here and received correctly the desktop renderer here. It could be that the path to the channel that the two use to communicate is incorrect on windows or some serialization error occurs.

@felixf4xu
Copy link
Contributor Author

Since the code of packages/cli/src/server/desktop/mod.rs changed a lot, I build my test project with local v0.5 (both dx and dioxus crate are built locally) again and found that it is working. 👍

One minor issue, the desktop windows disappears and then appears again during the hot reload, and the window changes its screen position when I have multiple monitors (from one monitor to the other). It does not look like a hot reloading but somewhat cold reloading.

@felixf4xu
Copy link
Contributor Author

I also found several related issues:

  1. dx cpu load is very high, I think thread::sleep(Duration::from_millis(1)) is needed inside the loop at https://github.com/DioxusLabs/dioxus/blob/master/packages/cli/src/server/desktop/mod.rs#L126

  2. During my test, the ErrorKind is not WouldBlock but Uncategorized, so the "Error connecting to hot reloading" string keeps printing out!

  3. About the wording

Error connecting to hot reloading: {} (Hot reloading is a feature of the dioxus-cli. If you are not using the CLI, this error can be ignored

I think it's misleading, it should read like

Error connecting to hot reloading: {} (Hot reloading is a feature of the dioxus-cli. If you are not using hot reloading, this error can be ignored

This error message is from CLI, so CLI is surely being used, but --hot-reload is an option.

@ealmloff
Copy link
Member

One minor issue, the desktop windows disappears and then appears again during the hot reload, and the window changes its screen position when I have multiple monitors (from one monitor to the other). It does not look like a hot reloading but somewhat cold reloading.

What part of the rsx are you trying to hot reload?

@felixf4xu
Copy link
Contributor Author

I debugged a lit bit, it seems to be related to this upstream issue: notify-rs/notify#113

I tested with deferent editors: notepad, vscode, it seems that more file change events are notified by vscode than notepad. If a file is changed and saved in VSCode, about 4 events are received. During those multiple (or duplicated) file changes, one of the file.read_to_string() call may fail: the return value is still Ok but the content length is 0. (I guess 4 callback functions are trying to read the same file at the same time?) This failure will cause UpdateResult::NeedsRebuild.

Maybe some debounce can be added to the watcher but it does not work for my case. A very quick fix is to ignore the case when file content length is 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Blocked by another PR/Issue bug Something isn't working desktop Suggestions related to the desktop renderer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants