bhauman / devcards

Devcards aims to provide a visual REPL experience for ClojureScript
1.53k stars 116 forks source link

not firing unmount events when changing pages / updating cards #24

Closed wilkerlucio closed 8 years ago

wilkerlucio commented 9 years ago

I have a component that adds global keyboard events when it's mounted and remove those events when the component is unmounted, that works fine as long as the React lifecycle get's respected, but I found 2 situations here where the lifecycle is neglected leaving the events there when they should be removed (and then I'm having duplicated event issues...).

The occasions when it happens:

1 - navigate out from the current cards list (that will remove the cards from the page, but the unmount events are not triggered on the components on the cards) 2 - remove card (usually happens for me when I rename the card to force update it).

Would be nice if devcards correctly unmounts the cards when removing then fullfilling the component lifecycle, without I'm having to refresh my page to remove hanging events.

How to reproduce:

Just create a simple component and mount it like this:

(defn unmount-sample [_ _]
  (reify
    om/IWillUnmount
    (will-unmount [_]
      (println "unmounting this"))

    om/IRender
    (render [_]
      (dom/div nil "unmount"))))

(defcard-om sample-card
  unmount-sample
  {})

Navigate in/out of the namespace using the devcards UI, you will notice that the event is not being fired.

bhauman commented 9 years ago

I think I know why this is happening. I'm going to look at it now.

BTW the code for devcards isn't too bad. If you fork it and add the "../devcards/src" to the :source-paths of your project, you can work on it live along with your code base :)

Thanks for taking an interest in devcards! I think you are ahead of the curve.

wilkerlucio commented 9 years ago

@bhauman cool, I'll try to play with the code a bit latter and see if I can try some ideas :)

bhauman commented 9 years ago

This is fixed I just deployed a new 0.2.0 SANPSHOT

Let me know how it works

wilkerlucio commented 9 years ago

@bhauman hi, it's working a priori, but I'm finding some weird behavior here, but I'm not sure if the issue is on devcards or at my component, I'm trying to debug it, but this is what's going on:

1 - I load the page first time, all mount events are called correctly 2 - I navigate out, it correctly fires all unmount events 3 - I navigate in again, then I have a issue, the mount event for my key listener is triggered twice, I have no idea why, and then when I leave the page only the first one of then get unmounted.

If you have any idea on why that's happening please let me know, I'll keep on debugging here.

bhauman commented 8 years ago

@wilkerlucio Is this working OK now? Or are you still having problems?

wilkerlucio commented 8 years ago

@bhauman just did some testing and it seems to be working fine.

bhauman commented 8 years ago

Cool let's close it then.