next-redux-wrapper icon indicating copy to clipboard operation
next-redux-wrapper copied to clipboard

pages/_app example for Redux Saga is a bit incorrect when getInitialProps are used along with getServerSideProps

Open vialus opened this issue 4 years ago • 0 comments

Describe the bug

If we want to process getInitialProps in the pages/_app and at the same time have getServerSideProps on the page level then we need to slightly modify the example in the Readme file.

Currently it has this code

// 2. Stop the saga if on server
        if (ctx.req) {
            ctx.store.dispatch(END);
            await (ctx.store as SagaStore).sagaTask.toPromise();
        }

The issue is that this code runs also for the getServerSideProps pages and prevents Sagas in that pages from running.

I have fixed it by changing the first line to:

if (ctx.req && Component.getInitialProps)

P.S Also it is worth mentioning that this example in Readme is written for the previous version of the library. Maybe it worked like this in the version 6 but in version 7 it does not without my small change.

vialus avatar Nov 14 '21 10:11 vialus