@@ -18,7 +18,9 @@ let use;
18
18
let useOptimistic ;
19
19
let useState ;
20
20
let useTransition ;
21
+ let useDeferredValue ;
21
22
let assertLog ;
23
+ let waitForPaint ;
22
24
23
25
describe ( 'ReactDefaultTransitionIndicator' , ( ) => {
24
26
beforeEach ( ( ) => {
@@ -27,12 +29,15 @@ describe('ReactDefaultTransitionIndicator', () => {
27
29
React = require ( 'react' ) ;
28
30
ReactNoop = require ( 'react-noop-renderer' ) ;
29
31
Scheduler = require ( 'scheduler' ) ;
30
- act = require ( 'internal-test-utils' ) . act ;
31
- assertLog = require ( 'internal-test-utils' ) . assertLog ;
32
+ const InternalTestUtils = require ( 'internal-test-utils' ) ;
33
+ act = InternalTestUtils . act ;
34
+ assertLog = InternalTestUtils . assertLog ;
35
+ waitForPaint = InternalTestUtils . waitForPaint ;
32
36
use = React . use ;
33
37
useOptimistic = React . useOptimistic ;
34
38
useState = React . useState ;
35
39
useTransition = React . useTransition ;
40
+ useDeferredValue = React . useDeferredValue ;
36
41
} ) ;
37
42
38
43
// @gate enableDefaultTransitionIndicator
@@ -277,4 +282,77 @@ describe('ReactDefaultTransitionIndicator', () => {
277
282
278
283
expect ( root ) . toMatchRenderedOutput ( 'Hi' ) ;
279
284
} ) ;
285
+
286
+ it ( 'should not trigger for useDeferredValue (sync)' , async ( ) => {
287
+ function Text ( { text} ) {
288
+ Scheduler . log ( text ) ;
289
+ return text ;
290
+ }
291
+ function App ( { value} ) {
292
+ const deferredValue = useDeferredValue ( value , 'Hi' ) ;
293
+ return < Text text = { deferredValue } /> ;
294
+ }
295
+
296
+ const root = ReactNoop . createRoot ( {
297
+ onDefaultTransitionIndicator ( ) {
298
+ Scheduler . log ( 'start' ) ;
299
+ return ( ) => {
300
+ Scheduler . log ( 'stop' ) ;
301
+ } ;
302
+ } ,
303
+ } ) ;
304
+ await act ( async ( ) => {
305
+ root . render ( < App value = "Hello" /> ) ;
306
+ await waitForPaint ( [ 'Hi' ] ) ;
307
+ expect ( root ) . toMatchRenderedOutput ( 'Hi' ) ;
308
+ } ) ;
309
+
310
+ assertLog ( [ 'Hello' ] ) ;
311
+
312
+ expect ( root ) . toMatchRenderedOutput ( 'Hello' ) ;
313
+
314
+ assertLog ( [ ] ) ;
315
+
316
+ await act ( async ( ) => {
317
+ root . render ( < App value = "Bye" /> ) ;
318
+ await waitForPaint ( [ 'Hello' ] ) ;
319
+ expect ( root ) . toMatchRenderedOutput ( 'Hello' ) ;
320
+ } ) ;
321
+
322
+ assertLog ( [ 'Bye' ] ) ;
323
+
324
+ expect ( root ) . toMatchRenderedOutput ( 'Bye' ) ;
325
+ } ) ;
326
+
327
+ // @gate enableDefaultTransitionIndicator
328
+ it ( 'should not trigger for useDeferredValue (transition)' , async ( ) => {
329
+ function Text ( { text} ) {
330
+ Scheduler . log ( text ) ;
331
+ return text ;
332
+ }
333
+ function App ( { value} ) {
334
+ const deferredValue = useDeferredValue ( value , 'Hi' ) ;
335
+ return < Text text = { deferredValue } /> ;
336
+ }
337
+
338
+ const root = ReactNoop . createRoot ( {
339
+ onDefaultTransitionIndicator ( ) {
340
+ Scheduler . log ( 'start' ) ;
341
+ return ( ) => {
342
+ Scheduler . log ( 'stop' ) ;
343
+ } ;
344
+ } ,
345
+ } ) ;
346
+ await act ( async ( ) => {
347
+ React . startTransition ( ( ) => {
348
+ root . render ( < App value = "Hello" /> ) ;
349
+ } ) ;
350
+ await waitForPaint ( [ 'start' , 'Hi' , 'stop' ] ) ;
351
+ expect ( root ) . toMatchRenderedOutput ( 'Hi' ) ;
352
+ } ) ;
353
+
354
+ assertLog ( [ 'Hello' ] ) ;
355
+
356
+ expect ( root ) . toMatchRenderedOutput ( 'Hello' ) ;
357
+ } ) ;
280
358
} ) ;
0 commit comments