Comments (5)
Note that using create_render_effect
instead of create_effect
here also works, because it runs the effect immediately, rather than waiting a tick. I think the issue is that trigger.notify()
tries to run all existing effects, which accidentally removes the queued-up create_effect
from the queue. So in that sense, this is a bug.
I can't think of a situation in which you'd actually need to do this, though: effects always run once initially (either immediately for create_render_effect
or at the end of the microtask for create_effect
) so why would you need to notify on the trigger as well? In general I'd say that mutating a signal or notifying a trigger during rendering is a code smell for this reason.
from leptos.
While I agree that the minimal example is contrived and useless. I encountered the bug in a situation in which I needed a trigger that triggered on certain child components being added or removed (with the trigger itself being provided via context). Hence the notify call in the render code to signal that a child component was mounted.
from leptos.
create_effect(move |_| trigger.notify());
in the component body does also work correctly, and is conceptually the "do this once the component has mounted" call.
So, a list of combinations that work correctly that I've tried:
- no
trigger.notify()
in the component body create_render_effect
andtrigger.notify()
in the component bodycreate_effect
andcreate_effect(move |_| trigger.notify())
- using a signal with value
()
rather than a trigger
4 suggests to me that this is some small, stupid discrepancy in the implementation of Trigger
as opposed to signals, which I've tried to track down for a few hours without much less. I'm going to take another crack at it right now and see if I can nail it down.
from leptos.
... well, sometimes once you figure out what the heck is going on, sometimes it's easier than anticipated.
#2059 should fix this (and also another issue with triggers #1948). Feel free to test your actual use case against that branch and let me know if it fixes it, but I think it will.
from leptos.
Yep, that commit indeed fixes the problem. Thanks a lot for investigating and fixing it!
from leptos.
Related Issues (20)
- Leptos Axum Handle Server Fn unwrapping Context<ResponseOptions> can panic under load HOT 22
- `mount_to_body` should accept `FnOnce` closures HOT 2
- The class display is inconsistent in some cases HOT 2
- Transition fallback not shown
- Allow turbofish in `view!` macro to better support generic components HOT 4
- Use idiomatic, built-in From and Into traits instead of IntoView, IntoAttribure, etc. HOT 3
- Actix server function panics with missing `HttpContext` HOT 3
- Trying to use (unsupported) equality constraint in component makes leptos ignore the component and its errors and report success HOT 2
- Support for markdown content sites? Similar to @nuxt/content support for nuxt
- Add `read_slice!()` and `write_slice!()` macros HOT 1
- My short onboarding experience HOT 9
- `callback::NotRawCallback` is not implemented for <closure> HOT 7
- Inconstistency between debug and release on `if let Some(x)...` HOT 5
- Trouble with Events not triggering at all HOT 5
- Can you provide a case of a browser right-click pop-up menu?
- Have signals/StoredValues update/update_value functions return the callbacks return value HOT 6
- examples: add `rust-toolchain.toml` files for examples HOT 1
- Resource::loading gives a warning if disposed before it was fully initialized HOT 2
- leptos_router: Feature: Support for trailing slashes. HOT 13
- Get error about missing "tracing" dependency when trying to use #[component] macro HOT 20
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leptos.