Skip to content

Commit 317faec

Browse files
committed
[react] SuspenseList was moved to experimental
facebook/react#22765
1 parent abece77 commit 317faec

4 files changed

Lines changed: 77 additions & 56 deletions

File tree

types/react-is/test/next-tests.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference types="../../react/next"/>
1+
/// <reference types="../../react/experimental"/>
22
import * as React from 'react';
33
import * as ReactIs from 'react-is';
44
import 'react-is/next';

types/react/experimental.d.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,61 @@ import React = require('./next');
3939
export {};
4040

4141
declare module '.' {
42+
export type SuspenseListRevealOrder = 'forwards' | 'backwards' | 'together';
43+
export type SuspenseListTailMode = 'collapsed' | 'hidden';
44+
45+
export interface SuspenseListCommonProps {
46+
/**
47+
* Note that SuspenseList require more than one child;
48+
* it is a runtime warning to provide only a single child.
49+
*
50+
* It does, however, allow those children to be wrapped inside a single
51+
* level of `<React.Fragment>`.
52+
*/
53+
children: ReactElement | Iterable<ReactElement>;
54+
}
55+
56+
interface DirectionalSuspenseListProps extends SuspenseListCommonProps {
57+
/**
58+
* Defines the order in which the `SuspenseList` children should be revealed.
59+
*/
60+
revealOrder: 'forwards' | 'backwards';
61+
/**
62+
* Dictates how unloaded items in a SuspenseList is shown.
63+
*
64+
* - By default, `SuspenseList` will show all fallbacks in the list.
65+
* - `collapsed` shows only the next fallback in the list.
66+
* - `hidden` doesn’t show any unloaded items.
67+
*/
68+
tail?: SuspenseListTailMode | undefined;
69+
}
70+
71+
interface NonDirectionalSuspenseListProps extends SuspenseListCommonProps {
72+
/**
73+
* Defines the order in which the `SuspenseList` children should be revealed.
74+
*/
75+
revealOrder?: Exclude<SuspenseListRevealOrder, DirectionalSuspenseListProps['revealOrder']> | undefined;
76+
/**
77+
* The tail property is invalid when not using the `forwards` or `backwards` reveal orders.
78+
*/
79+
tail?: never | undefined;
80+
}
81+
82+
export type SuspenseListProps = DirectionalSuspenseListProps | NonDirectionalSuspenseListProps;
83+
84+
/**
85+
* `SuspenseList` helps coordinate many components that can suspend by orchestrating the order
86+
* in which these components are revealed to the user.
87+
*
88+
* When multiple components need to fetch data, this data may arrive in an unpredictable order.
89+
* However, if you wrap these items in a `SuspenseList`, React will not show an item in the list
90+
* until previous items have been displayed (this behavior is adjustable).
91+
*
92+
* @see https://reactjs.org/docs/concurrent-mode-reference.html#suspenselist
93+
* @see https://reactjs.org/docs/concurrent-mode-patterns.html#suspenselist
94+
*/
95+
export const SuspenseList: ExoticComponent<SuspenseListProps>;
96+
4297
/**
4398
* @param subscribe
4499
* @param getSnapshot

types/react/next.d.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -42,61 +42,6 @@ declare module '.' {
4242
unstable_expectedLoadTime?: number | undefined;
4343
}
4444

45-
export type SuspenseListRevealOrder = 'forwards' | 'backwards' | 'together';
46-
export type SuspenseListTailMode = 'collapsed' | 'hidden';
47-
48-
export interface SuspenseListCommonProps {
49-
/**
50-
* Note that SuspenseList require more than one child;
51-
* it is a runtime warning to provide only a single child.
52-
*
53-
* It does, however, allow those children to be wrapped inside a single
54-
* level of `<React.Fragment>`.
55-
*/
56-
children: ReactElement | Iterable<ReactElement>;
57-
}
58-
59-
interface DirectionalSuspenseListProps extends SuspenseListCommonProps {
60-
/**
61-
* Defines the order in which the `SuspenseList` children should be revealed.
62-
*/
63-
revealOrder: 'forwards' | 'backwards';
64-
/**
65-
* Dictates how unloaded items in a SuspenseList is shown.
66-
*
67-
* - By default, `SuspenseList` will show all fallbacks in the list.
68-
* - `collapsed` shows only the next fallback in the list.
69-
* - `hidden` doesn’t show any unloaded items.
70-
*/
71-
tail?: SuspenseListTailMode | undefined;
72-
}
73-
74-
interface NonDirectionalSuspenseListProps extends SuspenseListCommonProps {
75-
/**
76-
* Defines the order in which the `SuspenseList` children should be revealed.
77-
*/
78-
revealOrder?: Exclude<SuspenseListRevealOrder, DirectionalSuspenseListProps['revealOrder']> | undefined;
79-
/**
80-
* The tail property is invalid when not using the `forwards` or `backwards` reveal orders.
81-
*/
82-
tail?: never | undefined;
83-
}
84-
85-
export type SuspenseListProps = DirectionalSuspenseListProps | NonDirectionalSuspenseListProps;
86-
87-
/**
88-
* `SuspenseList` helps coordinate many components that can suspend by orchestrating the order
89-
* in which these components are revealed to the user.
90-
*
91-
* When multiple components need to fetch data, this data may arrive in an unpredictable order.
92-
* However, if you wrap these items in a `SuspenseList`, React will not show an item in the list
93-
* until previous items have been displayed (this behavior is adjustable).
94-
*
95-
* @see https://reactjs.org/docs/concurrent-mode-reference.html#suspenselist
96-
* @see https://reactjs.org/docs/concurrent-mode-patterns.html#suspenselist
97-
*/
98-
export const SuspenseList: ExoticComponent<SuspenseListProps>;
99-
10045
// must be synchronous
10146
export type TransitionFunction = () => VoidOrUndefinedOnly;
10247
// strange definition to allow vscode to show documentation on the invocation

types/react/test/experimental.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,24 @@ function useExperimentalHooks() {
5151
return () => {};
5252
}, [toggle]);
5353
}
54+
55+
// Unsupported `revealOrder` triggers a runtime warning
56+
// $ExpectError
57+
<React.SuspenseList revealOrder="something">
58+
<React.Suspense fallback="Loading">Content</React.Suspense>
59+
</React.SuspenseList>;
60+
61+
<React.SuspenseList revealOrder="backwards">
62+
<React.Suspense fallback="Loading">A</React.Suspense>
63+
<React.Suspense fallback="Loading">B</React.Suspense>
64+
</React.SuspenseList>;
65+
66+
<React.SuspenseList revealOrder="forwards">
67+
<React.Suspense fallback="Loading">A</React.Suspense>
68+
<React.Suspense fallback="Loading">B</React.Suspense>
69+
</React.SuspenseList>;
70+
71+
<React.SuspenseList revealOrder="together">
72+
<React.Suspense fallback="Loading">A</React.Suspense>
73+
<React.Suspense fallback="Loading">B</React.Suspense>
74+
</React.SuspenseList>;

0 commit comments

Comments
 (0)