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

Interaction between IfmtInput::push_* and rsx-autoformat #3503

Open
ealmloff opened this issue Jan 6, 2025 · 1 comment
Open

Interaction between IfmtInput::push_* and rsx-autoformat #3503

ealmloff opened this issue Jan 6, 2025 · 1 comment
Labels
autoformatting Related to the autofmt crate bug Something isn't working rsx Related to rsx or the dioxus-rsx crate
Milestone

Comments

@ealmloff
Copy link
Member

ealmloff commented Jan 6, 2025

Problem

IfmtInput has methods like push_raw_str to modify the segments, but those methods do not effect the source. Since the autoformatter only uses the source it was originally parsed from formatting a ifmt segment reverts the segments that were pushed. This behavior caused this bug in the docsite codegen. The patch works around the issue by not merging adjacent text segments

Steps To Reproduce

Run this code and observe it panics:

#[test]
fn fails() {
    let mut rsx: CallBody = parse_quote! { "hello world" };
    if let dioxus_rsx::BodyNode::Text(text) = &mut rsx.body.roots[0] {
        // Modifying the IfmtInput directly is allowed, but it doesn't update the source that autofmt uses
        text.input
            .formatted_input
            .push_raw_str(" this isn't added to the formatted version".to_string());
    }
    let block = dioxus_autofmt::write_block_out(&rsx).unwrap();
    let re_parsed: CallBody = syn::parse_str(&block).unwrap();

    // normalize line endings for windows tests to pass
    assert_eq!(rsx.body, re_parsed.body);
}

Expected behavior

You should not be able to edit IfmtInput internals or modifying IfmtInput should work with the autoformatter

Environment:

  • Dioxus version: master
  • Rust version: nightly
  • OS info: MacOS
@ealmloff ealmloff added bug Something isn't working autoformatting Related to the autofmt crate rsx Related to rsx or the dioxus-rsx crate labels Jan 6, 2025
@jkelleyrtp
Copy link
Member

I think we might be able to get around the need for spans by simply not caching expressions at all. I think we used spans at one point but recent improvements mean we use span information just for caching the expression which we really don't need to do.

@jkelleyrtp jkelleyrtp added this to the 0.6.2 milestone Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autoformatting Related to the autofmt crate bug Something isn't working rsx Related to rsx or the dioxus-rsx crate
Projects
None yet
Development

No branches or pull requests

2 participants