From 134214d5129fdbb4dcbc9a21a03e82d1fb464c28 Mon Sep 17 00:00:00 2001 From: Darren Ethier Date: Tue, 12 Feb 2019 03:02:03 -0500 Subject: [PATCH] Fix recursion in sync routine. (#13818) --- packages/redux-routine/CHANGELOG.md | 3 ++- packages/redux-routine/src/runtime.js | 2 +- packages/redux-routine/src/test/index.js | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/redux-routine/CHANGELOG.md b/packages/redux-routine/CHANGELOG.md index dbddb8321016b6..1bec9149f60993 100644 --- a/packages/redux-routine/CHANGELOG.md +++ b/packages/redux-routine/CHANGELOG.md @@ -4,7 +4,8 @@ - Fix unhandled promise rejection error caused by returning null from registered generator ([#13314](https://github.com/WordPress/gutenberg/pull/13314)) - The middleware will no longer attempt to coerce an error to an instance of `Error`, and instead passes through the thrown value directly. This resolves issues where an `Error` would be thrown when the underlying values were not of type `Error` or `string` (e.g. a thrown object) and the message would end up not being useful (e.g. `[Object object]`). -([#13315](https://github.com/WordPress/gutenberg/pull/13315)) +([#13315](https://github.com/WordPress/gutenberg/pull/13315)) +- Fix unintended recursion when invoking sync routine ([#13818](https://github.com/WordPress/gutenberg/pull/13818)) ## 3.0.3 (2018-10-19) diff --git a/packages/redux-routine/src/runtime.js b/packages/redux-routine/src/runtime.js index d3de265c3f2b15..ec984a148435e2 100644 --- a/packages/redux-routine/src/runtime.js +++ b/packages/redux-routine/src/runtime.js @@ -28,7 +28,7 @@ export default function createRuntime( controls = {}, dispatch ) { // Async control routine awaits resolution. routine.then( yieldNext, yieldError ); } else { - next( routine ); + yieldNext( routine ); } return true; } ); diff --git a/packages/redux-routine/src/test/index.js b/packages/redux-routine/src/test/index.js index 79a35673f70a59..4a25b4771580fd 100644 --- a/packages/redux-routine/src/test/index.js +++ b/packages/redux-routine/src/test/index.js @@ -143,4 +143,21 @@ describe( 'createMiddleware', () => { expect( store.getState() ).toBe( 2 ); } ); + + it( 'does not recurse when action like object returns from a sync ' + + 'control', () => { + const post = { type: 'post' }; + const middleware = createMiddleware( { + UPDATE: () => post, + } ); + const store = createStoreWithMiddleware( middleware ); + function* getPostAction() { + const nextState = yield { type: 'UPDATE' }; + return { type: 'CHANGE', nextState }; + } + + store.dispatch( getPostAction() ); + + expect( store.getState() ).toEqual( post ); + } ); } );