-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
autoformattingRelated to the autofmt crateRelated to the autofmt cratebugSomething isn't workingSomething isn't working
Description
Problem
Summary
dx fmt corrupts source code when a file contains a top-level comment and an inline if/else expression within an RSX attribute.
The formatter incorrectly duplicates the file's leading comment and injects it at the end of the if/else expression, right before the element's closing brace.
The specific failure chain is:
-
dx fmtcopies the text from line 1 (e.g.,// A comment...). -
It pastes this text immediately after the else block inside the RSX.
-
Since the pasted text is a line comment (
//), it comments out the closing brace } that follows it. -
This leaves the RSX element unclosed, resulting in a compiler error
Minimal Reproduction
Step 1: Create this file (sample.rs)
// A comment about this file
use dioxus::prelude::*;
#[component]
pub fn Sample() -> Element {
let is_active = use_signal(|| false);
rsx! {
div { class: if is_active() { "active" } else { "inactive" },
div { class: if is_active() { "a" } else { "b" }}
}
}
}Step 2: Run the formatter
dx fmt --file sample.rsStep 3: Observe corrupted output
// A comment about this file
use dioxus::prelude::*;
#[component]
pub fn Sample() -> Element {
let is_active = use_signal(|| false);
rsx! {
div { class: if is_active() { "active" } else { "inactive" },
div { class: if is_active() { "a" } else { "b" } // A comment about this file }
}
}
}The bug: The comment from line 1 (// A comment about this file) has been appended and the closing } has been commented out.
Workaround
- Remove all top level comments
- Wrap the
rsxwithif/elsein an extra layer of{}brackets
Environment
- Dioxus CLI version: 0.7.2
- Rust version: 1.85.1
- OS: macOS 15.6.1 (arm64)
Metadata
Metadata
Assignees
Labels
autoformattingRelated to the autofmt crateRelated to the autofmt cratebugSomething isn't workingSomething isn't working