ngneat / effects

🪄 A framework-agnostic RxJS effects implementation
https://www.netbasal.com
MIT License
63 stars 11 forks source link

Effects directive only unregisters last effect for each effect provider #72

Open ntziolis opened 2 months ago

ntziolis commented 2 months ago

Which @ngneat/effects-* package(s) are the source of the bug?

effects-ng

Is this a regression?

No

Description

Effects directive only unregisters last effect for each effect provider. The other effects keep running even after the component with the directive are destroyed.

The below uses the instance as the key, which results in each additional effect in the loop overriding the last entry. https://github.com/ngneat/effects/blob/da32a41a521fa1829c1dc63b679c7f13dad1e0f2/libs/effects-ng/src/lib/use-directive-effects.ts#L70

During unregister sourceInstancesWithProvidersEffectsTokens is used to identify which effects to unregister. While there might be multiple providers in the set, there is always only one effect entry associated with each provider.

https://github.com/ngneat/effects/blob/da32a41a521fa1829c1dc63b679c7f13dad1e0f2/libs/effects-ng/src/lib/use-directive-effects.ts#L96

Please provide a link to a minimal reproduction of the bug

This can be reproduced by adding additional effects to the effect providers in the unit tests.

Please provide the exception or error you saw

Please provide the environment you discovered this bug in

No response

Anything else?

No response

Do you want to create a pull request?

Not sure if I understand the codebase enough to ensure I don't brake the other feature "an effect will always only run once"