ngneat / effects

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

Effects execution order not guaranteed #64

Open jmeinlschmidt opened 1 year ago

jmeinlschmidt commented 1 year ago

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

effects, effects-ng

Is this a regression?

No

Description

Please see the complete example at Stackblitz.

Although the effects execution order should be intuitively dependent on the execution order of actions, in reality, it depends on the effects declaration order.

The example provided in the Stackblitz prints SECOND followed by FIRST, even though it should be the other way. In order to fix this behaviour, it is necessary to change the effects declaration order (moving the load effect at the end). This can introduce some serious bugs which are hard to explore.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-heh5qh?devToolsHeight=33&file=src%2Ftodo.effects.ts

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in

No response

Anything else?

In my opinion, this should be mentioned in the docs, at least.

Do you want to create a pull request?

No

stackblitz[bot] commented 1 year ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

EricPoul commented 1 year ago

Hi. I looked at your example and it works fine. of()(in the TodoService) is synchronous, and since its effect is declared first it also prints first. that's not a problem with effects, it's how rxjs works.

Here's an example in clear rxjs https://stackblitz.com/edit/rxjs-bmjf66?devtoolsheight=60&file=index.ts

EricPoul commented 1 year ago

there's a doc in the elf/store. It's a little different but still about the same how rxjs works https://ngneat.github.io/elf/docs/troubleshooting/stale-emission

You can add auditTime(0) to fix the problem.