From b397ae0dd85e2d98398878db227f4fc495e51470 Mon Sep 17 00:00:00 2001 From: Verdan Mahmood Date: Thu, 8 Nov 2018 14:09:51 +0100 Subject: [PATCH 1/2] Fixing "Cannot read property cancel of undefined" There actually is really a random bug which trigger sometimes, only happens in production. ref: https://github.com/react-boilerplate/react-boilerplate/issues/2021 --- app/utils/sagaInjectors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/utils/sagaInjectors.js b/app/utils/sagaInjectors.js index f7d524d5..edf1a739 100644 --- a/app/utils/sagaInjectors.js +++ b/app/utils/sagaInjectors.js @@ -64,7 +64,7 @@ export function ejectSagaFactory(store, isValid) { if (Reflect.has(store.injectedSagas, key)) { const descriptor = store.injectedSagas[key]; - if (descriptor.mode !== DAEMON) { + if (descriptor.mode && descriptor.mode !== DAEMON) { descriptor.task.cancel(); // Clean up in production; in development we need `descriptor.saga` for hot reloading if (process.env.NODE_ENV === 'production') { From 686b476e879eb03d381086f59d6e49bc5b7538df Mon Sep 17 00:00:00 2001 From: Verdan Mahmood Date: Thu, 8 Nov 2018 14:33:18 +0100 Subject: [PATCH 2/2] Updating test case --- app/utils/tests/sagaInjectors.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/utils/tests/sagaInjectors.test.js b/app/utils/tests/sagaInjectors.test.js index 2e17b361..10fbe16c 100644 --- a/app/utils/tests/sagaInjectors.test.js +++ b/app/utils/tests/sagaInjectors.test.js @@ -70,9 +70,9 @@ describe('injectors', () => { expect(() => ejectSaga(1)).toThrow(); }); - it('should cancel a saga in a default mode', () => { + it('should cancel a saga in RESTART_ON_REMOUNT mode', () => { const cancel = jest.fn(); - store.injectedSagas.test = { task: { cancel } }; + store.injectedSagas.test = { task: { cancel }, mode: RESTART_ON_REMOUNT }; ejectSaga('test'); expect(cancel).toHaveBeenCalled();