@@ -19,7 +19,6 @@ let Suspense;
19
19
let SuspenseList ;
20
20
let useSyncExternalStore ;
21
21
let useSyncExternalStoreWithSelector ;
22
- let use ;
23
22
let PropTypes ;
24
23
let textCache ;
25
24
let window ;
@@ -43,7 +42,6 @@ describe('ReactDOMFizzServer', () => {
43
42
Suspense = React . Suspense ;
44
43
if ( gate ( flags => flags . enableSuspenseList ) ) {
45
44
SuspenseList = React . SuspenseList ;
46
- use = React . experimental_use ;
47
45
}
48
46
49
47
PropTypes = require ( 'prop-types' ) ;
@@ -5015,264 +5013,6 @@ describe('ReactDOMFizzServer', () => {
5015
5013
console . error = originalConsoleError ;
5016
5014
}
5017
5015
} ) ;
5018
-
5019
- // @gate enableUseHook
5020
- it ( 'basic use(promise)' , async ( ) => {
5021
- const promiseA = Promise . resolve ( 'A' ) ;
5022
- const promiseB = Promise . resolve ( 'B' ) ;
5023
- const promiseC = Promise . resolve ( 'C' ) ;
5024
-
5025
- function Async ( ) {
5026
- return use ( promiseA ) + use ( promiseB ) + use ( promiseC ) ;
5027
- }
5028
-
5029
- function App ( ) {
5030
- return (
5031
- < Suspense fallback = "Loading..." >
5032
- < Async />
5033
- </ Suspense >
5034
- ) ;
5035
- }
5036
-
5037
- await act ( async ( ) => {
5038
- const { pipe} = ReactDOMFizzServer . renderToPipeableStream ( < App /> ) ;
5039
- pipe ( writable ) ;
5040
- } ) ;
5041
-
5042
- // TODO: The `act` implementation in this file doesn't unwrap microtasks
5043
- // automatically. We can't use the same `act` we use for Fiber tests
5044
- // because that relies on the mock Scheduler. Doesn't affect any public
5045
- // API but we might want to fix this for our own internal tests.
5046
- //
5047
- // For now, wait for each promise in sequence.
5048
- await act ( async ( ) => {
5049
- await promiseA ;
5050
- } ) ;
5051
- await act ( async ( ) => {
5052
- await promiseB ;
5053
- } ) ;
5054
- await act ( async ( ) => {
5055
- await promiseC ;
5056
- } ) ;
5057
-
5058
- expect ( getVisibleChildren ( container ) ) . toEqual ( 'ABC' ) ;
5059
-
5060
- ReactDOMClient . hydrateRoot ( container , < App /> ) ;
5061
- expect ( Scheduler ) . toFlushAndYield ( [ ] ) ;
5062
- expect ( getVisibleChildren ( container ) ) . toEqual ( 'ABC' ) ;
5063
- } ) ;
5064
-
5065
- // @gate enableUseHook
5066
- it ( 'basic use(context)' , async ( ) => {
5067
- const ContextA = React . createContext ( 'default' ) ;
5068
- const ContextB = React . createContext ( 'B' ) ;
5069
- const ServerContext = React . createServerContext (
5070
- 'ServerContext' ,
5071
- 'default' ,
5072
- ) ;
5073
- function Client ( ) {
5074
- return use ( ContextA ) + use ( ContextB ) ;
5075
- }
5076
- function ServerComponent ( ) {
5077
- return use ( ServerContext ) ;
5078
- }
5079
- function Server ( ) {
5080
- return (
5081
- < ServerContext . Provider value = "C" >
5082
- < ServerComponent />
5083
- </ ServerContext . Provider >
5084
- ) ;
5085
- }
5086
- function App ( ) {
5087
- return (
5088
- < >
5089
- < ContextA . Provider value = "A" >
5090
- < Client />
5091
- </ ContextA . Provider >
5092
- < Server />
5093
- </ >
5094
- ) ;
5095
- }
5096
-
5097
- await act ( async ( ) => {
5098
- const { pipe} = ReactDOMFizzServer . renderToPipeableStream ( < App /> ) ;
5099
- pipe ( writable ) ;
5100
- } ) ;
5101
- expect ( getVisibleChildren ( container ) ) . toEqual ( [ 'AB' , 'C' ] ) ;
5102
-
5103
- // Hydration uses a different renderer runtime (Fiber instead of Fizz).
5104
- // We reset _currentRenderer here to not trigger a warning about multiple
5105
- // renderers concurrently using these contexts
5106
- ContextA . _currentRenderer = null ;
5107
- ServerContext . _currentRenderer = null ;
5108
- ReactDOMClient . hydrateRoot ( container , < App /> ) ;
5109
- expect ( Scheduler ) . toFlushAndYield ( [ ] ) ;
5110
- expect ( getVisibleChildren ( container ) ) . toEqual ( [ 'AB' , 'C' ] ) ;
5111
- } ) ;
5112
-
5113
- // @gate enableUseHook
5114
- it ( 'use(promise) in multiple components' , async ( ) => {
5115
- const promiseA = Promise . resolve ( 'A' ) ;
5116
- const promiseB = Promise . resolve ( 'B' ) ;
5117
- const promiseC = Promise . resolve ( 'C' ) ;
5118
- const promiseD = Promise . resolve ( 'D' ) ;
5119
-
5120
- function Child ( { prefix} ) {
5121
- return prefix + use ( promiseC ) + use ( promiseD ) ;
5122
- }
5123
-
5124
- function Parent ( ) {
5125
- return < Child prefix = { use ( promiseA ) + use ( promiseB ) } /> ;
5126
- }
5127
-
5128
- function App ( ) {
5129
- return (
5130
- < Suspense fallback = "Loading..." >
5131
- < Parent />
5132
- </ Suspense >
5133
- ) ;
5134
- }
5135
-
5136
- await act ( async ( ) => {
5137
- const { pipe} = ReactDOMFizzServer . renderToPipeableStream ( < App /> ) ;
5138
- pipe ( writable ) ;
5139
- } ) ;
5140
-
5141
- // TODO: The `act` implementation in this file doesn't unwrap microtasks
5142
- // automatically. We can't use the same `act` we use for Fiber tests
5143
- // because that relies on the mock Scheduler. Doesn't affect any public
5144
- // API but we might want to fix this for our own internal tests.
5145
- //
5146
- // For now, wait for each promise in sequence.
5147
- await act ( async ( ) => {
5148
- await promiseA ;
5149
- } ) ;
5150
- await act ( async ( ) => {
5151
- await promiseB ;
5152
- } ) ;
5153
- await act ( async ( ) => {
5154
- await promiseC ;
5155
- } ) ;
5156
- await act ( async ( ) => {
5157
- await promiseD ;
5158
- } ) ;
5159
-
5160
- expect ( getVisibleChildren ( container ) ) . toEqual ( 'ABCD' ) ;
5161
-
5162
- ReactDOMClient . hydrateRoot ( container , < App /> ) ;
5163
- expect ( Scheduler ) . toFlushAndYield ( [ ] ) ;
5164
- expect ( getVisibleChildren ( container ) ) . toEqual ( 'ABCD' ) ;
5165
- } ) ;
5166
-
5167
- // @gate enableUseHook
5168
- it ( 'using a rejected promise will throw' , async ( ) => {
5169
- const promiseA = Promise . resolve ( 'A' ) ;
5170
- const promiseB = Promise . reject ( new Error ( 'Oops!' ) ) ;
5171
- const promiseC = Promise . resolve ( 'C' ) ;
5172
-
5173
- // Jest/Node will raise an unhandled rejected error unless we await this. It
5174
- // works fine in the browser, though.
5175
- await expect ( promiseB ) . rejects . toThrow ( 'Oops!' ) ;
5176
-
5177
- function Async ( ) {
5178
- return use ( promiseA ) + use ( promiseB ) + use ( promiseC ) ;
5179
- }
5180
-
5181
- class ErrorBoundary extends React . Component {
5182
- state = { error : null } ;
5183
- static getDerivedStateFromError ( error ) {
5184
- return { error} ;
5185
- }
5186
- render ( ) {
5187
- if ( this . state . error ) {
5188
- return this . state . error . message ;
5189
- }
5190
- return this . props . children ;
5191
- }
5192
- }
5193
-
5194
- function App ( ) {
5195
- return (
5196
- < Suspense fallback = "Loading..." >
5197
- < ErrorBoundary >
5198
- < Async />
5199
- </ ErrorBoundary >
5200
- </ Suspense >
5201
- ) ;
5202
- }
5203
-
5204
- const reportedServerErrors = [ ] ;
5205
- await act ( async ( ) => {
5206
- const { pipe} = ReactDOMFizzServer . renderToPipeableStream ( < App /> , {
5207
- onError ( error ) {
5208
- reportedServerErrors . push ( error ) ;
5209
- } ,
5210
- } ) ;
5211
- pipe ( writable ) ;
5212
- } ) ;
5213
-
5214
- // TODO: The `act` implementation in this file doesn't unwrap microtasks
5215
- // automatically. We can't use the same `act` we use for Fiber tests
5216
- // because that relies on the mock Scheduler. Doesn't affect any public
5217
- // API but we might want to fix this for our own internal tests.
5218
- //
5219
- // For now, wait for each promise in sequence.
5220
- await act ( async ( ) => {
5221
- await promiseA ;
5222
- } ) ;
5223
- await act ( async ( ) => {
5224
- await expect ( promiseB ) . rejects . toThrow ( 'Oops!' ) ;
5225
- } ) ;
5226
- await act ( async ( ) => {
5227
- await promiseC ;
5228
- } ) ;
5229
-
5230
- expect ( getVisibleChildren ( container ) ) . toEqual ( 'Loading...' ) ;
5231
- expect ( reportedServerErrors . length ) . toBe ( 1 ) ;
5232
- expect ( reportedServerErrors [ 0 ] . message ) . toBe ( 'Oops!' ) ;
5233
-
5234
- const reportedClientErrors = [ ] ;
5235
- ReactDOMClient . hydrateRoot ( container , < App /> , {
5236
- onRecoverableError ( error ) {
5237
- reportedClientErrors . push ( error ) ;
5238
- } ,
5239
- } ) ;
5240
- expect ( Scheduler ) . toFlushAndYield ( [ ] ) ;
5241
- expect ( getVisibleChildren ( container ) ) . toEqual ( 'Oops!' ) ;
5242
- expect ( reportedClientErrors . length ) . toBe ( 1 ) ;
5243
- if ( __DEV__ ) {
5244
- expect ( reportedClientErrors [ 0 ] . message ) . toBe ( 'Oops!' ) ;
5245
- } else {
5246
- expect ( reportedClientErrors [ 0 ] . message ) . toBe (
5247
- 'The server could not finish this Suspense boundary, likely due to ' +
5248
- 'an error during server rendering. Switched to client rendering.' ,
5249
- ) ;
5250
- }
5251
- } ) ;
5252
-
5253
- // @gate enableUseHook
5254
- it ( "use a promise that's already been instrumented and resolved" , async ( ) => {
5255
- const thenable = {
5256
- status : 'fulfilled' ,
5257
- value : 'Hi' ,
5258
- then ( ) { } ,
5259
- } ;
5260
-
5261
- // This will never suspend because the thenable already resolved
5262
- function App ( ) {
5263
- return use ( thenable ) ;
5264
- }
5265
-
5266
- await act ( async ( ) => {
5267
- const { pipe} = ReactDOMFizzServer . renderToPipeableStream ( < App /> ) ;
5268
- pipe ( writable ) ;
5269
- } ) ;
5270
- expect ( getVisibleChildren ( container ) ) . toEqual ( 'Hi' ) ;
5271
-
5272
- ReactDOMClient . hydrateRoot ( container , < App /> ) ;
5273
- expect ( Scheduler ) . toFlushAndYield ( [ ] ) ;
5274
- expect ( getVisibleChildren ( container ) ) . toEqual ( 'Hi' ) ;
5275
- } ) ;
5276
5016
} ) ;
5277
5017
5278
5018
describe ( 'useEvent' , ( ) => {
0 commit comments