@@ -654,127 +654,133 @@ describe('ReactIncrementalUpdates', () => {
654654 } ) ;
655655 } ) ;
656656
657- it ( 'when rebasing, does not exclude updates that were already committed, regardless of priority' , async ( ) => {
658- const { useState, useLayoutEffect} = React ;
659-
660- let pushToLog ;
661- function App ( ) {
662- const [ log , setLog ] = useState ( '' ) ;
663- pushToLog = msg => {
664- setLog ( prevLog => prevLog + msg ) ;
665- } ;
657+ it . experimental (
658+ 'when rebasing, does not exclude updates that were already committed, regardless of priority' ,
659+ async ( ) => {
660+ const { useState, useLayoutEffect} = React ;
661+
662+ let pushToLog ;
663+ function App ( ) {
664+ const [ log , setLog ] = useState ( '' ) ;
665+ pushToLog = msg => {
666+ setLog ( prevLog => prevLog + msg ) ;
667+ } ;
666668
667- useLayoutEffect (
668- ( ) => {
669- Scheduler . unstable_yieldValue ( 'Committed: ' + log ) ;
670- if ( log === 'B' ) {
669+ useLayoutEffect (
670+ ( ) => {
671+ Scheduler . unstable_yieldValue ( 'Committed: ' + log ) ;
672+ if ( log === 'B' ) {
673+ // Right after B commits, schedule additional updates.
674+ Scheduler . unstable_runWithPriority (
675+ Scheduler . unstable_UserBlockingPriority ,
676+ ( ) => {
677+ pushToLog ( 'C' ) ;
678+ } ,
679+ ) ;
680+ setLog ( prevLog => prevLog + 'D' ) ;
681+ }
682+ } ,
683+ [ log ] ,
684+ ) ;
685+
686+ return log ;
687+ }
688+
689+ const root = ReactNoop . createRoot ( ) ;
690+ await ReactNoop . act ( async ( ) => {
691+ root . render ( < App /> ) ;
692+ } ) ;
693+ expect ( Scheduler ) . toHaveYielded ( [ 'Committed: ' ] ) ;
694+ expect ( root ) . toMatchRenderedOutput ( '' ) ;
695+
696+ await ReactNoop . act ( async ( ) => {
697+ pushToLog ( 'A' ) ;
698+ Scheduler . unstable_runWithPriority (
699+ Scheduler . unstable_UserBlockingPriority ,
700+ ( ) => {
701+ pushToLog ( 'B' ) ;
702+ } ,
703+ ) ;
704+ } ) ;
705+ expect ( Scheduler ) . toHaveYielded ( [
706+ // A and B are pending. B is higher priority, so we'll render that first.
707+ 'Committed: B' ,
708+ // Because A comes first in the queue, we're now in rebase mode. B must
709+ // be rebased on top of A. Also, in a layout effect, we received two new
710+ // updates: C and D. C is user-blocking and D is synchronous.
711+ //
712+ // First render the synchronous update. What we're testing here is that
713+ // B *is not dropped* even though it has lower than sync priority. That's
714+ // because we already committed it. However, this render should not
715+ // include C, because that update wasn't already committed.
716+ 'Committed: BD' ,
717+ 'Committed: BCD' ,
718+ 'Committed: ABCD' ,
719+ ] ) ;
720+ expect ( root ) . toMatchRenderedOutput ( 'ABCD' ) ;
721+ } ,
722+ ) ;
723+
724+ it . experimental (
725+ 'when rebasing, does not exclude updates that were already committed, regardless of priority (classes)' ,
726+ async ( ) => {
727+ let pushToLog ;
728+ class App extends React . Component {
729+ state = { log : '' } ;
730+ pushToLog = msg => {
731+ this . setState ( prevState => ( { log : prevState . log + msg } ) ) ;
732+ } ;
733+ componentDidUpdate ( ) {
734+ Scheduler . unstable_yieldValue ( 'Committed: ' + this . state . log ) ;
735+ if ( this . state . log === 'B' ) {
671736 // Right after B commits, schedule additional updates.
672737 Scheduler . unstable_runWithPriority (
673738 Scheduler . unstable_UserBlockingPriority ,
674739 ( ) => {
675- pushToLog ( 'C' ) ;
740+ this . pushToLog ( 'C' ) ;
676741 } ,
677742 ) ;
678- setLog ( prevLog => prevLog + 'D' ) ;
743+ this . pushToLog ( 'D' ) ;
679744 }
680- } ,
681- [ log ] ,
682- ) ;
683-
684- return log ;
685- }
686-
687- const root = ReactNoop . createRoot ( ) ;
688- await ReactNoop . act ( async ( ) => {
689- root . render ( < App /> ) ;
690- } ) ;
691- expect ( Scheduler ) . toHaveYielded ( [ 'Committed: ' ] ) ;
692- expect ( root ) . toMatchRenderedOutput ( '' ) ;
693-
694- await ReactNoop . act ( async ( ) => {
695- pushToLog ( 'A' ) ;
696- Scheduler . unstable_runWithPriority (
697- Scheduler . unstable_UserBlockingPriority ,
698- ( ) => {
699- pushToLog ( 'B' ) ;
700- } ,
701- ) ;
702- } ) ;
703- expect ( Scheduler ) . toHaveYielded ( [
704- // A and B are pending. B is higher priority, so we'll render that first.
705- 'Committed: B' ,
706- // Because A comes first in the queue, we're now in rebase mode. B must
707- // be rebased on top of A. Also, in a layout effect, we received two new
708- // updates: C and D. C is user-blocking and D is synchronous.
709- //
710- // First render the synchronous update. What we're testing here is that
711- // B *is not dropped* even though it has lower than sync priority. That's
712- // because we already committed it. However, this render should not
713- // include C, because that update wasn't already committed.
714- 'Committed: BD' ,
715- 'Committed: BCD' ,
716- 'Committed: ABCD' ,
717- ] ) ;
718- expect ( root ) . toMatchRenderedOutput ( 'ABCD' ) ;
719- } ) ;
720-
721- it ( 'when rebasing, does not exclude updates that were already committed, regardless of priority (classes)' , async ( ) => {
722- let pushToLog ;
723- class App extends React . Component {
724- state = { log : '' } ;
725- pushToLog = msg => {
726- this . setState ( prevState => ( { log : prevState . log + msg } ) ) ;
727- } ;
728- componentDidUpdate ( ) {
729- Scheduler . unstable_yieldValue ( 'Committed: ' + this . state . log ) ;
730- if ( this . state . log === 'B' ) {
731- // Right after B commits, schedule additional updates.
732- Scheduler . unstable_runWithPriority (
733- Scheduler . unstable_UserBlockingPriority ,
734- ( ) => {
735- this . pushToLog ( 'C' ) ;
736- } ,
737- ) ;
738- this . pushToLog ( 'D' ) ;
745+ }
746+ render ( ) {
747+ pushToLog = this . pushToLog ;
748+ return this . state . log ;
739749 }
740750 }
741- render ( ) {
742- pushToLog = this . pushToLog ;
743- return this . state . log ;
744- }
745- }
746751
747- const root = ReactNoop . createRoot ( ) ;
748- await ReactNoop . act ( async ( ) => {
749- root . render ( < App /> ) ;
750- } ) ;
751- expect ( Scheduler ) . toHaveYielded ( [ ] ) ;
752- expect ( root ) . toMatchRenderedOutput ( '' ) ;
753-
754- await ReactNoop . act ( async ( ) => {
755- pushToLog ( 'A' ) ;
756- Scheduler . unstable_runWithPriority (
757- Scheduler . unstable_UserBlockingPriority ,
758- ( ) => {
759- pushToLog ( 'B' ) ;
760- } ,
761- ) ;
762- } ) ;
763- expect ( Scheduler ) . toHaveYielded ( [
764- // A and B are pending. B is higher priority, so we'll render that first.
765- 'Committed: B' ,
766- // Because A comes first in the queue, we're now in rebase mode. B must
767- // be rebased on top of A. Also, in a layout effect, we received two new
768- // updates: C and D. C is user-blocking and D is synchronous.
769- //
770- // First render the synchronous update. What we're testing here is that
771- // B *is not dropped* even though it has lower than sync priority. That's
772- // because we already committed it. However, this render should not
773- // include C, because that update wasn't already committed.
774- 'Committed: BD' ,
775- 'Committed: BCD' ,
776- 'Committed: ABCD' ,
777- ] ) ;
778- expect ( root ) . toMatchRenderedOutput ( 'ABCD' ) ;
779- } ) ;
752+ const root = ReactNoop . createRoot ( ) ;
753+ await ReactNoop . act ( async ( ) => {
754+ root . render ( < App /> ) ;
755+ } ) ;
756+ expect ( Scheduler ) . toHaveYielded ( [ ] ) ;
757+ expect ( root ) . toMatchRenderedOutput ( '' ) ;
758+
759+ await ReactNoop . act ( async ( ) => {
760+ pushToLog ( 'A' ) ;
761+ Scheduler . unstable_runWithPriority (
762+ Scheduler . unstable_UserBlockingPriority ,
763+ ( ) => {
764+ pushToLog ( 'B' ) ;
765+ } ,
766+ ) ;
767+ } ) ;
768+ expect ( Scheduler ) . toHaveYielded ( [
769+ // A and B are pending. B is higher priority, so we'll render that first.
770+ 'Committed: B' ,
771+ // Because A comes first in the queue, we're now in rebase mode. B must
772+ // be rebased on top of A. Also, in a layout effect, we received two new
773+ // updates: C and D. C is user-blocking and D is synchronous.
774+ //
775+ // First render the synchronous update. What we're testing here is that
776+ // B *is not dropped* even though it has lower than sync priority. That's
777+ // because we already committed it. However, this render should not
778+ // include C, because that update wasn't already committed.
779+ 'Committed: BD' ,
780+ 'Committed: BCD' ,
781+ 'Committed: ABCD' ,
782+ ] ) ;
783+ expect ( root ) . toMatchRenderedOutput ( 'ABCD' ) ;
784+ } ,
785+ ) ;
780786} ) ;
0 commit comments