-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular: Unsubscribe prop subscriptions #12514
Angular: Unsubscribe prop subscriptions #12514
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff @Marklb -- thanks for diagnosing this and fixing it! 🔥
Angular: Unsubscribe prop subscriptions
@shilman Tried twice to upgrade to this version. After doing so I started getting TypeScript errors I don't get with .21 and if I comment out my own code to get those errors to temporarily stop, Storybook errors in the browser with an Each patch upgrade is a dice roll with @storybook/angular. |
@brandonpittman really sorry about that and thanks for letting me know. i'll hold off on patching angular stuff then and go through the full 6.1-alpha/beta/rc process instead. did you try the standard remove |
Yeah, I did the usual I know Angular's a pain in the ass. I appreciate your team supporting it at all. If my boss wasn't so dedicated to Angular, I'd force a change to React. |
I would be surprised if this caused an error like that, but I get errors every time I upgrade Angular, so I wouldn't say I am sure it wouldn't either. I hadn't updated Storybook from Did you also upgrade Angular or just Storybook? Last weekend I upgraded the main angular packages from The problems I got were things I knew how to fix though, like having to use |
@Marklb We're still on Angular 9. Not sure if that's what's causing issues, but .21 is fine. Saw similar issues during the 6.0 beta where anything about .37 just fell apart. |
Issue: #12507
When a prop was set for an
EventEmitter
type, theEventEmitter
would be subscribed to. The problem was that each timesetProps
was called, a new subscription was created without maintaining a reference to that subscription.In the following example, every time the
label
control changed, theonClick
EventEmitter
would be subscribed to. Since new subscriptions were being created, the props function would get called once for each subscription. So if label changed 2 times, then you clicked the button, there would be 3 actions (initial subscription, first label change subscription, second label change subscription), but there should only be one action.What I did
Kept a reference to the subscriptions to try and make sure they get unsubscribed. I wrote it to work for any
Observable
, but it should only be used forEventEmitter
props currently.When setting a prop for an
EventEmitter
:How to test
Set a value for an for an
EventEmitter
prop, then do something that updates props, such as changing a control. A new subscription should not be created if the value of that prop didn't change. If the value of that prop did change, the previous subscription should have been unsubscribed.