- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 716
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
Creating a component causes signals in props to run #1952
Comments
Thanks. As I said briefly on Discord, this is due to the interaction between two things:
This is why wrapping it in an unserializable newtype changes the behavior, for what it's worth. It will be emitted to tracing as an unserializable prop. Note that the read on this signal shouldn't be tracked, as the whole component body (including the props tracing) is lazy and only constructed on leptos/leptos_dom/src/components.rs Line 281 in ad290f5
I'm open to ideas for better solutions to this. |
Hm, I'm skeptical about point 2. I can imagine a lot of scenarios in which I'd want to serialize in response to a button press or some other kind of event where I'd want to use the untracked value. For dev-tools usage I can see wanting to actually subscribe to the signal instead of just having it be serialized automatically. Anyway, these are my suggestions:
|
To be clear on 2., you can always opt into untracking by calling |
Describe the bug
When a component is created within a view and has a signal as props - even if it does not actually use it - it will run the signal once on component creation.
Leptos Dependencies
To Reproduce
Running the following code, even just on actix server, will cause the log message to show. Furthermore, due to the
resource::get
in that derived signal, we get a warning in the browser that we are reading from a resource outside of Suspense.Expected behavior
The signal should only run when it being subscribed to in a reactive scope.
Additional context
Running the code with
env_logger
andRUST_LOG=debug
gives the output below, which hints that it might be due to the tracing.Wrapping the signal in a new-type when passing it as a prop seems to workaround the issue.
The text was updated successfully, but these errors were encountered: