@@ -284,6 +284,46 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
284
284
expect ( container . textContent ) . toEqual ( 'hovered' ) ;
285
285
} ) ;
286
286
287
+ // @gate experimental
288
+ it ( 'continuous native events flush as expected' , async ( ) => {
289
+ const root = ReactDOM . unstable_createRoot ( container ) ;
290
+
291
+ const target = React . createRef ( null ) ;
292
+ function Foo ( { hovered} ) {
293
+ const hoverString = hovered ? 'hovered' : 'not hovered' ;
294
+ Scheduler . unstable_yieldValue ( hoverString ) ;
295
+ return < div ref = { target } > { hoverString } </ div > ;
296
+ }
297
+
298
+ await act ( async ( ) => {
299
+ root . render ( < Foo hovered = { false } /> ) ;
300
+ } ) ;
301
+ expect ( container . textContent ) . toEqual ( 'not hovered' ) ;
302
+
303
+ await act ( async ( ) => {
304
+ // Note: React does not use native mouseenter/mouseleave events
305
+ // but we should still correctly determine their priority.
306
+ const mouseEnterEvent = document . createEvent ( 'MouseEvents' ) ;
307
+ mouseEnterEvent . initEvent ( 'mouseover' , true , true ) ;
308
+ target . current . addEventListener ( 'mouseover' , ( ) => {
309
+ root . render ( < Foo hovered = { true } /> ) ;
310
+ } ) ;
311
+ dispatchAndSetCurrentEvent ( target . current , mouseEnterEvent ) ;
312
+
313
+ // Since mouse end is not discrete, should not have updated yet
314
+ expect ( Scheduler ) . toHaveYielded ( [ 'not hovered' ] ) ;
315
+ expect ( container . textContent ) . toEqual ( 'not hovered' ) ;
316
+
317
+ expect ( Scheduler ) . toFlushAndYieldThrough ( [ 'hovered' ] ) ;
318
+ if ( gate ( flags => flags . enableSyncDefaultUpdates ) ) {
319
+ expect ( container . textContent ) . toEqual ( 'hovered' ) ;
320
+ } else {
321
+ expect ( container . textContent ) . toEqual ( 'not hovered' ) ;
322
+ }
323
+ } ) ;
324
+ expect ( container . textContent ) . toEqual ( 'hovered' ) ;
325
+ } ) ;
326
+
287
327
// @gate experimental
288
328
it ( 'should batch inside native events' , async ( ) => {
289
329
const root = ReactDOM . unstable_createRoot ( container ) ;
0 commit comments