@@ -18,7 +18,9 @@ let use;
1818let useOptimistic ;
1919let useState ;
2020let useTransition ;
21+ let useDeferredValue ;
2122let assertLog ;
23+ let waitForPaint ;
2224
2325describe ( 'ReactDefaultTransitionIndicator' , ( ) => {
2426 beforeEach ( ( ) => {
@@ -27,12 +29,15 @@ describe('ReactDefaultTransitionIndicator', () => {
2729 React = require ( 'react' ) ;
2830 ReactNoop = require ( 'react-noop-renderer' ) ;
2931 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 ;
3236 use = React . use ;
3337 useOptimistic = React . useOptimistic ;
3438 useState = React . useState ;
3539 useTransition = React . useTransition ;
40+ useDeferredValue = React . useDeferredValue ;
3641 } ) ;
3742
3843 // @gate enableDefaultTransitionIndicator
@@ -277,4 +282,77 @@ describe('ReactDefaultTransitionIndicator', () => {
277282
278283 expect ( root ) . toMatchRenderedOutput ( 'Hi' ) ;
279284 } ) ;
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+ } ) ;
280358} ) ;
0 commit comments