@@ -2071,4 +2071,57 @@ 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 ( true ) ;
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: true' ,
2106
+ 'Render count: 0' ,
2107
+ ] ) ;
2108
+ expect ( ReactNoop ) . toMatchRenderedOutput ( '0' ) ;
2109
+
2110
+ act ( ( ) => {
2111
+ increment ( ) ;
2112
+ increment ( ) ;
2113
+ increment ( ) ;
2114
+ } ) ;
2115
+ expect ( Scheduler ) . toFlushAndYield ( [ ] ) ;
2116
+ expect ( ReactNoop ) . toMatchRenderedOutput ( '0' ) ;
2117
+
2118
+ act ( ( ) => {
2119
+ setDisabled ( false ) ;
2120
+ } ) ;
2121
+ expect ( Scheduler ) . toFlushAndYield ( [
2122
+ 'Render disabled: false' ,
2123
+ 'Render count: 0' ,
2124
+ ] ) ;
2125
+ expect ( ReactNoop ) . toMatchRenderedOutput ( '0' ) ;
2126
+ } ) ;
2074
2127
} ) ;
0 commit comments