DioxusLabs / DioxusLabs/dioxus

Running dx fmt --all-code corrupts my code's syntax

Open
#5,682 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

**Problem**

Running `dx fmt --all-code` generates invalid Rust code.

The formatter rewrites valid `rsx!` event handlers into invalid syntax, causing the project to fail to compile.

I have attached two files:

- `code_before_dx_fmt.txt`: original source code that compiles correctly.
- `code_after_dx_fmt.txt`: the result after running `dx fmt --all-code`.

For example, an event handler like:

```rust
oninput: move |i| async move {
email_input.set(i.value());
},
```
is rewritten into invalid Rust syntax by the formatter.

```rust
oninput: move | i |
async move { email_input.set(i.value()); }
email_input.set(i.value());
},
```

**Steps To Reproduce**

1. Create or open a Dioxus Desktop project.
2. Add an `rsx!` event handler using an async closure (similar to the attached example).
3. Run:

```bash
dx fmt --all-code
```

4. Observe that the formatter generates invalid Rust syntax and the project no longer compiles.

**Screenshots**

Image

[code_after_dx_fmt.txt](https://github.com/user-attachments/files/30096873/code_after_dx_fmt.txt)
[code_before_dx_fmt.txt](https://github.com/user-attachments/files/30096874/code_before_dx_fmt.txt)

**Additional information**

I've attached the source code before and after formatting:

- `code_before_dx_fmt.txt`
- `code_after_dx_fmt.txt`

**Environment:**

- Dioxus version: 0.7.1
- DX CLI version: 0.7.9
- Rust version: 1.97.0
- OS info: Fedora Linux 44 (KDE Plasma)
- App platform: Desktop

**Questionnaire**

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with the attached code_before_dx_fmt.txt and run dx fmt --all-code, then compare the result with code_after_dx_fmt.txt. Start by tracing the dx fmt --all-code entry point and inspect how the async rsx! event handler is formatted; done means the formatted output remains valid Rust and the project compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.