@@ -36,6 +36,7 @@ let React;
36
36
let ReactServerDOMServer ;
37
37
let ReactServerDOMClient ;
38
38
let use ;
39
+ let cache ;
39
40
40
41
describe ( 'ReactFetch' , ( ) => {
41
42
beforeEach ( ( ) => {
@@ -50,6 +51,7 @@ describe('ReactFetch', () => {
50
51
ReactServerDOMServer = require ( 'react-server-dom-webpack/server.browser' ) ;
51
52
ReactServerDOMClient = require ( 'react-server-dom-webpack/client' ) ;
52
53
use = React . experimental_use ;
54
+ cache = React . experimental_cache ;
53
55
} ) ;
54
56
55
57
async function render ( Component ) {
@@ -96,6 +98,27 @@ describe('ReactFetch', () => {
96
98
expect ( fetchCount ) . toBe ( 2 ) ;
97
99
} ) ;
98
100
101
+ // @gate enableFetchInstrumentation && enableCache
102
+ it ( 'can dedupe cache in micro tasks' , async ( ) => {
103
+ const cached = cache ( async ( ) => {
104
+ fetchCount ++ ;
105
+ return 'world' ;
106
+ } ) ;
107
+ async function getData ( ) {
108
+ const r1 = await fetch ( 'hello' ) ;
109
+ const t1 = await r1 . text ( ) ;
110
+ const t2 = await cached ( ) ;
111
+ return t1 + ' ' + t2 ;
112
+ }
113
+ function Component ( ) {
114
+ return use ( getData ( ) ) ;
115
+ }
116
+ expect ( await render ( Component ) ) . toMatchInlineSnapshot (
117
+ `"GET hello [] world"` ,
118
+ ) ;
119
+ expect ( fetchCount ) . toBe ( 2 ) ;
120
+ } ) ;
121
+
99
122
// @gate enableFetchInstrumentation && enableCache
100
123
it ( 'can dedupe fetches using Request and not' , async ( ) => {
101
124
function Component ( ) {
0 commit comments