125
}
126
127
it('increases priority of updates as time progresses', async () => {
128
- if (gate(flags => flags.enableSyncDefaultUpdates)) {
128
+ if (gate(flags => flags.forceConcurrentByDefaultForTesting)) {
129
+ ReactNoop.render(<span prop="done" />);
130
+ expect(ReactNoop).toMatchRenderedOutput(null);
131
+
132
+ // Nothing has expired yet because time hasn't advanced.
133
+ flushNextRenderIfExpired();
134
+ expect(ReactNoop).toMatchRenderedOutput(null);
135
+ // Advance time a bit, but not enough to expire the low pri update.
136
+ ReactNoop.expire(4500);
137
+ flushNextRenderIfExpired();
138
+ expect(ReactNoop).toMatchRenderedOutput(null);
139
+ // Advance by another second. Now the update should expire and flush.
140
+ ReactNoop.expire(500);
141
+ flushNextRenderIfExpired();
142
+ expect(ReactNoop).toMatchRenderedOutput(<span prop="done" />);
143
+ } else {
144
ReactNoop.render(<Text text="Step 1" />);
145
React.startTransition(() => {
146
ReactNoop.render(<Text text="Step 2" />);
162
ReactNoop.expire(500);
163
await unstable_waitForExpired(['Step 2']);
164
expect(ReactNoop).toMatchRenderedOutput('Step 2');
150
- } else {
151
- ReactNoop.render(<span prop="done" />);
152
- expect(ReactNoop).toMatchRenderedOutput(null);
153
-
154
- // Nothing has expired yet because time hasn't advanced.
155
- flushNextRenderIfExpired();
156
- expect(ReactNoop).toMatchRenderedOutput(null);
157
- // Advance time a bit, but not enough to expire the low pri update.
158
- ReactNoop.expire(4500);
159
- flushNextRenderIfExpired();
160
- expect(ReactNoop).toMatchRenderedOutput(null);
161
- // Advance by another second. Now the update should expire and flush.
162
- ReactNoop.expire(500);
163
- flushNextRenderIfExpired();
164
- expect(ReactNoop).toMatchRenderedOutput(<span prop="done" />);
165
}
166
});
167
187
188
// First, show what happens for updates in two separate events.
189
// Schedule an update.
190
- if (gate(flags => flags.enableSyncDefaultUpdates)) {
191
- React.startTransition(() => {
192
- ReactNoop.render(<TextClass text="A" />);
193
- });
194
- } else {
190
+ React.startTransition(() => {
191
ReactNoop.render(<TextClass text="A" />);
196
- }
192
+ });
193
// Advance the timer.
194
Scheduler.unstable_advanceTime(2000);
195
// Partially flush the first update, then interrupt it.
244
245
// First, show what happens for updates in two separate events.
246
// Schedule an update.
251
- if (gate(flags => flags.enableSyncDefaultUpdates)) {
252
- React.startTransition(() => {
253
- ReactNoop.render(<TextClass text="A" />);
254
- });
255
- } else {
247
+ React.startTransition(() => {
248
ReactNoop.render(<TextClass text="A" />);
257
- }
249
+ });
250
+
251
// Advance the timer.
252
Scheduler.unstable_advanceTime(2000);
253
// Partially flush the first update, then interrupt it.
313
}
314
315
// Initial mount
323
- if (gate(flags => flags.enableSyncDefaultUpdates)) {
324
- React.startTransition(() => {
325
- ReactNoop.render(<App />);
326
- });
327
- } else {
316
+ React.startTransition(() => {
317
ReactNoop.render(<App />);
329
- }
318
+ });
319
+
320
await waitForAll([
321
'initial [A] [render]',
322
'initial [B] [render]',
329
]);
330
331
// Partial update
342
- if (gate(flags => flags.enableSyncDefaultUpdates)) {
343
- React.startTransition(() => {
344
- subscribers.forEach(s => s.setState({text: '1'}));
345
- });
346
- } else {
332
+ React.startTransition(() => {
333
subscribers.forEach(s => s.setState({text: '1'}));
348
- }
334
+ });
335
+
336
await waitFor(['1 [A] [render]', '1 [B] [render]']);
337
338
// Before the update can finish, update again. Even though no time has
358
);
359
}
360
374
- if (gate(flags => flags.enableSyncDefaultUpdates)) {
375
- React.startTransition(() => {
376
- root.render(<App />);
377
- });
378
- } else {
361
+ React.startTransition(() => {
362
root.render(<App />);
380
- }
363
+ });
364
365
await waitFor(['A']);
366
await waitFor(['B']);
387
</>
388
);
389
}
407
- if (gate(flags => flags.enableSyncDefaultUpdates)) {
408
- React.startTransition(() => {
409
- root.render(<App />);
410
- });
411
- } else {
390
+ React.startTransition(() => {
391
root.render(<App />);
413
- }
392
+ });
393
394
await waitFor(['A']);
395
await waitFor(['B']);
408
jest.resetModules();
409
Scheduler = require('scheduler');
410
432
- if (gate(flags => flags.enableSyncDefaultUpdates)) {
411
+ if (gate(flags => flags.forceConcurrentByDefaultForTesting)) {
412
+ // Before importing the renderer, advance the current time by a number
413
+ // larger than the maximum allowed for bitwise operations.
414
+ const maxSigned31BitInt = 1073741823;
415
+ Scheduler.unstable_advanceTime(maxSigned31BitInt * 100);
416
+ // Now import the renderer. On module initialization, it will read the
417
+ // current time.
418
+ ReactNoop = require('react-noop-renderer');
419
+ ReactNoop.render('Hi');
420
+
421
+ // The update should not have expired yet.
422
+ flushNextRenderIfExpired();
423
+ await waitFor([]);
424
+ expect(ReactNoop).toMatchRenderedOutput(null);
425
+ // Advance the time some more to expire the update.
426
+ Scheduler.unstable_advanceTime(10000);
427
+ flushNextRenderIfExpired();
428
+ await waitFor([]);
429
+ expect(ReactNoop).toMatchRenderedOutput('Hi');
430
+ } else {
431
const InternalTestUtils = require('internal-test-utils');
432
waitFor = InternalTestUtils.waitFor;
433
assertLog = InternalTestUtils.assertLog;
444
React = require('react');
445
446
ReactNoop.render(<Text text="Step 1" />);
449
- if (gate(flags => flags.enableSyncDefaultUpdates)) {
450
- React.startTransition(() => {
451
- ReactNoop.render(<Text text="Step 2" />);
452
- });
453
- await waitFor(['Step 1']);
454
- } else {
455
- ReactNoop.render('Hi');
456
- }
447
+ React.startTransition(() => {
448
+ ReactNoop.render(<Text text="Step 2" />);
449
+ });
450
+ await waitFor(['Step 1']);
451
452
// The update should not have expired yet.
453
await unstable_waitForExpired([]);
458
Scheduler.unstable_advanceTime(10000);
459
await unstable_waitForExpired(['Step 2']);
460
expect(ReactNoop).toMatchRenderedOutput('Step 2');
467
- } else {
468
- // Before importing the renderer, advance the current time by a number
469
- // larger than the maximum allowed for bitwise operations.
470
- const maxSigned31BitInt = 1073741823;
471
- Scheduler.unstable_advanceTime(maxSigned31BitInt * 100);
472
- // Now import the renderer. On module initialization, it will read the
473
- // current time.
474
- ReactNoop = require('react-noop-renderer');
475
- ReactNoop.render('Hi');
476
-
477
- // The update should not have expired yet.
478
- flushNextRenderIfExpired();
479
- await waitFor([]);
480
- expect(ReactNoop).toMatchRenderedOutput(null);
481
- // Advance the time some more to expire the update.
482
- Scheduler.unstable_advanceTime(10000);
483
- flushNextRenderIfExpired();
484
- await waitFor([]);
485
- expect(ReactNoop).toMatchRenderedOutput('Hi');
461
}
462
});
463
469
// Before scheduling an update, advance the current time.
470
Scheduler.unstable_advanceTime(10000);
471
497
- if (gate(flags => flags.enableSyncDefaultUpdates)) {
498
- React.startTransition(() => {
499
- ReactNoop.render('Hi');
500
- });
501
- } else {
472
+ React.startTransition(() => {
473
ReactNoop.render('Hi');
503
- }
474
+ });
475
+
476
await unstable_waitForExpired([]);
477
expect(ReactNoop).toMatchRenderedOutput(null);
478
513
514
// First demonstrate what happens when there's no starvation
515
await act(async () => {
544
- if (gate(flags => flags.enableSyncDefaultUpdates)) {
545
- React.startTransition(() => {
546
- updateNormalPri();
547
- });
548
- } else {
516
+ React.startTransition(() => {
517
updateNormalPri();
550
- }
518
+ });
519
await waitFor(['Sync pri: 0']);
520
updateSyncPri();
521
assertLog(['Sync pri: 1', 'Normal pri: 0']);
533
534
// Do the same thing, but starve the first update
535
await act(async () => {
568
- if (gate(flags => flags.enableSyncDefaultUpdates)) {
569
- React.startTransition(() => {
570
- updateNormalPri();
571
- });
572
- } else {
536
+ React.startTransition(() => {
537
updateNormalPri();
574
- }
538
+ });
539
await waitFor(['Sync pri: 1']);
540
541
// This time, a lot of time has elapsed since the normal pri update