dioxus-community / dioxus-free-icons

Use free svg icons in your Dioxus projects easily with dioxus-free-icons.
Other
67 stars 15 forks source link

Unnecessary title tags created in HTML #14

Closed nissy-dev closed 3 months ago

nissy-dev commented 2 years ago

If title props is empty value, empty title tag is created in HTML and it is not good. To avoid this, I tried to use "conditional rendering" but https://github.com/DioxusLabs/dioxus/issues/500 happened.

       svg {
            stroke: "currentColor",
            stroke_width: "0",
            class: format_args!("{}", cx.props.class),
            height: format_args!("{}", cx.props.height),
            width: format_args!("{}", cx.props.width),
            view_box: format_args!("{}", cx.props.icon.view_box()),
            xmlns: format_args!("{}", cx.props.icon.xmlns()),
            fill: format_args!("{}", cx.props.fill),
             // conditional rendering
            cx.props.title.is_some().then(|| {
                rsx!{  title  {  cx.props.title }  }
            }),
            cx.props.icon.child_elements()
        }

I will look into this issue now

nissy-dev commented 2 years ago

This is a reason. dioxus doesn't allow a fragment with 0 elements to make a diffing algorithm faster and simpler.

it is impossible to craft a fragment with 0 elements - they must always have at least a single placeholder element.

https://github.com/DioxusLabs/dioxus/blob/94004cfe19c1efb851b3d8147f608990c9ab21b5/packages/core/src/diff.rs#L29-L39