bmealhouse/next-redux-saga

Using NextJS router.push from within saga stops working with next-redux-saga

jbox5 opened this issue ยท 6 comments

jbox5 commented

Hi,

I've got a really simple saga that does nothing other than use NextJS 7 router and does a Router.push (using call(Router.push, '/mypath')).
However, the navigation does not happen. If I remove the 'withReduxSaga' HOC wrapper from my _app.js it begins working again.

Is there anything special I have to do when using next-redux-saga to make this work?

Thanks,
J.

Hi @jbox5, thanks for submitting the issue. Unfortunately, I don't have any time to devote to this project at the moment, but I'm happy to accept PRs or share commit rights with those interested in supporting next-redux-saga.

Please see the contributing docs to get started.

Hi @jbox5
Are you sure you're on the client side of your application? You need to redirect using req.redirect('some-url') on the server side. You can detect the current context using ctx.isServer withing #getInitialProps.

@bbortt I was hoping you were correct in your assumption of server vs client routing but unfortunately I'm seeing this on my end as well. Seems using call(Router.push, '/path') has no affect whatsoever ๐Ÿ˜ž. Will see if I can do some digging, but anyone with knowledge of this package may be better suited for the task than myself.

@jbox5 Assuming you weren't able to get this working?

Realized the actual logic of this module is ~40 lines of code so domain knowledge probably doesn't really apply ๐Ÿ˜….

Slight update though: it would seem that the usage of call itself is what's causing the problem. Using the router outside of call (e.g. - Router.push('/path) seems to work just fine. Probably move forward with this approach but maybe something worthwhile investigating if someone has interest/time.

A little embarrassed here, but... I had forgotten to precede the call with a yield ๐Ÿคฆโ€โ™‚๏ธ. With a yield in front (e.g. - yield call(Router.push, '/path'); everything works as expected. Feel free to close this issue

@wootencl Thank you very much for posting the solution. I was thinking about this ratter being a redux-saga issue, but its solved then ๐Ÿ‘