Strange bug causing sagas to return early that seems to be different from #1592
In our bug reproduction, buggySaga never reaches "checkpoint #2". Instead, it returns the result of the preceding line to its caller even though there's no return there.
This is a finicky, seemingly deterministic bug where some code combinations cause a saga to return early with the result of the last line executed. When we come across this bug, prepending the early return with a yield usually causes that prepended line to return early instead. Removing the early returning line usually causes the next yield to return early instead. We've only come across and/or reproduced this bug on react-native 0.71.x but we haven't tried very hard to reproduce the bug on newer versions or without react-native so we're not confident about the bug's scope. Buggy sagas return at the same spot across different runs and on both macos+iOS and linux+android so the bug appears to be deterministic.
While the bug presents similarly to #1592 we don't believe that it's the same bug for at least two reasons. First, changing the hermes stack size doesn't affect the behavior of buggy sagas. In contrast, changing the hermes stack size does change the behavior of our redux-saga#1592 reproduction. Second, adding delay(0) or micro ticks, even as many as one for each yield, doesn't prevent early returns whereas doing so does prevent early returns in our redux-saga#1592 reproduction.
Commenting out inlineRequires: true, in metro.config.js seems to affect behavior but it could be a blind alley.
For now, we're bandaging this bug by returning a boolean property at the end of each saga that with 3+ possible yields and checking this property in these sagas' callers to confirm that the saga didn't return early.
Source: redux-saga/redux-saga