Giter VIP home page Giter VIP logo

Comments (5)

gbj avatar gbj commented on May 24, 2024

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.

PaulWagener avatar PaulWagener commented on May 24, 2024

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.

gbj avatar gbj commented on May 24, 2024

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:

  1. no trigger.notify() in the component body
  2. create_render_effect and trigger.notify() in the component body
  3. create_effect and create_effect(move |_| trigger.notify())
  4. 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.

gbj avatar gbj commented on May 24, 2024

... 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.

PaulWagener avatar PaulWagener commented on May 24, 2024

Yep, that commit indeed fixes the problem. Thanks a lot for investigating and fixing it!

from leptos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.