Skip to content

Commit e0e1662

Browse files
committed
Fixes with alwaysThrottleRetries
1 parent e83bf3f commit e0e1662

File tree

9 files changed

+128
-36
lines changed

9 files changed

+128
-36
lines changed

packages/react-cache/src/__tests__/ReactCacheOld-test.internal.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,28 @@ describe('ReactCache', () => {
218218
await waitForPaint(['Suspend! [1]', 'Loading...']);
219219
jest.advanceTimersByTime(100);
220220
assertLog(['Promise resolved [1]']);
221-
await waitForAll([1, 'Suspend! [2]']);
221+
await waitForAll([
222+
1,
223+
'Suspend! [2]',
224+
...(gate('alwaysThrottleRetries')
225+
? []
226+
: [1, 'Suspend! [2]', 'Suspend! [3]']),
227+
]);
222228

223229
jest.advanceTimersByTime(100);
224-
assertLog(['Promise resolved [2]']);
225-
await waitForAll([1, 2, 'Suspend! [3]']);
230+
assertLog([
231+
'Promise resolved [2]',
232+
...(gate('alwaysThrottleRetries') ? [] : ['Promise resolved [3]']),
233+
]);
234+
await waitForAll([
235+
1,
236+
2,
237+
...(gate('alwaysThrottleRetries') ? ['Suspend! [3]'] : [3]),
238+
]);
226239

227240
jest.advanceTimersByTime(100);
228-
assertLog(['Promise resolved [3]']);
229-
await waitForAll([1, 2, 3]);
241+
assertLog(gate('alwaysThrottleRetries') ? ['Promise resolved [3]'] : []);
242+
await waitForAll(gate('alwaysThrottleRetries') ? [1, 2, 3] : []);
230243

231244
await act(() => jest.advanceTimersByTime(100));
232245
expect(root).toMatchRenderedOutput('123');

packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ describe('ReactLazy', () => {
198198

199199
await resolveFakeImport(Foo);
200200

201-
await waitForAll(['Foo']);
201+
await waitForAll([
202+
'Foo',
203+
...(gate('alwaysThrottleRetries') ? [] : ['Foo']),
204+
]);
202205
expect(root).not.toMatchRenderedOutput('FooBar');
203206

204207
await act(() => resolveFakeImport(Bar));

packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ describe('ReactSuspense', () => {
175175
// Resolve first Suspense's promise and switch back to the normal view. The
176176
// second Suspense should still show the placeholder
177177
await act(() => resolveText('A'));
178-
assertLog(['A', 'Suspend! [B]', 'Suspend! [B]']);
178+
assertLog([
179+
'A',
180+
...(gate('alwaysThrottleRetries')
181+
? ['Suspend! [B]', 'Suspend! [B]']
182+
: []),
183+
]);
179184
expect(container.textContent).toEqual('ALoading B...');
180185

181186
// Resolve the second Suspense's promise resolves and switche back to the
@@ -686,7 +691,13 @@ describe('ReactSuspense', () => {
686691
'Suspend! [Child 2]',
687692
]);
688693
await resolveText('Child 1');
689-
await waitForAll(['Child 1', 'Suspend! [Child 2]']);
694+
await waitForAll([
695+
'Child 1',
696+
'Suspend! [Child 2]',
697+
...(gate('alwaysThrottleRetries')
698+
? []
699+
: ['Child 1', 'Suspend! [Child 2]']),
700+
]);
690701

691702
jest.advanceTimersByTime(6000);
692703

packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@ describe('ReactSuspense', () => {
6060

6161
ReactNoop.render(elementBadType);
6262
await waitForAll([]);
63-
assertConsoleErrorDev(['Unexpected type for suspenseCallback.'], {
64-
withoutStack: true,
65-
});
63+
assertConsoleErrorDev(
64+
[
65+
'Unexpected type for suspenseCallback.',
66+
...(gate('alwaysThrottleRetries')
67+
? []
68+
: ['Unexpected type for suspenseCallback.']),
69+
],
70+
{
71+
withoutStack: true,
72+
},
73+
);
6674

6775
const elementMissingCallback = (
6876
<React.Suspense fallback={'Waiting'}>
@@ -93,7 +101,10 @@ describe('ReactSuspense', () => {
93101
ReactNoop.render(element);
94102
await waitForAll([]);
95103
expect(ReactNoop).toMatchRenderedOutput('Waiting');
96-
expect(ops).toEqual([new Set([promise])]);
104+
expect(ops).toEqual([
105+
new Set([promise]),
106+
...(gate('alwaysThrottleRetries') ? [] : new Set([promise])),
107+
]);
97108
ops = [];
98109

99110
await act(() => resolve());
@@ -132,7 +143,10 @@ describe('ReactSuspense', () => {
132143
ReactNoop.render(element);
133144
await waitForAll([]);
134145
expect(ReactNoop).toMatchRenderedOutput('Waiting Tier 1');
135-
expect(ops).toEqual([new Set([promise1])]);
146+
expect(ops).toEqual([
147+
new Set([promise1]),
148+
...(gate('alwaysThrottleRetries') ? [] : new Set([promise1, promise2])),
149+
]);
136150
ops = [];
137151

138152
await act(() => resolve1());
@@ -178,7 +192,10 @@ describe('ReactSuspense', () => {
178192
await waitForAll([]);
179193
expect(ReactNoop).toMatchRenderedOutput('Waiting Tier 2');
180194
expect(ops1).toEqual([]);
181-
expect(ops2).toEqual([new Set([promise])]);
195+
expect(ops2).toEqual([
196+
new Set([promise]),
197+
...(gate('alwaysThrottleRetries') ? [] : [new Set([promise])]),
198+
]);
182199
});
183200

184201
// @gate enableSuspenseCallback

packages/react-reconciler/src/__tests__/ReactSuspenseList-test.js

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ describe('ReactSuspenseList', () => {
258258
);
259259

260260
await act(() => C.resolve());
261-
assertLog(['Suspend! [B]', 'C', 'Suspend! [B]']);
261+
assertLog(
262+
gate('alwaysThrottleRetries')
263+
? ['Suspend! [B]', 'C', 'Suspend! [B]']
264+
: ['C'],
265+
);
262266

263267
expect(ReactNoop).toMatchRenderedOutput(
264268
<>
@@ -1979,7 +1983,11 @@ describe('ReactSuspenseList', () => {
19791983

19801984
await B.resolve();
19811985

1982-
await waitForAll(['B', 'Suspend! [C]']);
1986+
await waitForAll([
1987+
'B',
1988+
'Suspend! [C]',
1989+
...(!gate('alwaysThrottleRetries') ? ['Suspend! [C]'] : []),
1990+
]);
19831991

19841992
// Incremental loading is suspended.
19851993
jest.advanceTimersByTime(500);
@@ -2742,7 +2750,9 @@ describe('ReactSuspenseList', () => {
27422750
<span>Loading...</span>
27432751
</>,
27442752
);
2745-
expect(onRender).toHaveBeenCalledTimes(1);
2753+
expect(onRender).toHaveBeenCalledTimes(
2754+
gate('alwaysThrottleRetries') ? 1 : 2,
2755+
);
27462756

27472757
// The treeBaseDuration should be the time to render each child. The last
27482758
// one counts the fallback time.
@@ -2765,12 +2775,18 @@ describe('ReactSuspenseList', () => {
27652775
<span>C</span>
27662776
</>,
27672777
);
2768-
expect(onRender).toHaveBeenCalledTimes(2);
2778+
expect(onRender).toHaveBeenCalledTimes(
2779+
gate('alwaysThrottleRetries') ? 2 : 3,
2780+
);
27692781

27702782
// actualDuration
2771-
expect(onRender.mock.calls[1][2]).toBe(1 + 4 + 5);
2783+
expect(onRender.mock.calls[1][2]).toBe(
2784+
gate('alwaysThrottleRetries') ? 1 + 4 + 5 : 5,
2785+
);
27722786
// treeBaseDuration
2773-
expect(onRender.mock.calls[1][3]).toBe(1 + 4 + 5);
2787+
expect(onRender.mock.calls[1][3]).toBe(
2788+
gate('alwaysThrottleRetries') ? 1 + 4 + 5 : 8,
2789+
);
27742790

27752791
ReactNoop.render(<App addRow={true} suspendTail={true} />);
27762792

@@ -2802,7 +2818,9 @@ describe('ReactSuspenseList', () => {
28022818
<span>Loading...</span>
28032819
</>,
28042820
);
2805-
expect(onRender).toHaveBeenCalledTimes(4);
2821+
expect(onRender).toHaveBeenCalledTimes(
2822+
gate('alwaysThrottleRetries') ? 4 : 5,
2823+
);
28062824

28072825
// The treeBaseDuration should be the time to render the first two
28082826
// children and then two fallbacks.
@@ -2811,9 +2829,13 @@ describe('ReactSuspenseList', () => {
28112829
// with force fallback mode.
28122830

28132831
// actualDuration
2814-
expect(onRender.mock.calls[2][2]).toBe((1 + 4 + 5 + 3) * 2 + 3);
2832+
expect(onRender.mock.calls[2][2]).toBe(
2833+
gate('alwaysThrottleRetries') ? (1 + 4 + 5 + 3) * 2 + 3 : 10,
2834+
);
28152835
// treeBaseDuration
2816-
expect(onRender.mock.calls[2][3]).toBe(1 + 4 + 3 + 3);
2836+
expect(onRender.mock.calls[2][3]).toBe(
2837+
gate('alwaysThrottleRetries') ? 1 + 4 + 3 + 3 : 10,
2838+
);
28172839

28182840
await act(() => C.resolve());
28192841
assertLog(['C', 'Suspend! [D]', 'Suspend! [D]']);
@@ -2826,10 +2848,14 @@ describe('ReactSuspenseList', () => {
28262848
</>,
28272849
);
28282850

2829-
expect(onRender).toHaveBeenCalledTimes(6);
2851+
expect(onRender).toHaveBeenCalledTimes(
2852+
gate('alwaysThrottleRetries') ? 6 : 7,
2853+
);
28302854

28312855
// actualDuration
2832-
expect(onRender.mock.calls[5][2]).toBe(12);
2856+
expect(onRender.mock.calls[5][2]).toBe(
2857+
gate('alwaysThrottleRetries') ? 12 : 17,
2858+
);
28332859
// treeBaseDuration
28342860
expect(onRender.mock.calls[5][3]).toBe(1 + 4 + 5 + 3);
28352861
});

packages/react-reconciler/src/__tests__/ReactSuspensePlaceholder-test.internal.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ describe('ReactSuspensePlaceholder', () => {
382382
// Since this is initial render we immediately commit the fallback. Another test below
383383
// deals with the update case where this suspends.
384384
expect(ReactNoop).toMatchRenderedOutput('Loading...');
385-
expect(onRender).toHaveBeenCalledTimes(1);
385+
expect(onRender).toHaveBeenCalledTimes(
386+
gate('alwaysThrottleRetries') ? 1 : 2,
387+
);
386388

387389
// Initial mount only shows the "Loading..." Fallback.
388390
// The treeBaseDuration then should be 10ms spent rendering Fallback,
@@ -532,7 +534,9 @@ describe('ReactSuspensePlaceholder', () => {
532534
]);
533535
// Show the fallback UI.
534536
expect(ReactNoop).toMatchRenderedOutput('Loading...');
535-
expect(onRender).toHaveBeenCalledTimes(2);
537+
expect(onRender).toHaveBeenCalledTimes(
538+
gate('alwaysThrottleRetries') ? 2 : 3,
539+
);
536540

537541
jest.advanceTimersByTime(900);
538542

@@ -575,7 +579,9 @@ describe('ReactSuspensePlaceholder', () => {
575579
]);
576580
expect(ReactNoop).toMatchRenderedOutput('Loading...');
577581

578-
expect(onRender).toHaveBeenCalledTimes(4);
582+
expect(onRender).toHaveBeenCalledTimes(
583+
gate('alwaysThrottleRetries') ? 4 : 5,
584+
);
579585

580586
// Resolve the pending promise.
581587
await act(async () => {
@@ -587,13 +593,17 @@ describe('ReactSuspensePlaceholder', () => {
587593
await waitForAll(['Suspending', 'Loaded', 'New', 'Sibling']);
588594
});
589595

590-
expect(onRender).toHaveBeenCalledTimes(5);
596+
expect(onRender).toHaveBeenCalledTimes(
597+
gate('alwaysThrottleRetries') ? 5 : 6,
598+
);
591599

592600
// When the suspending data is resolved and our final UI is rendered,
593601
// both times should include the 6ms rendering Text,
594602
// the 2ms rendering Suspending, and the 1ms rendering AsyncText.
595603
expect(onRender.mock.calls[4][2]).toBe(9);
596-
expect(onRender.mock.calls[4][3]).toBe(9);
604+
expect(onRender.mock.calls[4][3]).toBe(
605+
gate('alwaysThrottleRetries') ? 9 : 10,
606+
);
597607
});
598608
});
599609
});

packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,12 @@ describe('ReactSuspenseWithNoopRenderer', () => {
347347
// Resolve first Suspense's promise so that it switches switches back to the
348348
// normal view. The second Suspense should still show the placeholder.
349349
await act(() => resolveText('A'));
350-
assertLog(['A', 'Suspend! [B]', 'Suspend! [B]']);
350+
assertLog([
351+
'A',
352+
...(gate('alwaysThrottleRetries')
353+
? ['Suspend! [B]', 'Suspend! [B]']
354+
: []),
355+
]);
351356
expect(ReactNoop).toMatchRenderedOutput(
352357
<>
353358
<span prop="A" />

packages/react-reconciler/src/__tests__/ReactUse-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,12 +2087,12 @@ describe('ReactUse', () => {
20872087
assertLog(['Async text requested [World]']);
20882088

20892089
await act(() => resolveTextRequests('World'));
2090-
assertConsoleErrorDev(
2090+
assertConsoleErrorDev([
20912091
'A component was suspended by an uncached promise. ' +
20922092
'Creating promises inside a Client Component or hook is not yet supported, ' +
20932093
'except via a Suspense-compatible library or framework.\n' +
20942094
' in App (at **)',
2095-
);
2095+
]);
20962096

20972097
assertLog(['Hi', 'World']);
20982098
expect(root).toMatchRenderedOutput('Hi World');
@@ -2139,13 +2139,13 @@ describe('ReactUse', () => {
21392139
assertLog(['Async text requested [World]']);
21402140

21412141
await act(() => resolveTextRequests('World'));
2142-
assertConsoleErrorDev(
2142+
assertConsoleErrorDev([
21432143
'A component was suspended by an uncached promise. ' +
21442144
'Creating promises inside a Client Component or hook is not yet supported, ' +
21452145
'except via a Suspense-compatible library or framework.\n' +
21462146
' in div (at **)\n' +
21472147
' in App (at **)',
2148-
);
2148+
]);
21492149

21502150
assertLog(['Hi', 'World']);
21512151
expect(root).toMatchRenderedOutput(<div>Hi World</div>);

packages/react-reconciler/src/__tests__/useSyncExternalStore-test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,14 @@ describe('useSyncExternalStore', () => {
428428
await act(() => {
429429
resolveText('A');
430430
});
431-
assertLog(['A', 'B', 'A', 'B', 'B']);
431+
assertLog([
432+
'A',
433+
'B',
434+
'A',
435+
'B',
436+
'B',
437+
...(gate('alwaysThrottleRetries') ? [] : ['B']),
438+
]);
432439

433440
expect(root).toMatchRenderedOutput('AB');
434441
});

0 commit comments

Comments
 (0)