Skip to content

Commit bda4cb1

Browse files
committed
Fixes with alwaysThrottleRetries
1 parent e83bf3f commit bda4cb1

File tree

6 files changed

+92
-26
lines changed

6 files changed

+92
-26
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__/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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ describe('ReactSuspense', () => {
9393
ReactNoop.render(element);
9494
await waitForAll([]);
9595
expect(ReactNoop).toMatchRenderedOutput('Waiting');
96-
expect(ops).toEqual([new Set([promise])]);
96+
expect(ops).toEqual([
97+
new Set([promise]),
98+
...(gate('alwaysThrottleRetries') ? [] : new Set([promise])),
99+
]);
97100
ops = [];
98101

99102
await act(() => resolve());
@@ -132,7 +135,10 @@ describe('ReactSuspense', () => {
132135
ReactNoop.render(element);
133136
await waitForAll([]);
134137
expect(ReactNoop).toMatchRenderedOutput('Waiting Tier 1');
135-
expect(ops).toEqual([new Set([promise1])]);
138+
expect(ops).toEqual([
139+
new Set([promise1]),
140+
...(gate('alwaysThrottleRetries') ? [] : new Set([promise1, promise2])),
141+
]);
136142
ops = [];
137143

138144
await act(() => resolve1());
@@ -178,7 +184,10 @@ describe('ReactSuspense', () => {
178184
await waitForAll([]);
179185
expect(ReactNoop).toMatchRenderedOutput('Waiting Tier 2');
180186
expect(ops1).toEqual([]);
181-
expect(ops2).toEqual([new Set([promise])]);
187+
expect(ops2).toEqual([
188+
new Set([promise]),
189+
...(gate('alwaysThrottleRetries') ? [] : [new Set([promise])]),
190+
]);
182191
});
183192

184193
// @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__/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)