Giter VIP home page Giter VIP logo

Comments (16)

vesparny avatar vesparny commented on May 23, 2024 1

@brucewpaul 2.0.2 has been published.
Thanks for reporting.

from brcast.

vesparny avatar vesparny commented on May 23, 2024

Can you please provide an example?

from brcast.

brucewpaul avatar brucewpaul commented on May 23, 2024

on the super basic level, if you provide a non function to subscribe, it will throw an error when it is iterating after a setState.

TypeError: listeners[id] is not a function
    at Object.keys.forEach.id:10:55
    at Array.forEach
    at Object.setState:10:28
    at eval:36:8
    at eval

In our (react) example, we have components that hide/show based on the breakpoint and communicatevia brcast. But if the components are nested, then then the top level component hides it's children, the children functions are no longer present, but brcast still tries to call them, thus throwing an error.

from brcast.

brucewpaul avatar brucewpaul commented on May 23, 2024

i.e. in the subscribe function, we setState on the react component, but the component is no longer mounted

from brcast.

brucewpaul avatar brucewpaul commented on May 23, 2024

Object.keys(listeners).forEach(id => typeof listeners[id] === 'function' && listeners[id](_state)) fixed it for me

from brcast.

vesparny avatar vesparny commented on May 23, 2024

Uhm I see.
The strange thing is that it should have happened also with previous version no?
You think you can paste the code generating the error?
Or meybe a https://codesandbox.io ?

I'm super curious to see the use case.

from brcast.

brucewpaul avatar brucewpaul commented on May 23, 2024
this.unsubscribe = this.context[__breakpoint__].subscribe((currentBreakpoint) => {
    this.setState({ currentBreakpoint });
});

and in the previous version, it would give a react warning saying that it can't update state on an unmounted component, but this version throws an error

from brcast.

brucewpaul avatar brucewpaul commented on May 23, 2024

there are a lot of pieces to it, but that is the part that is breaking it. And it only breaks in a nested component described above

from brcast.

brucewpaul avatar brucewpaul commented on May 23, 2024

not supplying it a function in the precious version also throws an errors, but the react example is throwing an error now

from brcast.

vesparny avatar vesparny commented on May 23, 2024

In which lifecycle method are you setting the subscription?
Are you invoking unsubscribe in componentWillUnmount?

If the key exists, I do not understand how the callback function can be undefined.

from brcast.

brucewpaul avatar brucewpaul commented on May 23, 2024

in componentDidMount and yes, it is being unsubscribed in componentWillUnmount

from brcast.

brucewpaul avatar brucewpaul commented on May 23, 2024

So with a higher up component, the breakpoint changes and receives the new breakpoint via brcast causing it to unmount. It also had a child that was subscribed to the same brcast, but is not longer there and unsubscribes as it unmounts. It seems at this point, the key is still in the listeners object and errors when it tries to call it

from brcast.

vesparny avatar vesparny commented on May 23, 2024

If you unsubscribe then the listener id should be removed from the keys object as well as the callback.
I'd like to write a test for this.

I can certainly add a quick fix as you proposed but I really want to reproduce the error before with and example or a failing unit test.

Are you willing to help with that?

If it's not too complex perhaps you can create a code sandbox?
Or even better a failing test.

Thanks a lot for reporting this

from brcast.

brucewpaul avatar brucewpaul commented on May 23, 2024

my pleasure and ya I'd be down to help out. I doubt I'll be able to get something reproducible up today, but will try tomorrow

from brcast.

vesparny avatar vesparny commented on May 23, 2024

Sure no problem. Take your time and thanks again

from brcast.

brucewpaul avatar brucewpaul commented on May 23, 2024

👍

from brcast.

Related Issues (4)

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.