Skip to content

Commit 2ad3ebd

Browse files
committed
Use options param for clientExports in WebpackMock
1 parent d18f8f8 commit 2ad3ebd

File tree

3 files changed

+107
-50
lines changed

3 files changed

+107
-50
lines changed

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js

Lines changed: 90 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,15 @@ describe('ReactFlightDOMBrowser', () => {
213213
function ClientInner({children}) {
214214
return <span>{children}</span>;
215215
},
216-
'42',
217-
'/test.js',
218-
new Promise(resolve => (resolveClientComponentChunk = resolve)),
216+
{
217+
chunk: {
218+
id: '42',
219+
filename: '/test.js',
220+
promise: new Promise(
221+
resolve => (resolveClientComponentChunk = resolve),
222+
),
223+
},
224+
},
219225
);
220226

221227
function Server() {
@@ -258,9 +264,15 @@ describe('ReactFlightDOMBrowser', () => {
258264
function ClientInner({value}) {
259265
return <pre>{JSON.stringify(value)}</pre>;
260266
},
261-
'42',
262-
'/test.js',
263-
new Promise(resolve => (resolveClientComponentChunk = resolve)),
267+
{
268+
chunk: {
269+
id: '42',
270+
filename: '/test.js',
271+
promise: new Promise(
272+
resolve => (resolveClientComponentChunk = resolve),
273+
),
274+
},
275+
},
264276
);
265277

266278
function Server({value}) {
@@ -309,9 +321,15 @@ describe('ReactFlightDOMBrowser', () => {
309321
function ClientInner({value}) {
310322
return <pre>{JSON.stringify(value)}</pre>;
311323
},
312-
'42',
313-
'/test.js',
314-
new Promise(resolve => (resolveClientComponentChunk = resolve)),
324+
{
325+
chunk: {
326+
id: '42',
327+
filename: '/test.js',
328+
promise: new Promise(
329+
resolve => (resolveClientComponentChunk = resolve),
330+
),
331+
},
332+
},
315333
);
316334

317335
function Server({value}) {
@@ -355,12 +373,15 @@ describe('ReactFlightDOMBrowser', () => {
355373
it('should resolve deduped objects that are themselves blocked', async () => {
356374
let resolveClientComponentChunk;
357375

358-
const Client = clientExports(
359-
[4, 5],
360-
'42',
361-
'/test.js',
362-
new Promise(resolve => (resolveClientComponentChunk = resolve)),
363-
);
376+
const Client = clientExports([4, 5], {
377+
chunk: {
378+
id: '42',
379+
filename: '/test.js',
380+
promise: new Promise(
381+
resolve => (resolveClientComponentChunk = resolve),
382+
),
383+
},
384+
});
364385

365386
const shared = [1, 2, 3, Client];
366387

@@ -407,9 +428,15 @@ describe('ReactFlightDOMBrowser', () => {
407428
function ClientOuter({children, value}) {
408429
return children;
409430
},
410-
'1',
411-
'/outer.js',
412-
new Promise(resolve => (resolveOuterClientComponentChunk = resolve)),
431+
{
432+
chunk: {
433+
id: '1',
434+
filename: '/outer.js',
435+
promise: new Promise(
436+
resolve => (resolveOuterClientComponentChunk = resolve),
437+
),
438+
},
439+
},
413440
);
414441

415442
function PassthroughServerComponent({children}) {
@@ -420,9 +447,15 @@ describe('ReactFlightDOMBrowser', () => {
420447
function ClientInner({children}) {
421448
return JSON.stringify(children);
422449
},
423-
'2',
424-
'/inner.js',
425-
new Promise(resolve => (resolveInnerClientComponentChunk = resolve)),
450+
{
451+
chunk: {
452+
id: '2',
453+
filename: '/inner.js',
454+
promise: new Promise(
455+
resolve => (resolveInnerClientComponentChunk = resolve),
456+
),
457+
},
458+
},
426459
);
427460

428461
const value = {};
@@ -475,18 +508,30 @@ describe('ReactFlightDOMBrowser', () => {
475508
function FooClient({children}) {
476509
return JSON.stringify(children);
477510
},
478-
'1',
479-
'/foo.js',
480-
new Promise(resolve => (resolveFooClientComponentChunk = resolve)),
511+
{
512+
chunk: {
513+
id: '1',
514+
filename: '/foo.js',
515+
promise: new Promise(
516+
resolve => (resolveFooClientComponentChunk = resolve),
517+
),
518+
},
519+
},
481520
);
482521

483522
const BarClient = clientExports(
484523
function BarClient() {
485524
return 'not used';
486525
},
487-
'2',
488-
'/bar.js',
489-
new Promise(resolve => (resolveBarClientComponentChunk = resolve)),
526+
{
527+
chunk: {
528+
id: '2',
529+
filename: '/bar.js',
530+
promise: new Promise(
531+
resolve => (resolveBarClientComponentChunk = resolve),
532+
),
533+
},
534+
},
490535
);
491536

492537
const shared = {foo: 1};
@@ -539,9 +584,15 @@ describe('ReactFlightDOMBrowser', () => {
539584
function Foo({children, item}) {
540585
return children;
541586
},
542-
'1',
543-
'/foo.js',
544-
new Promise(resolve => (resolveFooClientComponentChunk = resolve)),
587+
{
588+
chunk: {
589+
id: '1',
590+
filename: '/foo.js',
591+
promise: new Promise(
592+
resolve => (resolveFooClientComponentChunk = resolve),
593+
),
594+
},
595+
},
545596
);
546597

547598
const shared = <div />;
@@ -590,9 +641,15 @@ describe('ReactFlightDOMBrowser', () => {
590641
function Foo({children, item}) {
591642
return children;
592643
},
593-
'1',
594-
'/foo.js',
595-
new Promise(resolve => (resolveFooClientComponentChunk = resolve)),
644+
{
645+
chunk: {
646+
id: '1',
647+
filename: '/foo.js',
648+
promise: new Promise(
649+
resolve => (resolveFooClientComponentChunk = resolve),
650+
),
651+
},
652+
},
596653
);
597654

598655
const shared = <div />;

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMNode-test.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,9 @@ describe('ReactFlightDOMNode', () => {
111111
}
112112
// The Client build may not have the same IDs as the Server bundles for the same
113113
// component.
114-
const ClientComponentOnTheClient = clientExports(
115-
ClientComponent,
116-
123,
117-
'path/to/chunk.js',
118-
);
114+
const ClientComponentOnTheClient = clientExports(ClientComponent, {
115+
chunk: {id: 123, filename: 'path/to/chunk.js'},
116+
});
119117
const ClientComponentOnTheServer = clientExports(ClientComponent);
120118

121119
// In the SSR bundle this module won't exist. We simulate this by deleting it.
@@ -236,11 +234,9 @@ describe('ReactFlightDOMNode', () => {
236234
}
237235
// The Client build may not have the same IDs as the Server bundles for the same
238236
// component.
239-
const ClientComponentOnTheClient = clientExports(
240-
ClientComponent,
241-
123,
242-
'path/to/chunk.js',
243-
);
237+
const ClientComponentOnTheClient = clientExports(ClientComponent, {
238+
chunk: {id: 123, filename: 'path/to/chunk.js'},
239+
});
244240
const ClientComponentOnTheServer = clientExports(ClientComponent);
245241

246242
// In the SSR bundle this module won't exist. We simulate this by deleting it.

packages/react-server-dom-webpack/src/__tests__/utils/WebpackMock.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,20 @@ exports.clientModuleError = function clientModuleError(moduleError) {
6767

6868
exports.clientExports = function clientExports(
6969
moduleExports,
70-
chunkId,
71-
chunkFilename,
72-
blockOnChunk,
70+
options?: {
71+
chunk?: {
72+
id: string | number,
73+
filename: string,
74+
promise?: Promise,
75+
},
76+
} = {},
7377
) {
7478
const chunks = [];
75-
if (chunkId) {
76-
chunks.push(chunkId, chunkFilename);
79+
if (options.chunk) {
80+
chunks.push(options.chunk.id, options.chunk.filename);
7781

78-
if (blockOnChunk) {
79-
webpackChunkMap[chunkId] = blockOnChunk;
82+
if (options.chunk.promise) {
83+
webpackChunkMap[options.chunk.id] = options.chunk.promise;
8084
}
8185
}
8286
const idx = '' + webpackModuleIdx++;

0 commit comments

Comments
 (0)