diff --git a/packages/react-reconciler/src/ReactFiberHooks.js b/packages/react-reconciler/src/ReactFiberHooks.js index 3d6de1be19..5122a8dda4 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.js +++ b/packages/react-reconciler/src/ReactFiberHooks.js @@ -253,7 +253,7 @@ function cloneHook(hook: Hook): Hook { return { memoizedState: hook.memoizedState, - baseState: hook.memoizedState, + baseState: hook.baseState, queue: hook.queue, baseUpdate: hook.baseUpdate, diff --git a/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js b/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js index 36030a2124..ea56721474 100644 --- a/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js @@ -565,6 +565,39 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.flush(); expect(ReactNoop.getChildren()).toEqual([span('Count: 8')]); }); + + // Regression test for https://github.com/facebook/react/issues/14360 + it('handles dispatches with mixed priorities', () => { + const INCREMENT = 'INCREMENT'; + + function reducer(state, action) { + return action === INCREMENT ? state + 1 : state; + } + + function Counter(props, ref) { + const [count, dispatch] = useReducer(reducer, 0); + useImperativeMethods(ref, () => ({dispatch})); + return ; + } + + Counter = forwardRef(Counter); + const counter = React.createRef(null); + ReactNoop.render(); + + ReactNoop.flush(); + expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); + + counter.current.dispatch(INCREMENT); + counter.current.dispatch(INCREMENT); + counter.current.dispatch(INCREMENT); + ReactNoop.flushSync(() => { + counter.current.dispatch(INCREMENT); + }); + expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); + + ReactNoop.flush(); + expect(ReactNoop.getChildren()).toEqual([span('Count: 4')]); + }); }); describe('useEffect', () => {