carloskiki / leptos-icons

An icon library for the leptos web framework
MIT License
84 stars 16 forks source link

Accessing a signal outside a reactive tracking context #26

Closed adrianncovaci closed 9 months ago

adrianncovaci commented 9 months ago

When attempting to reactively update an icon using a signal like: <Icon icon=icon_signal class="h-6 w-6 text-gray-400"/>, I encountered the warning: Signal or memo accessed outside a reactive tracking context (defined at /rustc/ad963232d9b987d66a6f8e6ec4141f672b8b9900/library/core/src/convert/mod.rs:716:9) on the line let icon: IconData = icon.get().into(); in lib.rs.

Wouldn't it be more appropriate to handle the signal inside the Icon component so that it'll react on change (for example, if modifying the icon from another component). This is what I had in mind:

    let icon_signal = move || icondata::IconData::from(icon.get());
    // handle rest of svg attr's
    ...
carloskiki commented 9 months ago

This seems like a bug. Can you please provide the relevant part of the component that produces this warning, and specify the version of this library and the version of leptos you are using.

FYI: The inputs to the Icon component are already all of type MaybeSignal<T> so the library should already be able to handle signals (I think).

adrianncovaci commented 9 months ago

I've been using the lates leptos version (0.5.0-rc3) and the main branch for leptos-icons, however I think this issue occurs on previous leptos version as well due to the fact that the get method was used outside of a closure inside the component's body, here. I've prepared a pr which fixes this.

carloskiki commented 9 months ago

I will publish version 0.0.16-rc3, and the bug should be fixed