Giter Site home page Giter Site logo

Weird dispatch issue with useElmish about feliz HOT 5 CLOSED

forki avatar forki commented on July 20, 2024
Weird dispatch issue with useElmish

from feliz.

Comments (5)

forki avatar forki commented on July 20, 2024 1

this actually makes a lot of sense and I wonder why it ever worked before.

anyways sorry about the noise and many thanks for the help to spot the obvious!

from feliz.

alfonsogarciacaro avatar alfonsogarciacaro commented on July 20, 2024 1

@Zaid-Ajaj If I replace Feliz.UseElmish with Fable.React.UseElmish Elmish subscriptions work. Haven't checked what's the actual difference (maybe because Fable.React.UseElmish doesn't use the useSyncExternalStore polyfill?)

Test project: https://github.com/alfonsogarciacaro/app

from feliz.

alfonsogarciacaro avatar alfonsogarciacaro commented on July 20, 2024

Generated code looks right. By debugging I found that the dispatch reference captured by subscribeToTimer becomes invalid. Not sure if there's something funny going on or this how useSyncExternalStore is supposed to work (React has this oddities).

You have two options:

  1. Pass dispatch as a dependency to useEffect. This is actually what React recommends, any captured value must also be a dependency.
    React.useEffect(subscribeToTimer, [| box dispatch |])

  2. Use Elmish subscriptions

☝️ Forget about the 2nd option, I tested and in that case the subscription is registered twice. Not sure why.

from feliz.

Zaid-Ajaj avatar Zaid-Ajaj commented on July 20, 2024

this actually makes a lot of sense and I wonder why it ever worked before.

It could be that previous version gave you a stable dispatch (the view and the effect get the same dispatch, always)

Sometimes to avoid capturing, I use inline (i.e. let inline subscribeToTimer()) so that the body of the effect is inlined and doesn't capture but that might not work with effects as subscriptions. I used that often with React.useMemo

from feliz.

Zaid-Ajaj avatar Zaid-Ajaj commented on July 20, 2024

@alfonsogarciacaro I am not sure, will have a look! First thing I need to do is actually bring back tests to life to ensure expected behaviour, will try when time permits

from feliz.

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.