@@ -2071,4 +2071,66 @@ describe('ReactHooksWithNoopRenderer', () => {
2071
2071
expect ( Scheduler ) . toFlushAndYield ( [ 'Step: 5, Shadow: 5' ] ) ;
2072
2072
expect ( ReactNoop ) . toMatchRenderedOutput ( '5' ) ;
2073
2073
} ) ;
2074
+
2075
+ it ( 'successful eager bailout should not store dispatched item in the queue' , ( ) => {
2076
+ let setDisabled ;
2077
+ let increment ;
2078
+
2079
+ function Counter ( { disabled } ) {
2080
+ const [ count , dispatch ] = useReducer ( ( state , action ) => {
2081
+ if ( disabled ) {
2082
+ return state ;
2083
+ }
2084
+ if ( action . type === 'increment' ) {
2085
+ return state + 1 ;
2086
+ }
2087
+ return state ;
2088
+ } , 0 ) ;
2089
+
2090
+ increment = ( ) => dispatch ( { type : 'increment' } )
2091
+
2092
+ Scheduler . yieldValue ( 'Render count: ' + count ) ;
2093
+ return count ;
2094
+ }
2095
+
2096
+ function App ( ) {
2097
+ const [ disabled , _setDisabled ] = useState ( false ) ;
2098
+ setDisabled = _setDisabled ;
2099
+ Scheduler . yieldValue ( 'Render disabled: ' + disabled ) ;
2100
+ return < Counter disabled = { disabled } /> ;
2101
+ }
2102
+
2103
+ ReactNoop . render ( < App /> ) ;
2104
+ expect ( Scheduler ) . toFlushAndYield ( [
2105
+ 'Render disabled: false' ,
2106
+ 'Render count: 0' ,
2107
+ ] ) ;
2108
+ expect ( ReactNoop ) . toMatchRenderedOutput ( '0' ) ;
2109
+
2110
+ act ( ( ) => {
2111
+ increment ( )
2112
+ } ) ;
2113
+ expect ( Scheduler ) . toFlushAndYield ( [ 'Render count: 1' ] ) ;
2114
+ expect ( ReactNoop ) . toMatchRenderedOutput ( '1' ) ;
2115
+
2116
+ act ( ( ) => {
2117
+ setDisabled ( true ) ;
2118
+ increment ( ) ;
2119
+ increment ( ) ;
2120
+ } ) ;
2121
+ expect ( Scheduler ) . toFlushAndYield ( [
2122
+ 'Render disabled: true' ,
2123
+ 'Render count: 1' ,
2124
+ ] ) ;
2125
+ expect ( ReactNoop ) . toMatchRenderedOutput ( '1' ) ;
2126
+
2127
+ act ( ( ) => {
2128
+ setDisabled ( false ) ;
2129
+ } ) ;
2130
+ expect ( Scheduler ) . toFlushAndYield ( [
2131
+ 'Render disabled: false' ,
2132
+ 'Render count: 1' ,
2133
+ ] ) ;
2134
+ expect ( ReactNoop ) . toMatchRenderedOutput ( '1' ) ;
2135
+ } ) ;
2074
2136
} ) ;
0 commit comments