react-server-dom-webpack 18.3.0-next-5dd90c562-20230502 → 19.0.0-canary-2b036d3f1-20240327

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/cjs/react-server-dom-webpack-client.browser.development.js +1768 -1188
  2. package/cjs/react-server-dom-webpack-client.browser.production.js +1739 -0
  3. package/cjs/react-server-dom-webpack-client.browser.production.min.js +40 -34
  4. package/cjs/react-server-dom-webpack-client.browser.production.min.js.map +1 -0
  5. package/cjs/react-server-dom-webpack-client.edge.development.js +1755 -221
  6. package/cjs/react-server-dom-webpack-client.edge.production.js +1986 -0
  7. package/cjs/react-server-dom-webpack-client.edge.production.min.js +45 -28
  8. package/cjs/react-server-dom-webpack-client.edge.production.min.js.map +1 -0
  9. package/cjs/react-server-dom-webpack-client.node.development.js +1743 -239
  10. package/cjs/react-server-dom-webpack-client.node.production.js +1942 -0
  11. package/cjs/react-server-dom-webpack-client.node.production.min.js +44 -28
  12. package/cjs/react-server-dom-webpack-client.node.production.min.js.map +1 -0
  13. package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +1702 -194
  14. package/cjs/react-server-dom-webpack-client.node.unbundled.production.js +1895 -0
  15. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +43 -26
  16. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js.map +1 -0
  17. package/cjs/react-server-dom-webpack-node-register.js +12 -18
  18. package/cjs/react-server-dom-webpack-node-register.js.map +1 -0
  19. package/cjs/react-server-dom-webpack-plugin.js +22 -19
  20. package/cjs/react-server-dom-webpack-plugin.js.map +1 -0
  21. package/cjs/react-server-dom-webpack-server.browser.development.js +1588 -808
  22. package/cjs/react-server-dom-webpack-server.browser.production.js +3257 -0
  23. package/cjs/react-server-dom-webpack-server.browser.production.min.js +80 -62
  24. package/cjs/react-server-dom-webpack-server.browser.production.min.js.map +1 -0
  25. package/cjs/react-server-dom-webpack-server.edge.development.js +1583 -811
  26. package/cjs/react-server-dom-webpack-server.edge.production.js +3261 -0
  27. package/cjs/react-server-dom-webpack-server.edge.production.min.js +82 -62
  28. package/cjs/react-server-dom-webpack-server.edge.production.min.js.map +1 -0
  29. package/cjs/react-server-dom-webpack-server.node.development.js +1575 -805
  30. package/cjs/react-server-dom-webpack-server.node.production.js +3464 -0
  31. package/cjs/react-server-dom-webpack-server.node.production.min.js +85 -67
  32. package/cjs/react-server-dom-webpack-server.node.production.min.js.map +1 -0
  33. package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1526 -761
  34. package/cjs/react-server-dom-webpack-server.node.unbundled.production.js +3391 -0
  35. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +82 -65
  36. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js.map +1 -0
  37. package/esm/react-server-dom-webpack-node-loader.production.min.js +19 -12
  38. package/package.json +7 -13
  39. package/umd/react-server-dom-webpack-client.browser.development.js +1770 -1189
  40. package/umd/react-server-dom-webpack-client.browser.production.min.js +26 -20
  41. package/umd/react-server-dom-webpack-server.browser.development.js +1589 -808
  42. package/umd/react-server-dom-webpack-server.browser.production.min.js +55 -42
@@ -0,0 +1,3257 @@
1
+ /**
2
+ * @license React
3
+ * react-server-dom-webpack-server.browser.production.min.js
4
+ *
5
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ var ReactDOM = require('react-dom');
14
+ var React = require('react');
15
+
16
+ // -----------------------------------------------------------------------------
17
+ const enablePostpone = false;
18
+
19
+ function scheduleWork(callback) {
20
+ callback();
21
+ }
22
+ const VIEW_SIZE = 2048;
23
+ let currentView = null;
24
+ let writtenBytes = 0;
25
+ function beginWriting(destination) {
26
+ currentView = new Uint8Array(VIEW_SIZE);
27
+ writtenBytes = 0;
28
+ }
29
+ function writeChunk(destination, chunk) {
30
+ if (chunk.byteLength === 0) {
31
+ return;
32
+ }
33
+
34
+ if (chunk.byteLength > VIEW_SIZE) {
35
+ // this chunk may overflow a single view which implies it was not
36
+ // one that is cached by the streaming renderer. We will enqueu
37
+ // it directly and expect it is not re-used
38
+ if (writtenBytes > 0) {
39
+ destination.enqueue(new Uint8Array(currentView.buffer, 0, writtenBytes));
40
+ currentView = new Uint8Array(VIEW_SIZE);
41
+ writtenBytes = 0;
42
+ }
43
+
44
+ destination.enqueue(chunk);
45
+ return;
46
+ }
47
+
48
+ let bytesToWrite = chunk;
49
+ const allowableBytes = currentView.length - writtenBytes;
50
+
51
+ if (allowableBytes < bytesToWrite.byteLength) {
52
+ // this chunk would overflow the current view. We enqueue a full view
53
+ // and start a new view with the remaining chunk
54
+ if (allowableBytes === 0) {
55
+ // the current view is already full, send it
56
+ destination.enqueue(currentView);
57
+ } else {
58
+ // fill up the current view and apply the remaining chunk bytes
59
+ // to a new view.
60
+ currentView.set(bytesToWrite.subarray(0, allowableBytes), writtenBytes); // writtenBytes += allowableBytes; // this can be skipped because we are going to immediately reset the view
61
+
62
+ destination.enqueue(currentView);
63
+ bytesToWrite = bytesToWrite.subarray(allowableBytes);
64
+ }
65
+
66
+ currentView = new Uint8Array(VIEW_SIZE);
67
+ writtenBytes = 0;
68
+ }
69
+
70
+ currentView.set(bytesToWrite, writtenBytes);
71
+ writtenBytes += bytesToWrite.byteLength;
72
+ }
73
+ function writeChunkAndReturn(destination, chunk) {
74
+ writeChunk(destination, chunk); // in web streams there is no backpressure so we can alwas write more
75
+
76
+ return true;
77
+ }
78
+ function completeWriting(destination) {
79
+ if (currentView && writtenBytes > 0) {
80
+ destination.enqueue(new Uint8Array(currentView.buffer, 0, writtenBytes));
81
+ currentView = null;
82
+ writtenBytes = 0;
83
+ }
84
+ }
85
+ function close$1(destination) {
86
+ destination.close();
87
+ }
88
+ const textEncoder = new TextEncoder();
89
+ function stringToChunk(content) {
90
+ return textEncoder.encode(content);
91
+ }
92
+ function byteLengthOfChunk(chunk) {
93
+ return chunk.byteLength;
94
+ }
95
+ function closeWithError(destination, error) {
96
+ // $FlowFixMe[method-unbinding]
97
+ if (typeof destination.error === 'function') {
98
+ // $FlowFixMe[incompatible-call]: This is an Error object or the destination accepts other types.
99
+ destination.error(error);
100
+ } else {
101
+ // Earlier implementations doesn't support this method. In that environment you're
102
+ // supposed to throw from a promise returned but we don't return a promise in our
103
+ // approach. We could fork this implementation but this is environment is an edge
104
+ // case to begin with. It's even less common to run this in an older environment.
105
+ // Even then, this is not where errors are supposed to happen and they get reported
106
+ // to a global callback in addition to this anyway. So it's fine just to close this.
107
+ destination.close();
108
+ }
109
+ }
110
+
111
+ // eslint-disable-next-line no-unused-vars
112
+ const CLIENT_REFERENCE_TAG$1 = Symbol.for('react.client.reference');
113
+ const SERVER_REFERENCE_TAG = Symbol.for('react.server.reference');
114
+ function isClientReference(reference) {
115
+ return reference.$$typeof === CLIENT_REFERENCE_TAG$1;
116
+ }
117
+ function isServerReference(reference) {
118
+ return reference.$$typeof === SERVER_REFERENCE_TAG;
119
+ }
120
+ function registerClientReference(proxyImplementation, id, exportName) {
121
+ return registerClientReferenceImpl(proxyImplementation, id + '#' + exportName, false);
122
+ }
123
+
124
+ function registerClientReferenceImpl(proxyImplementation, id, async) {
125
+ return Object.defineProperties(proxyImplementation, {
126
+ $$typeof: {
127
+ value: CLIENT_REFERENCE_TAG$1
128
+ },
129
+ $$id: {
130
+ value: id
131
+ },
132
+ $$async: {
133
+ value: async
134
+ }
135
+ });
136
+ } // $FlowFixMe[method-unbinding]
137
+
138
+
139
+ const FunctionBind = Function.prototype.bind; // $FlowFixMe[method-unbinding]
140
+
141
+ const ArraySlice = Array.prototype.slice;
142
+
143
+ function bind() {
144
+ // $FlowFixMe[unsupported-syntax]
145
+ const newFn = FunctionBind.apply(this, arguments);
146
+
147
+ if (this.$$typeof === SERVER_REFERENCE_TAG) {
148
+
149
+ const args = ArraySlice.call(arguments, 1);
150
+ return Object.defineProperties(newFn, {
151
+ $$typeof: {
152
+ value: SERVER_REFERENCE_TAG
153
+ },
154
+ $$id: {
155
+ value: this.$$id
156
+ },
157
+ $$bound: {
158
+ value: this.$$bound ? this.$$bound.concat(args) : args
159
+ },
160
+ bind: {
161
+ value: bind
162
+ }
163
+ });
164
+ }
165
+
166
+ return newFn;
167
+ }
168
+
169
+ function registerServerReference(reference, id, exportName) {
170
+ return Object.defineProperties(reference, {
171
+ $$typeof: {
172
+ value: SERVER_REFERENCE_TAG
173
+ },
174
+ $$id: {
175
+ value: exportName === null ? id : id + '#' + exportName,
176
+ configurable: true
177
+ },
178
+ $$bound: {
179
+ value: null,
180
+ configurable: true
181
+ },
182
+ bind: {
183
+ value: bind,
184
+ configurable: true
185
+ }
186
+ });
187
+ }
188
+ const PROMISE_PROTOTYPE = Promise.prototype;
189
+ const deepProxyHandlers = {
190
+ get: function (target, name, receiver) {
191
+ switch (name) {
192
+ // These names are read by the Flight runtime if you end up using the exports object.
193
+ case '$$typeof':
194
+ // These names are a little too common. We should probably have a way to
195
+ // have the Flight runtime extract the inner target instead.
196
+ return target.$$typeof;
197
+
198
+ case '$$id':
199
+ return target.$$id;
200
+
201
+ case '$$async':
202
+ return target.$$async;
203
+
204
+ case 'name':
205
+ return target.name;
206
+
207
+ case 'displayName':
208
+ return undefined;
209
+ // We need to special case this because createElement reads it if we pass this
210
+ // reference.
211
+
212
+ case 'defaultProps':
213
+ return undefined;
214
+ // Avoid this attempting to be serialized.
215
+
216
+ case 'toJSON':
217
+ return undefined;
218
+
219
+ case Symbol.toPrimitive:
220
+ // $FlowFixMe[prop-missing]
221
+ return Object.prototype[Symbol.toPrimitive];
222
+
223
+ case Symbol.toStringTag:
224
+ // $FlowFixMe[prop-missing]
225
+ return Object.prototype[Symbol.toStringTag];
226
+
227
+ case 'Provider':
228
+ throw new Error("Cannot render a Client Context Provider on the Server. " + "Instead, you can export a Client Component wrapper " + "that itself renders a Client Context Provider.");
229
+ } // eslint-disable-next-line react-internal/safe-string-coercion
230
+
231
+
232
+ const expression = String(target.name) + '.' + String(name);
233
+ throw new Error("Cannot access " + expression + " on the server. " + 'You cannot dot into a client module from a server component. ' + 'You can only pass the imported name through.');
234
+ },
235
+ set: function () {
236
+ throw new Error('Cannot assign to a client module from a server module.');
237
+ }
238
+ };
239
+
240
+ function getReference(target, name) {
241
+ switch (name) {
242
+ // These names are read by the Flight runtime if you end up using the exports object.
243
+ case '$$typeof':
244
+ return target.$$typeof;
245
+
246
+ case '$$id':
247
+ return target.$$id;
248
+
249
+ case '$$async':
250
+ return target.$$async;
251
+
252
+ case 'name':
253
+ return target.name;
254
+ // We need to special case this because createElement reads it if we pass this
255
+ // reference.
256
+
257
+ case 'defaultProps':
258
+ return undefined;
259
+ // Avoid this attempting to be serialized.
260
+
261
+ case 'toJSON':
262
+ return undefined;
263
+
264
+ case Symbol.toPrimitive:
265
+ // $FlowFixMe[prop-missing]
266
+ return Object.prototype[Symbol.toPrimitive];
267
+
268
+ case Symbol.toStringTag:
269
+ // $FlowFixMe[prop-missing]
270
+ return Object.prototype[Symbol.toStringTag];
271
+
272
+ case '__esModule':
273
+ // Something is conditionally checking which export to use. We'll pretend to be
274
+ // an ESM compat module but then we'll check again on the client.
275
+ const moduleId = target.$$id;
276
+ target.default = registerClientReferenceImpl(function () {
277
+ throw new Error("Attempted to call the default export of " + moduleId + " from the server " + "but it's on the client. It's not possible to invoke a client function from " + "the server, it can only be rendered as a Component or passed to props of a " + "Client Component.");
278
+ }, target.$$id + '#', target.$$async);
279
+ return true;
280
+
281
+ case 'then':
282
+ if (target.then) {
283
+ // Use a cached value
284
+ return target.then;
285
+ }
286
+
287
+ if (!target.$$async) {
288
+ // If this module is expected to return a Promise (such as an AsyncModule) then
289
+ // we should resolve that with a client reference that unwraps the Promise on
290
+ // the client.
291
+ const clientReference = registerClientReferenceImpl({}, target.$$id, true);
292
+ const proxy = new Proxy(clientReference, proxyHandlers$1); // Treat this as a resolved Promise for React's use()
293
+
294
+ target.status = 'fulfilled';
295
+ target.value = proxy;
296
+ const then = target.then = registerClientReferenceImpl(function then(resolve, reject) {
297
+ // Expose to React.
298
+ return Promise.resolve(resolve(proxy));
299
+ }, // If this is not used as a Promise but is treated as a reference to a `.then`
300
+ // export then we should treat it as a reference to that name.
301
+ target.$$id + '#then', false);
302
+ return then;
303
+ } else {
304
+ // Since typeof .then === 'function' is a feature test we'd continue recursing
305
+ // indefinitely if we return a function. Instead, we return an object reference
306
+ // if we check further.
307
+ return undefined;
308
+ }
309
+
310
+ }
311
+
312
+ if (typeof name === 'symbol') {
313
+ throw new Error('Cannot read Symbol exports. Only named exports are supported on a client module ' + 'imported on the server.');
314
+ }
315
+
316
+ let cachedReference = target[name];
317
+
318
+ if (!cachedReference) {
319
+ const reference = registerClientReferenceImpl(function () {
320
+ throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
321
+ "Attempted to call " + String(name) + "() from the server but " + String(name) + " is on the client. " + "It's not possible to invoke a client function from the server, it can " + "only be rendered as a Component or passed to props of a Client Component.");
322
+ }, target.$$id + '#' + name, target.$$async);
323
+ Object.defineProperty(reference, 'name', {
324
+ value: name
325
+ });
326
+ cachedReference = target[name] = new Proxy(reference, deepProxyHandlers);
327
+ }
328
+
329
+ return cachedReference;
330
+ }
331
+
332
+ const proxyHandlers$1 = {
333
+ get: function (target, name, receiver) {
334
+ return getReference(target, name);
335
+ },
336
+ getOwnPropertyDescriptor: function (target, name) {
337
+ let descriptor = Object.getOwnPropertyDescriptor(target, name);
338
+
339
+ if (!descriptor) {
340
+ descriptor = {
341
+ value: getReference(target, name),
342
+ writable: false,
343
+ configurable: false,
344
+ enumerable: false
345
+ };
346
+ Object.defineProperty(target, name, descriptor);
347
+ }
348
+
349
+ return descriptor;
350
+ },
351
+
352
+ getPrototypeOf(target) {
353
+ // Pretend to be a Promise in case anyone asks.
354
+ return PROMISE_PROTOTYPE;
355
+ },
356
+
357
+ set: function () {
358
+ throw new Error('Cannot assign to a client module from a server module.');
359
+ }
360
+ };
361
+ function createClientModuleProxy(moduleId) {
362
+ const clientReference = registerClientReferenceImpl({}, // Represents the whole Module object instead of a particular import.
363
+ moduleId, false);
364
+ return new Proxy(clientReference, proxyHandlers$1);
365
+ }
366
+
367
+ function getClientReferenceKey(reference) {
368
+ return reference.$$async ? reference.$$id + '#async' : reference.$$id;
369
+ }
370
+ function resolveClientReferenceMetadata(config, clientReference) {
371
+ const modulePath = clientReference.$$id;
372
+ let name = '';
373
+ let resolvedModuleData = config[modulePath];
374
+
375
+ if (resolvedModuleData) {
376
+ // The potentially aliased name.
377
+ name = resolvedModuleData.name;
378
+ } else {
379
+ // We didn't find this specific export name but we might have the * export
380
+ // which contains this name as well.
381
+ // TODO: It's unfortunate that we now have to parse this string. We should
382
+ // probably go back to encoding path and name separately on the client reference.
383
+ const idx = modulePath.lastIndexOf('#');
384
+
385
+ if (idx !== -1) {
386
+ name = modulePath.slice(idx + 1);
387
+ resolvedModuleData = config[modulePath.slice(0, idx)];
388
+ }
389
+
390
+ if (!resolvedModuleData) {
391
+ throw new Error('Could not find the module "' + modulePath + '" in the React Client Manifest. ' + 'This is probably a bug in the React Server Components bundler.');
392
+ }
393
+ }
394
+
395
+ if (clientReference.$$async === true) {
396
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name, 1];
397
+ } else {
398
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name];
399
+ }
400
+ }
401
+ function getServerReferenceId(config, serverReference) {
402
+ return serverReference.$$id;
403
+ }
404
+ function getServerReferenceBoundArguments(config, serverReference) {
405
+ return serverReference.$$bound;
406
+ }
407
+
408
+ const ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
409
+
410
+ const ReactDOMCurrentDispatcher = ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
411
+ const previousDispatcher = ReactDOMCurrentDispatcher.current;
412
+ ReactDOMCurrentDispatcher.current = {
413
+ prefetchDNS,
414
+ preconnect,
415
+ preload,
416
+ preloadModule: preloadModule$1,
417
+ preinitStyle,
418
+ preinitScript,
419
+ preinitModuleScript
420
+ };
421
+
422
+ function prefetchDNS(href) {
423
+ if (typeof href === 'string' && href) {
424
+ const request = resolveRequest();
425
+
426
+ if (request) {
427
+ const hints = getHints(request);
428
+ const key = 'D|' + href;
429
+
430
+ if (hints.has(key)) {
431
+ // duplicate hint
432
+ return;
433
+ }
434
+
435
+ hints.add(key);
436
+ emitHint(request, 'D', href);
437
+ } else {
438
+ previousDispatcher.prefetchDNS(href);
439
+ }
440
+ }
441
+ }
442
+
443
+ function preconnect(href, crossOrigin) {
444
+ if (typeof href === 'string') {
445
+ const request = resolveRequest();
446
+
447
+ if (request) {
448
+ const hints = getHints(request);
449
+ const key = "C|" + (crossOrigin == null ? 'null' : crossOrigin) + "|" + href;
450
+
451
+ if (hints.has(key)) {
452
+ // duplicate hint
453
+ return;
454
+ }
455
+
456
+ hints.add(key);
457
+
458
+ if (typeof crossOrigin === 'string') {
459
+ emitHint(request, 'C', [href, crossOrigin]);
460
+ } else {
461
+ emitHint(request, 'C', href);
462
+ }
463
+ } else {
464
+ previousDispatcher.preconnect(href, crossOrigin);
465
+ }
466
+ }
467
+ }
468
+
469
+ function preload(href, as, options) {
470
+ if (typeof href === 'string') {
471
+ const request = resolveRequest();
472
+
473
+ if (request) {
474
+ const hints = getHints(request);
475
+ let key = 'L';
476
+
477
+ if (as === 'image' && options) {
478
+ key += getImagePreloadKey(href, options.imageSrcSet, options.imageSizes);
479
+ } else {
480
+ key += "[" + as + "]" + href;
481
+ }
482
+
483
+ if (hints.has(key)) {
484
+ // duplicate hint
485
+ return;
486
+ }
487
+
488
+ hints.add(key);
489
+ const trimmed = trimOptions(options);
490
+
491
+ if (trimmed) {
492
+ emitHint(request, 'L', [href, as, trimmed]);
493
+ } else {
494
+ emitHint(request, 'L', [href, as]);
495
+ }
496
+ } else {
497
+ previousDispatcher.preload(href, as, options);
498
+ }
499
+ }
500
+ }
501
+
502
+ function preloadModule$1(href, options) {
503
+ if (typeof href === 'string') {
504
+ const request = resolveRequest();
505
+
506
+ if (request) {
507
+ const hints = getHints(request);
508
+ const key = 'm|' + href;
509
+
510
+ if (hints.has(key)) {
511
+ // duplicate hint
512
+ return;
513
+ }
514
+
515
+ hints.add(key);
516
+ const trimmed = trimOptions(options);
517
+
518
+ if (trimmed) {
519
+ return emitHint(request, 'm', [href, trimmed]);
520
+ } else {
521
+ return emitHint(request, 'm', href);
522
+ }
523
+ } else {
524
+ previousDispatcher.preloadModule(href, options);
525
+ }
526
+ }
527
+ }
528
+
529
+ function preinitStyle(href, precedence, options) {
530
+ if (typeof href === 'string') {
531
+ const request = resolveRequest();
532
+
533
+ if (request) {
534
+ const hints = getHints(request);
535
+ const key = 'S|' + href;
536
+
537
+ if (hints.has(key)) {
538
+ // duplicate hint
539
+ return;
540
+ }
541
+
542
+ hints.add(key);
543
+ const trimmed = trimOptions(options);
544
+
545
+ if (trimmed) {
546
+ return emitHint(request, 'S', [href, typeof precedence === 'string' ? precedence : 0, trimmed]);
547
+ } else if (typeof precedence === 'string') {
548
+ return emitHint(request, 'S', [href, precedence]);
549
+ } else {
550
+ return emitHint(request, 'S', href);
551
+ }
552
+ } else {
553
+ previousDispatcher.preinitStyle(href, precedence, options);
554
+ }
555
+ }
556
+ }
557
+
558
+ function preinitScript(src, options) {
559
+ if (typeof src === 'string') {
560
+ const request = resolveRequest();
561
+
562
+ if (request) {
563
+ const hints = getHints(request);
564
+ const key = 'X|' + src;
565
+
566
+ if (hints.has(key)) {
567
+ // duplicate hint
568
+ return;
569
+ }
570
+
571
+ hints.add(key);
572
+ const trimmed = trimOptions(options);
573
+
574
+ if (trimmed) {
575
+ return emitHint(request, 'X', [src, trimmed]);
576
+ } else {
577
+ return emitHint(request, 'X', src);
578
+ }
579
+ } else {
580
+ previousDispatcher.preinitScript(src, options);
581
+ }
582
+ }
583
+ }
584
+
585
+ function preinitModuleScript(src, options) {
586
+ if (typeof src === 'string') {
587
+ const request = resolveRequest();
588
+
589
+ if (request) {
590
+ const hints = getHints(request);
591
+ const key = 'M|' + src;
592
+
593
+ if (hints.has(key)) {
594
+ // duplicate hint
595
+ return;
596
+ }
597
+
598
+ hints.add(key);
599
+ const trimmed = trimOptions(options);
600
+
601
+ if (trimmed) {
602
+ return emitHint(request, 'M', [src, trimmed]);
603
+ } else {
604
+ return emitHint(request, 'M', src);
605
+ }
606
+ } else {
607
+ previousDispatcher.preinitModuleScript(src, options);
608
+ }
609
+ }
610
+ } // Flight normally encodes undefined as a special character however for directive option
611
+ // arguments we don't want to send unnecessary keys and bloat the payload so we create a
612
+ // trimmed object which omits any keys with null or undefined values.
613
+ // This is only typesafe because these option objects have entirely optional fields where
614
+ // null and undefined represent the same thing as no property.
615
+
616
+
617
+ function trimOptions(options) {
618
+ if (options == null) return null;
619
+ let hasProperties = false;
620
+ const trimmed = {};
621
+
622
+ for (const key in options) {
623
+ if (options[key] != null) {
624
+ hasProperties = true;
625
+ trimmed[key] = options[key];
626
+ }
627
+ }
628
+
629
+ return hasProperties ? trimmed : null;
630
+ }
631
+
632
+ function getImagePreloadKey(href, imageSrcSet, imageSizes) {
633
+ let uniquePart = '';
634
+
635
+ if (typeof imageSrcSet === 'string' && imageSrcSet !== '') {
636
+ uniquePart += '[' + imageSrcSet + ']';
637
+
638
+ if (typeof imageSizes === 'string') {
639
+ uniquePart += '[' + imageSizes + ']';
640
+ }
641
+ } else {
642
+ uniquePart += '[][]' + href;
643
+ }
644
+
645
+ return "[image]" + uniquePart;
646
+ }
647
+
648
+ // This module registers the host dispatcher so it needs to be imported
649
+ // small, smaller than how we encode undefined, and is unambiguous. We could use
650
+ // a different tuple structure to encode this instead but this makes the runtime
651
+ // cost cheaper by eliminating a type checks in more positions.
652
+ // prettier-ignore
653
+
654
+ function createHints() {
655
+ return new Set();
656
+ }
657
+
658
+ const supportsRequestStorage = false;
659
+ const requestStorage = null;
660
+
661
+ const TEMPORARY_REFERENCE_TAG = Symbol.for('react.temporary.reference'); // eslint-disable-next-line no-unused-vars
662
+
663
+ function isTemporaryReference(reference) {
664
+ return reference.$$typeof === TEMPORARY_REFERENCE_TAG;
665
+ }
666
+ function resolveTemporaryReferenceID(temporaryReference) {
667
+ return temporaryReference.$$id;
668
+ }
669
+ const proxyHandlers = {
670
+ get: function (target, name, receiver) {
671
+ switch (name) {
672
+ // These names are read by the Flight runtime if you end up using the exports object.
673
+ case '$$typeof':
674
+ // These names are a little too common. We should probably have a way to
675
+ // have the Flight runtime extract the inner target instead.
676
+ return target.$$typeof;
677
+
678
+ case '$$id':
679
+ return target.$$id;
680
+
681
+ case '$$async':
682
+ return target.$$async;
683
+
684
+ case 'name':
685
+ return undefined;
686
+
687
+ case 'displayName':
688
+ return undefined;
689
+ // We need to special case this because createElement reads it if we pass this
690
+ // reference.
691
+
692
+ case 'defaultProps':
693
+ return undefined;
694
+ // Avoid this attempting to be serialized.
695
+
696
+ case 'toJSON':
697
+ return undefined;
698
+
699
+ case Symbol.toPrimitive:
700
+ // $FlowFixMe[prop-missing]
701
+ return Object.prototype[Symbol.toPrimitive];
702
+
703
+ case Symbol.toStringTag:
704
+ // $FlowFixMe[prop-missing]
705
+ return Object.prototype[Symbol.toStringTag];
706
+
707
+ case 'Provider':
708
+ throw new Error("Cannot render a Client Context Provider on the Server. " + "Instead, you can export a Client Component wrapper " + "that itself renders a Client Context Provider.");
709
+ }
710
+
711
+ throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
712
+ "Cannot access " + String(name) + " on the server. " + 'You cannot dot into a temporary client reference from a server component. ' + 'You can only pass the value through to the client.');
713
+ },
714
+ set: function () {
715
+ throw new Error('Cannot assign to a temporary client reference from a server module.');
716
+ }
717
+ };
718
+ function createTemporaryReference(id) {
719
+ const reference = Object.defineProperties(function () {
720
+ throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
721
+ "Attempted to call a temporary Client Reference from the server but it is on the client. " + "It's not possible to invoke a client function from the server, it can " + "only be rendered as a Component or passed to props of a Client Component.");
722
+ }, {
723
+ $$typeof: {
724
+ value: TEMPORARY_REFERENCE_TAG
725
+ },
726
+ $$id: {
727
+ value: id
728
+ }
729
+ });
730
+ return new Proxy(reference, proxyHandlers);
731
+ }
732
+
733
+ // ATTENTION
734
+ // When adding new symbols to this file,
735
+ // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
736
+ // The Symbol used to tag the ReactElement-like types.
737
+ const REACT_ELEMENT_TYPE = Symbol.for('react.element');
738
+ const REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
739
+ const REACT_CONTEXT_TYPE = Symbol.for('react.context');
740
+ const REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
741
+ const REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
742
+ const REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
743
+ const REACT_MEMO_TYPE = Symbol.for('react.memo');
744
+ const REACT_LAZY_TYPE = Symbol.for('react.lazy');
745
+ const REACT_MEMO_CACHE_SENTINEL = Symbol.for('react.memo_cache_sentinel');
746
+ const REACT_POSTPONE_TYPE = Symbol.for('react.postpone');
747
+ const MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
748
+ const FAUX_ITERATOR_SYMBOL = '@@iterator';
749
+ function getIteratorFn(maybeIterable) {
750
+ if (maybeIterable === null || typeof maybeIterable !== 'object') {
751
+ return null;
752
+ }
753
+
754
+ const maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
755
+
756
+ if (typeof maybeIterator === 'function') {
757
+ return maybeIterator;
758
+ }
759
+
760
+ return null;
761
+ }
762
+
763
+ // Corresponds to ReactFiberWakeable and ReactFizzWakeable modules. Generally,
764
+ // changes to one module should be reflected in the others.
765
+ // TODO: Rename this module and the corresponding Fiber one to "Thenable"
766
+ // instead of "Wakeable". Or some other more appropriate name.
767
+ // An error that is thrown (e.g. by `use`) to trigger Suspense. If we
768
+ // detect this is caught by userspace, we'll log a warning in development.
769
+ const SuspenseException = new Error("Suspense Exception: This is not a real error! It's an implementation " + 'detail of `use` to interrupt the current render. You must either ' + 'rethrow it immediately, or move the `use` call outside of the ' + '`try/catch` block. Capturing without rethrowing will lead to ' + 'unexpected behavior.\n\n' + 'To handle async errors, wrap your component in an error boundary, or ' + "call the promise's `.catch` method and pass the result to `use`");
770
+ function createThenableState() {
771
+ // The ThenableState is created the first time a component suspends. If it
772
+ // suspends again, we'll reuse the same state.
773
+ return [];
774
+ }
775
+
776
+ function noop() {}
777
+
778
+ function trackUsedThenable(thenableState, thenable, index) {
779
+ const previous = thenableState[index];
780
+
781
+ if (previous === undefined) {
782
+ thenableState.push(thenable);
783
+ } else {
784
+ if (previous !== thenable) {
785
+ // Reuse the previous thenable, and drop the new one. We can assume
786
+ // they represent the same value, because components are idempotent.
787
+ // Avoid an unhandled rejection errors for the Promises that we'll
788
+ // intentionally ignore.
789
+ thenable.then(noop, noop);
790
+ thenable = previous;
791
+ }
792
+ } // We use an expando to track the status and result of a thenable so that we
793
+ // can synchronously unwrap the value. Think of this as an extension of the
794
+ // Promise API, or a custom interface that is a superset of Thenable.
795
+ //
796
+ // If the thenable doesn't have a status, set it to "pending" and attach
797
+ // a listener that will update its status and result when it resolves.
798
+
799
+
800
+ switch (thenable.status) {
801
+ case 'fulfilled':
802
+ {
803
+ const fulfilledValue = thenable.value;
804
+ return fulfilledValue;
805
+ }
806
+
807
+ case 'rejected':
808
+ {
809
+ const rejectedError = thenable.reason;
810
+ throw rejectedError;
811
+ }
812
+
813
+ default:
814
+ {
815
+ if (typeof thenable.status === 'string') ; else {
816
+ const pendingThenable = thenable;
817
+ pendingThenable.status = 'pending';
818
+ pendingThenable.then(fulfilledValue => {
819
+ if (thenable.status === 'pending') {
820
+ const fulfilledThenable = thenable;
821
+ fulfilledThenable.status = 'fulfilled';
822
+ fulfilledThenable.value = fulfilledValue;
823
+ }
824
+ }, error => {
825
+ if (thenable.status === 'pending') {
826
+ const rejectedThenable = thenable;
827
+ rejectedThenable.status = 'rejected';
828
+ rejectedThenable.reason = error;
829
+ }
830
+ }); // Check one more time in case the thenable resolved synchronously
831
+
832
+ switch (thenable.status) {
833
+ case 'fulfilled':
834
+ {
835
+ const fulfilledThenable = thenable;
836
+ return fulfilledThenable.value;
837
+ }
838
+
839
+ case 'rejected':
840
+ {
841
+ const rejectedThenable = thenable;
842
+ throw rejectedThenable.reason;
843
+ }
844
+ }
845
+ } // Suspend.
846
+ //
847
+ // Throwing here is an implementation detail that allows us to unwind the
848
+ // call stack. But we shouldn't allow it to leak into userspace. Throw an
849
+ // opaque placeholder value instead of the actual thenable. If it doesn't
850
+ // get captured by the work loop, log a warning, because that means
851
+ // something in userspace must have caught it.
852
+
853
+
854
+ suspendedThenable = thenable;
855
+ throw SuspenseException;
856
+ }
857
+ }
858
+ } // This is used to track the actual thenable that suspended so it can be
859
+ // passed to the rest of the Suspense implementation — which, for historical
860
+ // reasons, expects to receive a thenable.
861
+
862
+ let suspendedThenable = null;
863
+ function getSuspendedThenable() {
864
+ // This is called right after `use` suspends by throwing an exception. `use`
865
+ // throws an opaque value instead of the thenable itself so that it can't be
866
+ // caught in userspace. Then the work loop accesses the actual thenable using
867
+ // this function.
868
+ if (suspendedThenable === null) {
869
+ throw new Error('Expected a suspended thenable. This is a bug in React. Please file ' + 'an issue.');
870
+ }
871
+
872
+ const thenable = suspendedThenable;
873
+ suspendedThenable = null;
874
+ return thenable;
875
+ }
876
+
877
+ let currentRequest$1 = null;
878
+ let thenableIndexCounter = 0;
879
+ let thenableState = null;
880
+ function prepareToUseHooksForRequest(request) {
881
+ currentRequest$1 = request;
882
+ }
883
+ function resetHooksForRequest() {
884
+ currentRequest$1 = null;
885
+ }
886
+ function prepareToUseHooksForComponent(prevThenableState) {
887
+ thenableIndexCounter = 0;
888
+ thenableState = prevThenableState;
889
+ }
890
+ function getThenableStateAfterSuspending() {
891
+ // If you use() to Suspend this should always exist but if you throw a Promise instead,
892
+ // which is not really supported anymore, it will be empty. We use the empty set as a
893
+ // marker to know if this was a replay of the same component or first attempt.
894
+ const state = thenableState || createThenableState();
895
+ thenableState = null;
896
+ return state;
897
+ }
898
+ const HooksDispatcher = {
899
+ useMemo(nextCreate) {
900
+ return nextCreate();
901
+ },
902
+
903
+ useCallback(callback) {
904
+ return callback;
905
+ },
906
+
907
+ useDebugValue() {},
908
+
909
+ useDeferredValue: unsupportedHook,
910
+ useTransition: unsupportedHook,
911
+ readContext: unsupportedContext,
912
+ useContext: unsupportedContext,
913
+ useReducer: unsupportedHook,
914
+ useRef: unsupportedHook,
915
+ useState: unsupportedHook,
916
+ useInsertionEffect: unsupportedHook,
917
+ useLayoutEffect: unsupportedHook,
918
+ useImperativeHandle: unsupportedHook,
919
+ useEffect: unsupportedHook,
920
+ useId,
921
+ useSyncExternalStore: unsupportedHook,
922
+
923
+ useCacheRefresh() {
924
+ return unsupportedRefresh;
925
+ },
926
+
927
+ useMemoCache(size) {
928
+ const data = new Array(size);
929
+
930
+ for (let i = 0; i < size; i++) {
931
+ data[i] = REACT_MEMO_CACHE_SENTINEL;
932
+ }
933
+
934
+ return data;
935
+ },
936
+
937
+ use
938
+ };
939
+
940
+ function unsupportedHook() {
941
+ throw new Error('This Hook is not supported in Server Components.');
942
+ }
943
+
944
+ function unsupportedRefresh() {
945
+ throw new Error('Refreshing the cache is not supported in Server Components.');
946
+ }
947
+
948
+ function unsupportedContext() {
949
+ throw new Error('Cannot read a Client Context from a Server Component.');
950
+ }
951
+
952
+ function useId() {
953
+ if (currentRequest$1 === null) {
954
+ throw new Error('useId can only be used while React is rendering');
955
+ }
956
+
957
+ const id = currentRequest$1.identifierCount++; // use 'S' for Flight components to distinguish from 'R' and 'r' in Fizz/Client
958
+
959
+ return ':' + currentRequest$1.identifierPrefix + 'S' + id.toString(32) + ':';
960
+ }
961
+
962
+ function use(usable) {
963
+ if (usable !== null && typeof usable === 'object' || typeof usable === 'function') {
964
+ // $FlowFixMe[method-unbinding]
965
+ if (typeof usable.then === 'function') {
966
+ // This is a thenable.
967
+ const thenable = usable; // Track the position of the thenable within this fiber.
968
+
969
+ const index = thenableIndexCounter;
970
+ thenableIndexCounter += 1;
971
+
972
+ if (thenableState === null) {
973
+ thenableState = createThenableState();
974
+ }
975
+
976
+ return trackUsedThenable(thenableState, thenable, index);
977
+ } else if (usable.$$typeof === REACT_CONTEXT_TYPE) {
978
+ unsupportedContext();
979
+ }
980
+ }
981
+
982
+ if (isClientReference(usable)) {
983
+ if (usable.value != null && usable.value.$$typeof === REACT_CONTEXT_TYPE) {
984
+ // Show a more specific message since it's a common mistake.
985
+ throw new Error('Cannot read a Client Context from a Server Component.');
986
+ } else {
987
+ throw new Error('Cannot use() an already resolved Client Reference.');
988
+ }
989
+ } else {
990
+ throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
991
+ 'An unsupported type was passed to use(): ' + String(usable));
992
+ }
993
+ }
994
+
995
+ function createSignal() {
996
+ return new AbortController().signal;
997
+ }
998
+
999
+ function resolveCache() {
1000
+ const request = resolveRequest();
1001
+
1002
+ if (request) {
1003
+ return getCache(request);
1004
+ }
1005
+
1006
+ return new Map();
1007
+ }
1008
+
1009
+ const DefaultCacheDispatcher = {
1010
+ getCacheSignal() {
1011
+ const cache = resolveCache();
1012
+ let entry = cache.get(createSignal);
1013
+
1014
+ if (entry === undefined) {
1015
+ entry = createSignal();
1016
+ cache.set(createSignal, entry);
1017
+ }
1018
+
1019
+ return entry;
1020
+ },
1021
+
1022
+ getCacheForType(resourceType) {
1023
+ const cache = resolveCache();
1024
+ let entry = cache.get(resourceType);
1025
+
1026
+ if (entry === undefined) {
1027
+ entry = resourceType(); // TODO: Warn if undefined?
1028
+
1029
+ cache.set(resourceType, entry);
1030
+ }
1031
+
1032
+ return entry;
1033
+ }
1034
+
1035
+ };
1036
+
1037
+ const isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
1038
+
1039
+ function isArray(a) {
1040
+ return isArrayImpl(a);
1041
+ }
1042
+
1043
+ const getPrototypeOf = Object.getPrototypeOf;
1044
+
1045
+ function objectName(object) {
1046
+ // $FlowFixMe[method-unbinding]
1047
+ const name = Object.prototype.toString.call(object);
1048
+ return name.replace(/^\[object (.*)\]$/, function (m, p0) {
1049
+ return p0;
1050
+ });
1051
+ }
1052
+
1053
+ function describeKeyForErrorMessage(key) {
1054
+ const encodedKey = JSON.stringify(key);
1055
+ return '"' + key + '"' === encodedKey ? key : encodedKey;
1056
+ }
1057
+
1058
+ function describeValueForErrorMessage(value) {
1059
+ switch (typeof value) {
1060
+ case 'string':
1061
+ {
1062
+ return JSON.stringify(value.length <= 10 ? value : value.slice(0, 10) + '...');
1063
+ }
1064
+
1065
+ case 'object':
1066
+ {
1067
+ if (isArray(value)) {
1068
+ return '[...]';
1069
+ }
1070
+
1071
+ if (value !== null && value.$$typeof === CLIENT_REFERENCE_TAG) {
1072
+ return describeClientReference();
1073
+ }
1074
+
1075
+ const name = objectName(value);
1076
+
1077
+ if (name === 'Object') {
1078
+ return '{...}';
1079
+ }
1080
+
1081
+ return name;
1082
+ }
1083
+
1084
+ case 'function':
1085
+ {
1086
+ if (value.$$typeof === CLIENT_REFERENCE_TAG) {
1087
+ return describeClientReference();
1088
+ }
1089
+
1090
+ const name = value.displayName || value.name;
1091
+ return name ? 'function ' + name : 'function';
1092
+ }
1093
+
1094
+ default:
1095
+ // eslint-disable-next-line react-internal/safe-string-coercion
1096
+ return String(value);
1097
+ }
1098
+ }
1099
+
1100
+ function describeElementType(type) {
1101
+ if (typeof type === 'string') {
1102
+ return type;
1103
+ }
1104
+
1105
+ switch (type) {
1106
+ case REACT_SUSPENSE_TYPE:
1107
+ return 'Suspense';
1108
+
1109
+ case REACT_SUSPENSE_LIST_TYPE:
1110
+ return 'SuspenseList';
1111
+ }
1112
+
1113
+ if (typeof type === 'object') {
1114
+ switch (type.$$typeof) {
1115
+ case REACT_FORWARD_REF_TYPE:
1116
+ return describeElementType(type.render);
1117
+
1118
+ case REACT_MEMO_TYPE:
1119
+ return describeElementType(type.type);
1120
+
1121
+ case REACT_LAZY_TYPE:
1122
+ {
1123
+ const lazyComponent = type;
1124
+ const payload = lazyComponent._payload;
1125
+ const init = lazyComponent._init;
1126
+
1127
+ try {
1128
+ // Lazy may contain any component type so we recursively resolve it.
1129
+ return describeElementType(init(payload));
1130
+ } catch (x) {}
1131
+ }
1132
+ }
1133
+ }
1134
+
1135
+ return '';
1136
+ }
1137
+
1138
+ const CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
1139
+
1140
+ function describeClientReference(ref) {
1141
+ return 'client';
1142
+ }
1143
+
1144
+ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1145
+ const objKind = objectName(objectOrArray);
1146
+
1147
+ if (objKind !== 'Object' && objKind !== 'Array') {
1148
+ return objKind;
1149
+ }
1150
+
1151
+ let str = '';
1152
+ let start = -1;
1153
+ let length = 0;
1154
+
1155
+ if (isArray(objectOrArray)) {
1156
+ {
1157
+ // Print Array
1158
+ str = '[';
1159
+ const array = objectOrArray;
1160
+
1161
+ for (let i = 0; i < array.length; i++) {
1162
+ if (i > 0) {
1163
+ str += ', ';
1164
+ }
1165
+
1166
+ const value = array[i];
1167
+ let substr;
1168
+
1169
+ if (typeof value === 'object' && value !== null) {
1170
+ substr = describeObjectForErrorMessage(value);
1171
+ } else {
1172
+ substr = describeValueForErrorMessage(value);
1173
+ }
1174
+
1175
+ if ('' + i === expandedName) {
1176
+ start = str.length;
1177
+ length = substr.length;
1178
+ str += substr;
1179
+ } else if (substr.length < 10 && str.length + substr.length < 40) {
1180
+ str += substr;
1181
+ } else {
1182
+ str += '...';
1183
+ }
1184
+ }
1185
+
1186
+ str += ']';
1187
+ }
1188
+ } else {
1189
+ if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
1190
+ str = '<' + describeElementType(objectOrArray.type) + '/>';
1191
+ } else if (objectOrArray.$$typeof === CLIENT_REFERENCE_TAG) {
1192
+ return describeClientReference();
1193
+ } else {
1194
+ // Print Object
1195
+ str = '{';
1196
+ const object = objectOrArray;
1197
+ const names = Object.keys(object);
1198
+
1199
+ for (let i = 0; i < names.length; i++) {
1200
+ if (i > 0) {
1201
+ str += ', ';
1202
+ }
1203
+
1204
+ const name = names[i];
1205
+ str += describeKeyForErrorMessage(name) + ': ';
1206
+ const value = object[name];
1207
+ let substr;
1208
+
1209
+ if (typeof value === 'object' && value !== null) {
1210
+ substr = describeObjectForErrorMessage(value);
1211
+ } else {
1212
+ substr = describeValueForErrorMessage(value);
1213
+ }
1214
+
1215
+ if (name === expandedName) {
1216
+ start = str.length;
1217
+ length = substr.length;
1218
+ str += substr;
1219
+ } else if (substr.length < 10 && str.length + substr.length < 40) {
1220
+ str += substr;
1221
+ } else {
1222
+ str += '...';
1223
+ }
1224
+ }
1225
+
1226
+ str += '}';
1227
+ }
1228
+ }
1229
+
1230
+ if (expandedName === undefined) {
1231
+ return str;
1232
+ }
1233
+
1234
+ if (start > -1 && length > 0) {
1235
+ const highlight = ' '.repeat(start) + '^'.repeat(length);
1236
+ return '\n ' + str + '\n ' + highlight;
1237
+ }
1238
+
1239
+ return '\n ' + str;
1240
+ }
1241
+
1242
+ const ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
1243
+
1244
+ const ReactSharedServerInternals = // $FlowFixMe: It's defined in the one we resolve to.
1245
+ React.__SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
1246
+
1247
+ if (!ReactSharedServerInternals) {
1248
+ throw new Error('The "react" package in this environment is not configured correctly. ' + 'The "react-server" condition must be enabled in any environment that ' + 'runs React Server Components.');
1249
+ }
1250
+
1251
+ const ObjectPrototype = Object.prototype;
1252
+ const stringify = JSON.stringify; // Serializable values
1253
+ // Thenable<ReactClientValue>
1254
+
1255
+ const PENDING$1 = 0;
1256
+ const COMPLETED = 1;
1257
+ const ABORTED = 3;
1258
+ const ERRORED$1 = 4;
1259
+ const ReactCurrentCache = ReactSharedServerInternals.ReactCurrentCache;
1260
+ const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
1261
+
1262
+ function defaultErrorHandler(error) {
1263
+ console['error'](error); // Don't transform to our wrapper
1264
+ }
1265
+
1266
+ function defaultPostponeHandler(reason) {// Noop
1267
+ }
1268
+
1269
+ const OPEN = 0;
1270
+ const CLOSING = 1;
1271
+ const CLOSED = 2;
1272
+ function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpone, environmentName) {
1273
+ if (ReactCurrentCache.current !== null && ReactCurrentCache.current !== DefaultCacheDispatcher) {
1274
+ throw new Error('Currently React only supports one RSC renderer at a time.');
1275
+ }
1276
+
1277
+ ReactCurrentCache.current = DefaultCacheDispatcher;
1278
+ const abortSet = new Set();
1279
+ const pingedTasks = [];
1280
+ const cleanupQueue = [];
1281
+
1282
+ const hints = createHints();
1283
+ const request = {
1284
+ status: OPEN,
1285
+ flushScheduled: false,
1286
+ fatalError: null,
1287
+ destination: null,
1288
+ bundlerConfig,
1289
+ cache: new Map(),
1290
+ nextChunkId: 0,
1291
+ pendingChunks: 0,
1292
+ hints,
1293
+ abortableTasks: abortSet,
1294
+ pingedTasks: pingedTasks,
1295
+ completedImportChunks: [],
1296
+ completedHintChunks: [],
1297
+ completedRegularChunks: [],
1298
+ completedErrorChunks: [],
1299
+ writtenSymbols: new Map(),
1300
+ writtenClientReferences: new Map(),
1301
+ writtenServerReferences: new Map(),
1302
+ writtenObjects: new WeakMap(),
1303
+ identifierPrefix: identifierPrefix || '',
1304
+ identifierCount: 1,
1305
+ taintCleanupQueue: cleanupQueue,
1306
+ onError: onError === undefined ? defaultErrorHandler : onError,
1307
+ onPostpone: onPostpone === undefined ? defaultPostponeHandler : onPostpone
1308
+ };
1309
+
1310
+ const rootTask = createTask(request, model, null, false, abortSet);
1311
+ pingedTasks.push(rootTask);
1312
+ return request;
1313
+ }
1314
+ let currentRequest = null;
1315
+ function resolveRequest() {
1316
+ if (currentRequest) return currentRequest;
1317
+
1318
+ return null;
1319
+ }
1320
+
1321
+ function serializeThenable(request, task, thenable) {
1322
+ const newTask = createTask(request, null, task.keyPath, // the server component sequence continues through Promise-as-a-child.
1323
+ task.implicitSlot, request.abortableTasks);
1324
+
1325
+ switch (thenable.status) {
1326
+ case 'fulfilled':
1327
+ {
1328
+ // We have the resolved value, we can go ahead and schedule it for serialization.
1329
+ newTask.model = thenable.value;
1330
+ pingTask(request, newTask);
1331
+ return newTask.id;
1332
+ }
1333
+
1334
+ case 'rejected':
1335
+ {
1336
+ const x = thenable.reason;
1337
+
1338
+ {
1339
+ const digest = logRecoverableError(request, x);
1340
+ emitErrorChunk(request, newTask.id, digest);
1341
+ }
1342
+
1343
+ return newTask.id;
1344
+ }
1345
+
1346
+ default:
1347
+ {
1348
+ if (typeof thenable.status === 'string') {
1349
+ // Only instrument the thenable if the status if not defined. If
1350
+ // it's defined, but an unknown value, assume it's been instrumented by
1351
+ // some custom userspace implementation. We treat it as "pending".
1352
+ break;
1353
+ }
1354
+
1355
+ const pendingThenable = thenable;
1356
+ pendingThenable.status = 'pending';
1357
+ pendingThenable.then(fulfilledValue => {
1358
+ if (thenable.status === 'pending') {
1359
+ const fulfilledThenable = thenable;
1360
+ fulfilledThenable.status = 'fulfilled';
1361
+ fulfilledThenable.value = fulfilledValue;
1362
+ }
1363
+ }, error => {
1364
+ if (thenable.status === 'pending') {
1365
+ const rejectedThenable = thenable;
1366
+ rejectedThenable.status = 'rejected';
1367
+ rejectedThenable.reason = error;
1368
+ }
1369
+ });
1370
+ break;
1371
+ }
1372
+ }
1373
+
1374
+ thenable.then(value => {
1375
+ newTask.model = value;
1376
+ pingTask(request, newTask);
1377
+ }, reason => {
1378
+ {
1379
+ newTask.status = ERRORED$1;
1380
+ const digest = logRecoverableError(request, reason);
1381
+ emitErrorChunk(request, newTask.id, digest);
1382
+ }
1383
+
1384
+ request.abortableTasks.delete(newTask);
1385
+
1386
+ if (request.destination !== null) {
1387
+ flushCompletedChunks(request, request.destination);
1388
+ }
1389
+ });
1390
+ return newTask.id;
1391
+ }
1392
+
1393
+ function emitHint(request, code, model) {
1394
+ emitHintChunk(request, code, model);
1395
+ enqueueFlush(request);
1396
+ }
1397
+ function getHints(request) {
1398
+ return request.hints;
1399
+ }
1400
+ function getCache(request) {
1401
+ return request.cache;
1402
+ }
1403
+
1404
+ function readThenable(thenable) {
1405
+ if (thenable.status === 'fulfilled') {
1406
+ return thenable.value;
1407
+ } else if (thenable.status === 'rejected') {
1408
+ throw thenable.reason;
1409
+ }
1410
+
1411
+ throw thenable;
1412
+ }
1413
+
1414
+ function createLazyWrapperAroundWakeable(wakeable) {
1415
+ // This is a temporary fork of the `use` implementation until we accept
1416
+ // promises everywhere.
1417
+ const thenable = wakeable;
1418
+
1419
+ switch (thenable.status) {
1420
+ case 'fulfilled':
1421
+ case 'rejected':
1422
+ break;
1423
+
1424
+ default:
1425
+ {
1426
+ if (typeof thenable.status === 'string') {
1427
+ // Only instrument the thenable if the status if not defined. If
1428
+ // it's defined, but an unknown value, assume it's been instrumented by
1429
+ // some custom userspace implementation. We treat it as "pending".
1430
+ break;
1431
+ }
1432
+
1433
+ const pendingThenable = thenable;
1434
+ pendingThenable.status = 'pending';
1435
+ pendingThenable.then(fulfilledValue => {
1436
+ if (thenable.status === 'pending') {
1437
+ const fulfilledThenable = thenable;
1438
+ fulfilledThenable.status = 'fulfilled';
1439
+ fulfilledThenable.value = fulfilledValue;
1440
+ }
1441
+ }, error => {
1442
+ if (thenable.status === 'pending') {
1443
+ const rejectedThenable = thenable;
1444
+ rejectedThenable.status = 'rejected';
1445
+ rejectedThenable.reason = error;
1446
+ }
1447
+ });
1448
+ break;
1449
+ }
1450
+ }
1451
+
1452
+ const lazyType = {
1453
+ $$typeof: REACT_LAZY_TYPE,
1454
+ _payload: thenable,
1455
+ _init: readThenable
1456
+ };
1457
+
1458
+ return lazyType;
1459
+ }
1460
+
1461
+ function renderFunctionComponent(request, task, key, Component, props) {
1462
+ // Reset the task's thenable state before continuing, so that if a later
1463
+ // component suspends we can reuse the same task object. If the same
1464
+ // component suspends again, the thenable state will be restored.
1465
+ const prevThenableState = task.thenableState;
1466
+ task.thenableState = null;
1467
+
1468
+ prepareToUseHooksForComponent(prevThenableState); // The secondArg is always undefined in Server Components since refs error early.
1469
+
1470
+ const secondArg = undefined;
1471
+ let result = Component(props, secondArg);
1472
+
1473
+ if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
1474
+ // When the return value is in children position we can resolve it immediately,
1475
+ // to its value without a wrapper if it's synchronously available.
1476
+ const thenable = result;
1477
+
1478
+ if (thenable.status === 'fulfilled') {
1479
+ return thenable.value;
1480
+ } // TODO: Once we accept Promises as children on the client, we can just return
1481
+ // the thenable here.
1482
+
1483
+
1484
+ result = createLazyWrapperAroundWakeable(result);
1485
+ } // Track this element's key on the Server Component on the keyPath context..
1486
+
1487
+
1488
+ const prevKeyPath = task.keyPath;
1489
+ const prevImplicitSlot = task.implicitSlot;
1490
+
1491
+ if (key !== null) {
1492
+ // Append the key to the path. Technically a null key should really add the child
1493
+ // index. We don't do that to hold the payload small and implementation simple.
1494
+ task.keyPath = prevKeyPath === null ? key : prevKeyPath + ',' + key;
1495
+ } else if (prevKeyPath === null) {
1496
+ // This sequence of Server Components has no keys. This means that it was rendered
1497
+ // in a slot that needs to assign an implicit key. Even if children below have
1498
+ // explicit keys, they should not be used for the outer most key since it might
1499
+ // collide with other slots in that set.
1500
+ task.implicitSlot = true;
1501
+ }
1502
+
1503
+ const json = renderModelDestructive(request, task, emptyRoot, '', result);
1504
+ task.keyPath = prevKeyPath;
1505
+ task.implicitSlot = prevImplicitSlot;
1506
+ return json;
1507
+ }
1508
+
1509
+ function renderFragment(request, task, children) {
1510
+
1511
+ {
1512
+ return children;
1513
+ }
1514
+ }
1515
+
1516
+ function renderClientElement(task, type, key, props) {
1517
+ {
1518
+ return [REACT_ELEMENT_TYPE, type, key, props];
1519
+ } // We prepend the terminal client element that actually gets serialized with
1520
+ } // The chunk ID we're currently rendering that we can assign debug data to.
1521
+
1522
+
1523
+ let debugID = null;
1524
+
1525
+ function renderElement(request, task, type, key, ref, props) {
1526
+ if (ref !== null && ref !== undefined) {
1527
+ // When the ref moves to the regular props object this will implicitly
1528
+ // throw for functions. We could probably relax it to a DEV warning for other
1529
+ // cases.
1530
+ // TODO: `ref` is now just a prop when `enableRefAsProp` is on. Should we
1531
+ // do what the above comment says?
1532
+ throw new Error('Refs cannot be used in Server Components, nor passed to Client Components.');
1533
+ }
1534
+
1535
+ if (typeof type === 'function') {
1536
+ if (isClientReference(type) || isTemporaryReference(type)) {
1537
+ // This is a reference to a Client Component.
1538
+ return renderClientElement(task, type, key, props);
1539
+ } // This is a Server Component.
1540
+
1541
+
1542
+ return renderFunctionComponent(request, task, key, type, props);
1543
+ } else if (typeof type === 'string') {
1544
+ // This is a host element. E.g. HTML.
1545
+ return renderClientElement(task, type, key, props);
1546
+ } else if (typeof type === 'symbol') {
1547
+ if (type === REACT_FRAGMENT_TYPE && key === null) {
1548
+ // For key-less fragments, we add a small optimization to avoid serializing
1549
+ // it as a wrapper.
1550
+ const prevImplicitSlot = task.implicitSlot;
1551
+
1552
+ if (task.keyPath === null) {
1553
+ task.implicitSlot = true;
1554
+ }
1555
+
1556
+ const json = renderModelDestructive(request, task, emptyRoot, '', props.children);
1557
+ task.implicitSlot = prevImplicitSlot;
1558
+ return json;
1559
+ } // This might be a built-in React component. We'll let the client decide.
1560
+ // Any built-in works as long as its props are serializable.
1561
+
1562
+
1563
+ return renderClientElement(task, type, key, props);
1564
+ } else if (type != null && typeof type === 'object') {
1565
+ if (isClientReference(type)) {
1566
+ // This is a reference to a Client Component.
1567
+ return renderClientElement(task, type, key, props);
1568
+ }
1569
+
1570
+ switch (type.$$typeof) {
1571
+ case REACT_LAZY_TYPE:
1572
+ {
1573
+ const payload = type._payload;
1574
+ const init = type._init;
1575
+ const wrappedType = init(payload);
1576
+ return renderElement(request, task, wrappedType, key, ref, props);
1577
+ }
1578
+
1579
+ case REACT_FORWARD_REF_TYPE:
1580
+ {
1581
+ return renderFunctionComponent(request, task, key, type.render, props);
1582
+ }
1583
+
1584
+ case REACT_MEMO_TYPE:
1585
+ {
1586
+ return renderElement(request, task, type.type, key, ref, props);
1587
+ }
1588
+ }
1589
+ }
1590
+
1591
+ throw new Error("Unsupported Server Component type: " + describeValueForErrorMessage(type));
1592
+ }
1593
+
1594
+ function pingTask(request, task) {
1595
+ const pingedTasks = request.pingedTasks;
1596
+ pingedTasks.push(task);
1597
+
1598
+ if (pingedTasks.length === 1) {
1599
+ request.flushScheduled = request.destination !== null;
1600
+ scheduleWork(() => performWork(request));
1601
+ }
1602
+ }
1603
+
1604
+ function createTask(request, model, keyPath, implicitSlot, abortSet) {
1605
+ request.pendingChunks++;
1606
+ const id = request.nextChunkId++;
1607
+
1608
+ if (typeof model === 'object' && model !== null) {
1609
+ // If we're about to write this into a new task we can assign it an ID early so that
1610
+ // any other references can refer to the value we're about to write.
1611
+ {
1612
+ request.writtenObjects.set(model, id);
1613
+ }
1614
+ }
1615
+
1616
+ const task = {
1617
+ id,
1618
+ status: PENDING$1,
1619
+ model,
1620
+ keyPath,
1621
+ implicitSlot,
1622
+ ping: () => pingTask(request, task),
1623
+ toJSON: function (parentPropertyName, value) {
1624
+ const parent = this; // Make sure that `parent[parentPropertyName]` wasn't JSONified before `value` was passed to us
1625
+
1626
+ return renderModel(request, task, parent, parentPropertyName, value);
1627
+ },
1628
+ thenableState: null
1629
+ };
1630
+ abortSet.add(task);
1631
+ return task;
1632
+ }
1633
+
1634
+ function serializeByValueID(id) {
1635
+ return '$' + id.toString(16);
1636
+ }
1637
+
1638
+ function serializeLazyID(id) {
1639
+ return '$L' + id.toString(16);
1640
+ }
1641
+
1642
+ function serializePromiseID(id) {
1643
+ return '$@' + id.toString(16);
1644
+ }
1645
+
1646
+ function serializeServerReferenceID(id) {
1647
+ return '$F' + id.toString(16);
1648
+ }
1649
+
1650
+ function serializeTemporaryReferenceID(id) {
1651
+ return '$T' + id;
1652
+ }
1653
+
1654
+ function serializeSymbolReference(name) {
1655
+ return '$S' + name;
1656
+ }
1657
+
1658
+ function serializeNumber(number) {
1659
+ if (Number.isFinite(number)) {
1660
+ if (number === 0 && 1 / number === -Infinity) {
1661
+ return '$-0';
1662
+ } else {
1663
+ return number;
1664
+ }
1665
+ } else {
1666
+ if (number === Infinity) {
1667
+ return '$Infinity';
1668
+ } else if (number === -Infinity) {
1669
+ return '$-Infinity';
1670
+ } else {
1671
+ return '$NaN';
1672
+ }
1673
+ }
1674
+ }
1675
+
1676
+ function serializeUndefined() {
1677
+ return '$undefined';
1678
+ }
1679
+
1680
+ function serializeDateFromDateJSON(dateJSON) {
1681
+ // JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
1682
+ // We need only tack on a $D prefix.
1683
+ return '$D' + dateJSON;
1684
+ }
1685
+
1686
+ function serializeBigInt(n) {
1687
+ return '$n' + n.toString(10);
1688
+ }
1689
+
1690
+ function serializeRowHeader(tag, id) {
1691
+ return id.toString(16) + ':' + tag;
1692
+ }
1693
+
1694
+ function encodeReferenceChunk(request, id, reference) {
1695
+ const json = stringify(reference);
1696
+ const row = id.toString(16) + ':' + json + '\n';
1697
+ return stringToChunk(row);
1698
+ }
1699
+
1700
+ function serializeClientReference(request, parent, parentPropertyName, clientReference) {
1701
+ const clientReferenceKey = getClientReferenceKey(clientReference);
1702
+ const writtenClientReferences = request.writtenClientReferences;
1703
+ const existingId = writtenClientReferences.get(clientReferenceKey);
1704
+
1705
+ if (existingId !== undefined) {
1706
+ if (parent[0] === REACT_ELEMENT_TYPE && parentPropertyName === '1') {
1707
+ // If we're encoding the "type" of an element, we can refer
1708
+ // to that by a lazy reference instead of directly since React
1709
+ // knows how to deal with lazy values. This lets us suspend
1710
+ // on this component rather than its parent until the code has
1711
+ // loaded.
1712
+ return serializeLazyID(existingId);
1713
+ }
1714
+
1715
+ return serializeByValueID(existingId);
1716
+ }
1717
+
1718
+ try {
1719
+ const clientReferenceMetadata = resolveClientReferenceMetadata(request.bundlerConfig, clientReference);
1720
+ request.pendingChunks++;
1721
+ const importId = request.nextChunkId++;
1722
+ emitImportChunk(request, importId, clientReferenceMetadata);
1723
+ writtenClientReferences.set(clientReferenceKey, importId);
1724
+
1725
+ if (parent[0] === REACT_ELEMENT_TYPE && parentPropertyName === '1') {
1726
+ // If we're encoding the "type" of an element, we can refer
1727
+ // to that by a lazy reference instead of directly since React
1728
+ // knows how to deal with lazy values. This lets us suspend
1729
+ // on this component rather than its parent until the code has
1730
+ // loaded.
1731
+ return serializeLazyID(importId);
1732
+ }
1733
+
1734
+ return serializeByValueID(importId);
1735
+ } catch (x) {
1736
+ request.pendingChunks++;
1737
+ const errorId = request.nextChunkId++;
1738
+ const digest = logRecoverableError(request, x);
1739
+ emitErrorChunk(request, errorId, digest);
1740
+ return serializeByValueID(errorId);
1741
+ }
1742
+ }
1743
+
1744
+ function outlineModel(request, value) {
1745
+ const newTask = createTask(request, value, null, // The way we use outlining is for reusing an object.
1746
+ false, // It makes no sense for that use case to be contextual.
1747
+ request.abortableTasks);
1748
+ retryTask(request, newTask);
1749
+ return newTask.id;
1750
+ }
1751
+
1752
+ function serializeServerReference(request, serverReference) {
1753
+ const writtenServerReferences = request.writtenServerReferences;
1754
+ const existingId = writtenServerReferences.get(serverReference);
1755
+
1756
+ if (existingId !== undefined) {
1757
+ return serializeServerReferenceID(existingId);
1758
+ }
1759
+
1760
+ const bound = getServerReferenceBoundArguments(request.bundlerConfig, serverReference);
1761
+ const serverReferenceMetadata = {
1762
+ id: getServerReferenceId(request.bundlerConfig, serverReference),
1763
+ bound: bound ? Promise.resolve(bound) : null
1764
+ };
1765
+ const metadataId = outlineModel(request, serverReferenceMetadata);
1766
+ writtenServerReferences.set(serverReference, metadataId);
1767
+ return serializeServerReferenceID(metadataId);
1768
+ }
1769
+
1770
+ function serializeTemporaryReference(request, temporaryReference) {
1771
+ const id = resolveTemporaryReferenceID(temporaryReference);
1772
+ return serializeTemporaryReferenceID(id);
1773
+ }
1774
+
1775
+ function serializeLargeTextString(request, text) {
1776
+ request.pendingChunks += 2;
1777
+ const textId = request.nextChunkId++;
1778
+ const textChunk = stringToChunk(text);
1779
+ const binaryLength = byteLengthOfChunk(textChunk);
1780
+ const row = textId.toString(16) + ':T' + binaryLength.toString(16) + ',';
1781
+ const headerChunk = stringToChunk(row);
1782
+ request.completedRegularChunks.push(headerChunk, textChunk);
1783
+ return serializeByValueID(textId);
1784
+ }
1785
+
1786
+ function serializeMap(request, map) {
1787
+ const entries = Array.from(map);
1788
+
1789
+ for (let i = 0; i < entries.length; i++) {
1790
+ const key = entries[i][0];
1791
+
1792
+ if (typeof key === 'object' && key !== null) {
1793
+ const writtenObjects = request.writtenObjects;
1794
+ const existingId = writtenObjects.get(key);
1795
+
1796
+ if (existingId === undefined) {
1797
+ // Mark all object keys as seen so that they're always outlined.
1798
+ writtenObjects.set(key, -1);
1799
+ }
1800
+ }
1801
+ }
1802
+
1803
+ const id = outlineModel(request, entries);
1804
+ return '$Q' + id.toString(16);
1805
+ }
1806
+
1807
+ function serializeSet(request, set) {
1808
+ const entries = Array.from(set);
1809
+
1810
+ for (let i = 0; i < entries.length; i++) {
1811
+ const key = entries[i];
1812
+
1813
+ if (typeof key === 'object' && key !== null) {
1814
+ const writtenObjects = request.writtenObjects;
1815
+ const existingId = writtenObjects.get(key);
1816
+
1817
+ if (existingId === undefined) {
1818
+ // Mark all object keys as seen so that they're always outlined.
1819
+ writtenObjects.set(key, -1);
1820
+ }
1821
+ }
1822
+ }
1823
+
1824
+ const id = outlineModel(request, entries);
1825
+ return '$W' + id.toString(16);
1826
+ }
1827
+
1828
+ function escapeStringValue(value) {
1829
+ if (value[0] === '$') {
1830
+ // We need to escape $ prefixed strings since we use those to encode
1831
+ // references to IDs and as special symbol values.
1832
+ return '$' + value;
1833
+ } else {
1834
+ return value;
1835
+ }
1836
+ }
1837
+
1838
+ let modelRoot = false;
1839
+
1840
+ function renderModel(request, task, parent, key, value) {
1841
+ const prevKeyPath = task.keyPath;
1842
+ const prevImplicitSlot = task.implicitSlot;
1843
+
1844
+ try {
1845
+ return renderModelDestructive(request, task, parent, key, value);
1846
+ } catch (thrownValue) {
1847
+ const x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
1848
+ // reasons, the rest of the Suspense implementation expects the thrown
1849
+ // value to be a thenable, because before `use` existed that was the
1850
+ // (unstable) API for suspending. This implementation detail can change
1851
+ // later, once we deprecate the old API in favor of `use`.
1852
+ getSuspendedThenable() : thrownValue; // If the suspended/errored value was an element or lazy it can be reduced
1853
+ // to a lazy reference, so that it doesn't error the parent.
1854
+
1855
+ const model = task.model;
1856
+ const wasReactNode = typeof model === 'object' && model !== null && (model.$$typeof === REACT_ELEMENT_TYPE || model.$$typeof === REACT_LAZY_TYPE);
1857
+
1858
+ if (typeof x === 'object' && x !== null) {
1859
+ // $FlowFixMe[method-unbinding]
1860
+ if (typeof x.then === 'function') {
1861
+ // Something suspended, we'll need to create a new task and resolve it later.
1862
+ const newTask = createTask(request, task.model, task.keyPath, task.implicitSlot, request.abortableTasks);
1863
+ const ping = newTask.ping;
1864
+ x.then(ping, ping);
1865
+ newTask.thenableState = getThenableStateAfterSuspending(); // Restore the context. We assume that this will be restored by the inner
1866
+ // functions in case nothing throws so we don't use "finally" here.
1867
+
1868
+ task.keyPath = prevKeyPath;
1869
+ task.implicitSlot = prevImplicitSlot;
1870
+
1871
+ if (wasReactNode) {
1872
+ return serializeLazyID(newTask.id);
1873
+ }
1874
+
1875
+ return serializeByValueID(newTask.id);
1876
+ }
1877
+ } // Restore the context. We assume that this will be restored by the inner
1878
+ // functions in case nothing throws so we don't use "finally" here.
1879
+
1880
+
1881
+ task.keyPath = prevKeyPath;
1882
+ task.implicitSlot = prevImplicitSlot;
1883
+
1884
+ if (wasReactNode) {
1885
+ // Something errored. We'll still send everything we have up until this point.
1886
+ // We'll replace this element with a lazy reference that throws on the client
1887
+ // once it gets rendered.
1888
+ request.pendingChunks++;
1889
+ const errorId = request.nextChunkId++;
1890
+ const digest = logRecoverableError(request, x);
1891
+ emitErrorChunk(request, errorId, digest);
1892
+ return serializeLazyID(errorId);
1893
+ } // Something errored but it was not in a React Node. There's no need to serialize
1894
+ // it by value because it'll just error the whole parent row anyway so we can
1895
+ // just stop any siblings and error the whole parent row.
1896
+
1897
+
1898
+ throw x;
1899
+ }
1900
+ }
1901
+
1902
+ function renderModelDestructive(request, task, parent, parentPropertyName, value) {
1903
+ // Set the currently rendering model
1904
+ task.model = value; // Special Symbol, that's very common.
1905
+
1906
+ if (value === REACT_ELEMENT_TYPE) {
1907
+ return '$';
1908
+ }
1909
+
1910
+ if (value === null) {
1911
+ return null;
1912
+ }
1913
+
1914
+ if (typeof value === 'object') {
1915
+ switch (value.$$typeof) {
1916
+ case REACT_ELEMENT_TYPE:
1917
+ {
1918
+ const writtenObjects = request.writtenObjects;
1919
+ const existingId = writtenObjects.get(value);
1920
+
1921
+ if (existingId !== undefined) {
1922
+ if (modelRoot === value) {
1923
+ // This is the ID we're currently emitting so we need to write it
1924
+ // once but if we discover it again, we refer to it by id.
1925
+ modelRoot = null;
1926
+ } else if (existingId === -1) {
1927
+ // Seen but not yet outlined.
1928
+ // TODO: If we throw here we can treat this as suspending which causes an outline
1929
+ // but that is able to reuse the same task if we're already in one but then that
1930
+ // will be a lazy future value rather than guaranteed to exist but maybe that's good.
1931
+ const newId = outlineModel(request, value);
1932
+ return serializeByValueID(newId);
1933
+ } else {
1934
+ // We've already emitted this as an outlined object, so we can refer to that by its
1935
+ // existing ID. TODO: We should use a lazy reference since, unlike plain objects,
1936
+ // elements might suspend so it might not have emitted yet even if we have the ID for
1937
+ // it. However, this creates an extra wrapper when it's not needed. We should really
1938
+ // detect whether this already was emitted and synchronously available. In that
1939
+ // case we can refer to it synchronously and only make it lazy otherwise.
1940
+ // We currently don't have a data structure that lets us see that though.
1941
+ return serializeByValueID(existingId);
1942
+ }
1943
+ } else {
1944
+ // This is the first time we've seen this object. We may never see it again
1945
+ // so we'll inline it. Mark it as seen. If we see it again, we'll outline.
1946
+ writtenObjects.set(value, -1);
1947
+ }
1948
+
1949
+ const element = value;
1950
+
1951
+ const props = element.props;
1952
+ let ref;
1953
+
1954
+ {
1955
+ ref = element.ref;
1956
+ } // Attempt to render the Server Component.
1957
+
1958
+
1959
+ return renderElement(request, task, element.type, // $FlowFixMe[incompatible-call] the key of an element is null | string
1960
+ element.key, ref, props);
1961
+ }
1962
+
1963
+ case REACT_LAZY_TYPE:
1964
+ {
1965
+ // Reset the task's thenable state before continuing. If there was one, it was
1966
+ // from suspending the lazy before.
1967
+ task.thenableState = null;
1968
+ const lazy = value;
1969
+ const payload = lazy._payload;
1970
+ const init = lazy._init;
1971
+ const resolvedModel = init(payload);
1972
+
1973
+ return renderModelDestructive(request, task, emptyRoot, '', resolvedModel);
1974
+ }
1975
+ }
1976
+
1977
+ if (isClientReference(value)) {
1978
+ return serializeClientReference(request, parent, parentPropertyName, value);
1979
+ }
1980
+
1981
+ const writtenObjects = request.writtenObjects;
1982
+ const existingId = writtenObjects.get(value); // $FlowFixMe[method-unbinding]
1983
+
1984
+ if (typeof value.then === 'function') {
1985
+ if (existingId !== undefined) {
1986
+ if (modelRoot === value) {
1987
+ // This is the ID we're currently emitting so we need to write it
1988
+ // once but if we discover it again, we refer to it by id.
1989
+ modelRoot = null;
1990
+ } else {
1991
+ // We've seen this promise before, so we can just refer to the same result.
1992
+ return serializePromiseID(existingId);
1993
+ }
1994
+ } // We assume that any object with a .then property is a "Thenable" type,
1995
+ // or a Promise type. Either of which can be represented by a Promise.
1996
+
1997
+
1998
+ const promiseId = serializeThenable(request, task, value);
1999
+ writtenObjects.set(value, promiseId);
2000
+ return serializePromiseID(promiseId);
2001
+ }
2002
+
2003
+ if (existingId !== undefined) {
2004
+ if (modelRoot === value) {
2005
+ // This is the ID we're currently emitting so we need to write it
2006
+ // once but if we discover it again, we refer to it by id.
2007
+ modelRoot = null;
2008
+ } else if (existingId === -1) {
2009
+ // Seen but not yet outlined.
2010
+ const newId = outlineModel(request, value);
2011
+ return serializeByValueID(newId);
2012
+ } else {
2013
+ // We've already emitted this as an outlined object, so we can
2014
+ // just refer to that by its existing ID.
2015
+ return serializeByValueID(existingId);
2016
+ }
2017
+ } else {
2018
+ // This is the first time we've seen this object. We may never see it again
2019
+ // so we'll inline it. Mark it as seen. If we see it again, we'll outline.
2020
+ writtenObjects.set(value, -1);
2021
+ }
2022
+
2023
+ if (isArray(value)) {
2024
+ return renderFragment(request, task, value);
2025
+ }
2026
+
2027
+ if (value instanceof Map) {
2028
+ return serializeMap(request, value);
2029
+ }
2030
+
2031
+ if (value instanceof Set) {
2032
+ return serializeSet(request, value);
2033
+ }
2034
+
2035
+ const iteratorFn = getIteratorFn(value);
2036
+
2037
+ if (iteratorFn) {
2038
+ return renderFragment(request, task, Array.from(value));
2039
+ } // Verify that this is a simple plain object.
2040
+
2041
+
2042
+ const proto = getPrototypeOf(value);
2043
+
2044
+ if (proto !== ObjectPrototype && (proto === null || getPrototypeOf(proto) !== null)) {
2045
+ throw new Error('Only plain objects, and a few built-ins, can be passed to Client Components ' + 'from Server Components. Classes or null prototypes are not supported.');
2046
+ }
2047
+
2048
+
2049
+ return value;
2050
+ }
2051
+
2052
+ if (typeof value === 'string') {
2053
+
2054
+
2055
+ if (value[value.length - 1] === 'Z') {
2056
+ // Possibly a Date, whose toJSON automatically calls toISOString
2057
+ // $FlowFixMe[incompatible-use]
2058
+ const originalValue = parent[parentPropertyName];
2059
+
2060
+ if (originalValue instanceof Date) {
2061
+ return serializeDateFromDateJSON(value);
2062
+ }
2063
+ }
2064
+
2065
+ if (value.length >= 1024) {
2066
+ // For large strings, we encode them outside the JSON payload so that we
2067
+ // don't have to double encode and double parse the strings. This can also
2068
+ // be more compact in case the string has a lot of escaped characters.
2069
+ return serializeLargeTextString(request, value);
2070
+ }
2071
+
2072
+ return escapeStringValue(value);
2073
+ }
2074
+
2075
+ if (typeof value === 'boolean') {
2076
+ return value;
2077
+ }
2078
+
2079
+ if (typeof value === 'number') {
2080
+ return serializeNumber(value);
2081
+ }
2082
+
2083
+ if (typeof value === 'undefined') {
2084
+ return serializeUndefined();
2085
+ }
2086
+
2087
+ if (typeof value === 'function') {
2088
+ if (isClientReference(value)) {
2089
+ return serializeClientReference(request, parent, parentPropertyName, value);
2090
+ }
2091
+
2092
+ if (isServerReference(value)) {
2093
+ return serializeServerReference(request, value);
2094
+ }
2095
+
2096
+ if (isTemporaryReference(value)) {
2097
+ return serializeTemporaryReference(request, value);
2098
+ }
2099
+
2100
+ if (/^on[A-Z]/.test(parentPropertyName)) {
2101
+ throw new Error('Event handlers cannot be passed to Client Component props.' + describeObjectForErrorMessage(parent, parentPropertyName) + '\nIf you need interactivity, consider converting part of this to a Client Component.');
2102
+ } else {
2103
+ throw new Error('Functions cannot be passed directly to Client Components ' + 'unless you explicitly expose it by marking it with "use server". ' + 'Or maybe you meant to call this function rather than return it.' + describeObjectForErrorMessage(parent, parentPropertyName));
2104
+ }
2105
+ }
2106
+
2107
+ if (typeof value === 'symbol') {
2108
+ const writtenSymbols = request.writtenSymbols;
2109
+ const existingId = writtenSymbols.get(value);
2110
+
2111
+ if (existingId !== undefined) {
2112
+ return serializeByValueID(existingId);
2113
+ } // $FlowFixMe[incompatible-type] `description` might be undefined
2114
+
2115
+
2116
+ const name = value.description;
2117
+
2118
+ if (Symbol.for(name) !== value) {
2119
+ throw new Error('Only global symbols received from Symbol.for(...) can be passed to Client Components. ' + ("The symbol Symbol.for(" + // $FlowFixMe[incompatible-type] `description` might be undefined
2120
+ value.description + ") cannot be found among global symbols.") + describeObjectForErrorMessage(parent, parentPropertyName));
2121
+ }
2122
+
2123
+ request.pendingChunks++;
2124
+ const symbolId = request.nextChunkId++;
2125
+ emitSymbolChunk(request, symbolId, name);
2126
+ writtenSymbols.set(value, symbolId);
2127
+ return serializeByValueID(symbolId);
2128
+ }
2129
+
2130
+ if (typeof value === 'bigint') {
2131
+
2132
+ return serializeBigInt(value);
2133
+ }
2134
+
2135
+ throw new Error("Type " + typeof value + " is not supported in Client Component props." + describeObjectForErrorMessage(parent, parentPropertyName));
2136
+ }
2137
+
2138
+ function logPostpone(request, reason) {
2139
+ const prevRequest = currentRequest;
2140
+ currentRequest = null;
2141
+
2142
+ try {
2143
+ const onPostpone = request.onPostpone;
2144
+
2145
+ if (supportsRequestStorage) ; else {
2146
+ onPostpone(reason);
2147
+ }
2148
+ } finally {
2149
+ currentRequest = prevRequest;
2150
+ }
2151
+ }
2152
+
2153
+ function logRecoverableError(request, error) {
2154
+ const prevRequest = currentRequest;
2155
+ currentRequest = null;
2156
+ let errorDigest;
2157
+
2158
+ try {
2159
+ const onError = request.onError;
2160
+
2161
+ if (supportsRequestStorage) ; else {
2162
+ errorDigest = onError(error);
2163
+ }
2164
+ } finally {
2165
+ currentRequest = prevRequest;
2166
+ }
2167
+
2168
+ if (errorDigest != null && typeof errorDigest !== 'string') {
2169
+ // eslint-disable-next-line react-internal/prod-error-codes
2170
+ throw new Error("onError returned something with a type other than \"string\". onError should return a string and may return null or undefined but must not return anything else. It received something of type \"" + typeof errorDigest + "\" instead");
2171
+ }
2172
+
2173
+ return errorDigest || '';
2174
+ }
2175
+
2176
+ function fatalError(request, error) {
2177
+
2178
+
2179
+ if (request.destination !== null) {
2180
+ request.status = CLOSED;
2181
+ closeWithError(request.destination, error);
2182
+ } else {
2183
+ request.status = CLOSING;
2184
+ request.fatalError = error;
2185
+ }
2186
+ }
2187
+
2188
+ function emitPostponeChunk(request, id, postponeInstance) {
2189
+ let row;
2190
+
2191
+ {
2192
+ // No reason included in prod.
2193
+ row = serializeRowHeader('P', id) + '\n';
2194
+ }
2195
+
2196
+ const processedChunk = stringToChunk(row);
2197
+ request.completedErrorChunks.push(processedChunk);
2198
+ }
2199
+
2200
+ function emitErrorChunk(request, id, digest, error) {
2201
+ let errorInfo;
2202
+
2203
+ {
2204
+ errorInfo = {
2205
+ digest
2206
+ };
2207
+ }
2208
+
2209
+ const row = serializeRowHeader('E', id) + stringify(errorInfo) + '\n';
2210
+ const processedChunk = stringToChunk(row);
2211
+ request.completedErrorChunks.push(processedChunk);
2212
+ }
2213
+
2214
+ function emitImportChunk(request, id, clientReferenceMetadata) {
2215
+ // $FlowFixMe[incompatible-type] stringify can return null
2216
+ const json = stringify(clientReferenceMetadata);
2217
+ const row = serializeRowHeader('I', id) + json + '\n';
2218
+ const processedChunk = stringToChunk(row);
2219
+ request.completedImportChunks.push(processedChunk);
2220
+ }
2221
+
2222
+ function emitHintChunk(request, code, model) {
2223
+ const json = stringify(model);
2224
+ const id = request.nextChunkId++;
2225
+ const row = serializeRowHeader('H' + code, id) + json + '\n';
2226
+ const processedChunk = stringToChunk(row);
2227
+ request.completedHintChunks.push(processedChunk);
2228
+ }
2229
+
2230
+ function emitSymbolChunk(request, id, name) {
2231
+ const symbolReference = serializeSymbolReference(name);
2232
+ const processedChunk = encodeReferenceChunk(request, id, symbolReference);
2233
+ request.completedImportChunks.push(processedChunk);
2234
+ }
2235
+
2236
+ function emitModelChunk(request, id, json) {
2237
+ const row = id.toString(16) + ':' + json + '\n';
2238
+ const processedChunk = stringToChunk(row);
2239
+ request.completedRegularChunks.push(processedChunk);
2240
+ }
2241
+
2242
+ const emptyRoot = {};
2243
+
2244
+ function retryTask(request, task) {
2245
+ if (task.status !== PENDING$1) {
2246
+ // We completed this by other means before we had a chance to retry it.
2247
+ return;
2248
+ }
2249
+
2250
+ try {
2251
+ // Track the root so we know that we have to emit this object even though it
2252
+ // already has an ID. This is needed because we might see this object twice
2253
+ // in the same toJSON if it is cyclic.
2254
+ modelRoot = task.model;
2255
+
2256
+ if (false) ; // We call the destructive form that mutates this task. That way if something
2257
+ // suspends again, we can reuse the same task instead of spawning a new one.
2258
+
2259
+
2260
+ const resolvedModel = renderModelDestructive(request, task, emptyRoot, '', task.model);
2261
+
2262
+ if (false) ; // Track the root again for the resolved object.
2263
+
2264
+
2265
+ modelRoot = resolvedModel; // The keyPath resets at any terminal child node.
2266
+
2267
+ task.keyPath = null;
2268
+ task.implicitSlot = false;
2269
+ let json;
2270
+
2271
+ if (typeof resolvedModel === 'object' && resolvedModel !== null) {
2272
+ // Object might contain unresolved values like additional elements.
2273
+ // This is simulating what the JSON loop would do if this was part of it.
2274
+ // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
2275
+ json = stringify(resolvedModel, task.toJSON);
2276
+ } else {
2277
+ // If the value is a string, it means it's a terminal value and we already escaped it
2278
+ // We don't need to escape it again so it's not passed the toJSON replacer.
2279
+ // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
2280
+ json = stringify(resolvedModel);
2281
+ }
2282
+
2283
+ emitModelChunk(request, task.id, json);
2284
+ request.abortableTasks.delete(task);
2285
+ task.status = COMPLETED;
2286
+ } catch (thrownValue) {
2287
+ const x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
2288
+ // reasons, the rest of the Suspense implementation expects the thrown
2289
+ // value to be a thenable, because before `use` existed that was the
2290
+ // (unstable) API for suspending. This implementation detail can change
2291
+ // later, once we deprecate the old API in favor of `use`.
2292
+ getSuspendedThenable() : thrownValue;
2293
+
2294
+ if (typeof x === 'object' && x !== null) {
2295
+ // $FlowFixMe[method-unbinding]
2296
+ if (typeof x.then === 'function') {
2297
+ // Something suspended again, let's pick it back up later.
2298
+ const ping = task.ping;
2299
+ x.then(ping, ping);
2300
+ task.thenableState = getThenableStateAfterSuspending();
2301
+ return;
2302
+ }
2303
+ }
2304
+
2305
+ request.abortableTasks.delete(task);
2306
+ task.status = ERRORED$1;
2307
+ const digest = logRecoverableError(request, x);
2308
+ emitErrorChunk(request, task.id, digest);
2309
+ } finally {
2310
+ }
2311
+ }
2312
+
2313
+ function performWork(request) {
2314
+ const prevDispatcher = ReactCurrentDispatcher.current;
2315
+ ReactCurrentDispatcher.current = HooksDispatcher;
2316
+ const prevRequest = currentRequest;
2317
+ currentRequest = request;
2318
+ prepareToUseHooksForRequest(request);
2319
+
2320
+ try {
2321
+ const pingedTasks = request.pingedTasks;
2322
+ request.pingedTasks = [];
2323
+
2324
+ for (let i = 0; i < pingedTasks.length; i++) {
2325
+ const task = pingedTasks[i];
2326
+ retryTask(request, task);
2327
+ }
2328
+
2329
+ if (request.destination !== null) {
2330
+ flushCompletedChunks(request, request.destination);
2331
+ }
2332
+ } catch (error) {
2333
+ logRecoverableError(request, error);
2334
+ fatalError(request, error);
2335
+ } finally {
2336
+ ReactCurrentDispatcher.current = prevDispatcher;
2337
+ resetHooksForRequest();
2338
+ currentRequest = prevRequest;
2339
+ }
2340
+ }
2341
+
2342
+ function abortTask(task, request, errorId) {
2343
+ task.status = ABORTED; // Instead of emitting an error per task.id, we emit a model that only
2344
+ // has a single value referencing the error.
2345
+
2346
+ const ref = serializeByValueID(errorId);
2347
+ const processedChunk = encodeReferenceChunk(request, task.id, ref);
2348
+ request.completedErrorChunks.push(processedChunk);
2349
+ }
2350
+
2351
+ function flushCompletedChunks(request, destination) {
2352
+ beginWriting();
2353
+
2354
+ try {
2355
+ // We emit module chunks first in the stream so that
2356
+ // they can be preloaded as early as possible.
2357
+ const importsChunks = request.completedImportChunks;
2358
+ let i = 0;
2359
+
2360
+ for (; i < importsChunks.length; i++) {
2361
+ request.pendingChunks--;
2362
+ const chunk = importsChunks[i];
2363
+ const keepWriting = writeChunkAndReturn(destination, chunk);
2364
+
2365
+ if (!keepWriting) ;
2366
+ }
2367
+
2368
+ importsChunks.splice(0, i); // Next comes hints.
2369
+
2370
+ const hintChunks = request.completedHintChunks;
2371
+ i = 0;
2372
+
2373
+ for (; i < hintChunks.length; i++) {
2374
+ const chunk = hintChunks[i];
2375
+ const keepWriting = writeChunkAndReturn(destination, chunk);
2376
+
2377
+ if (!keepWriting) ;
2378
+ }
2379
+
2380
+ hintChunks.splice(0, i); // Next comes model data.
2381
+
2382
+ const regularChunks = request.completedRegularChunks;
2383
+ i = 0;
2384
+
2385
+ for (; i < regularChunks.length; i++) {
2386
+ request.pendingChunks--;
2387
+ const chunk = regularChunks[i];
2388
+ const keepWriting = writeChunkAndReturn(destination, chunk);
2389
+
2390
+ if (!keepWriting) ;
2391
+ }
2392
+
2393
+ regularChunks.splice(0, i); // Finally, errors are sent. The idea is that it's ok to delay
2394
+ // any error messages and prioritize display of other parts of
2395
+ // the page.
2396
+
2397
+ const errorChunks = request.completedErrorChunks;
2398
+ i = 0;
2399
+
2400
+ for (; i < errorChunks.length; i++) {
2401
+ request.pendingChunks--;
2402
+ const chunk = errorChunks[i];
2403
+ const keepWriting = writeChunkAndReturn(destination, chunk);
2404
+
2405
+ if (!keepWriting) ;
2406
+ }
2407
+
2408
+ errorChunks.splice(0, i);
2409
+ } finally {
2410
+ request.flushScheduled = false;
2411
+ completeWriting(destination);
2412
+ }
2413
+
2414
+ if (request.pendingChunks === 0) {
2415
+
2416
+ close$1(destination);
2417
+ }
2418
+ }
2419
+
2420
+ function startWork(request) {
2421
+ request.flushScheduled = request.destination !== null;
2422
+
2423
+ {
2424
+ scheduleWork(() => performWork(request));
2425
+ }
2426
+ }
2427
+
2428
+ function enqueueFlush(request) {
2429
+ if (request.flushScheduled === false && // If there are pinged tasks we are going to flush anyway after work completes
2430
+ request.pingedTasks.length === 0 && // If there is no destination there is nothing we can flush to. A flush will
2431
+ // happen when we start flowing again
2432
+ request.destination !== null) {
2433
+ const destination = request.destination;
2434
+ request.flushScheduled = true;
2435
+ scheduleWork(() => flushCompletedChunks(request, destination));
2436
+ }
2437
+ }
2438
+
2439
+ function startFlowing(request, destination) {
2440
+ if (request.status === CLOSING) {
2441
+ request.status = CLOSED;
2442
+ closeWithError(destination, request.fatalError);
2443
+ return;
2444
+ }
2445
+
2446
+ if (request.status === CLOSED) {
2447
+ return;
2448
+ }
2449
+
2450
+ if (request.destination !== null) {
2451
+ // We're already flowing.
2452
+ return;
2453
+ }
2454
+
2455
+ request.destination = destination;
2456
+
2457
+ try {
2458
+ flushCompletedChunks(request, destination);
2459
+ } catch (error) {
2460
+ logRecoverableError(request, error);
2461
+ fatalError(request, error);
2462
+ }
2463
+ }
2464
+ function stopFlowing(request) {
2465
+ request.destination = null;
2466
+ } // This is called to early terminate a request. It creates an error at all pending tasks.
2467
+
2468
+ function abort(request, reason) {
2469
+ try {
2470
+ const abortableTasks = request.abortableTasks;
2471
+
2472
+ if (abortableTasks.size > 0) {
2473
+ // We have tasks to abort. We'll emit one error row and then emit a reference
2474
+ // to that row from every row that's still remaining.
2475
+ request.pendingChunks++;
2476
+ const errorId = request.nextChunkId++;
2477
+
2478
+ if (enablePostpone && typeof reason === 'object' && reason !== null && reason.$$typeof === REACT_POSTPONE_TYPE) ; else {
2479
+ const error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
2480
+ const digest = logRecoverableError(request, error);
2481
+ emitErrorChunk(request, errorId, digest, error);
2482
+ }
2483
+
2484
+ abortableTasks.forEach(task => abortTask(task, request, errorId));
2485
+ abortableTasks.clear();
2486
+ }
2487
+
2488
+ if (request.destination !== null) {
2489
+ flushCompletedChunks(request, request.destination);
2490
+ }
2491
+ } catch (error) {
2492
+ logRecoverableError(request, error);
2493
+ fatalError(request, error);
2494
+ }
2495
+ }
2496
+
2497
+ // This is the parsed shape of the wire format which is why it is
2498
+ // condensed to only the essentialy information
2499
+ const ID = 0;
2500
+ const CHUNKS = 1;
2501
+ const NAME = 2; // export const ASYNC = 3;
2502
+ // This logic is correct because currently only include the 4th tuple member
2503
+ // when the module is async. If that changes we will need to actually assert
2504
+ // the value is true. We don't index into the 4th slot because flow does not
2505
+ // like the potential out of bounds access
2506
+
2507
+ function isAsyncImport(metadata) {
2508
+ return metadata.length === 4;
2509
+ }
2510
+
2511
+ function resolveServerReference(bundlerConfig, id) {
2512
+ let name = '';
2513
+ let resolvedModuleData = bundlerConfig[id];
2514
+
2515
+ if (resolvedModuleData) {
2516
+ // The potentially aliased name.
2517
+ name = resolvedModuleData.name;
2518
+ } else {
2519
+ // We didn't find this specific export name but we might have the * export
2520
+ // which contains this name as well.
2521
+ // TODO: It's unfortunate that we now have to parse this string. We should
2522
+ // probably go back to encoding path and name separately on the client reference.
2523
+ const idx = id.lastIndexOf('#');
2524
+
2525
+ if (idx !== -1) {
2526
+ name = id.slice(idx + 1);
2527
+ resolvedModuleData = bundlerConfig[id.slice(0, idx)];
2528
+ }
2529
+
2530
+ if (!resolvedModuleData) {
2531
+ throw new Error('Could not find the module "' + id + '" in the React Server Manifest. ' + 'This is probably a bug in the React Server Components bundler.');
2532
+ }
2533
+ } // TODO: This needs to return async: true if it's an async module.
2534
+
2535
+
2536
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name];
2537
+ } // The chunk cache contains all the chunks we've preloaded so far.
2538
+ // If they're still pending they're a thenable. This map also exists
2539
+ // in Webpack but unfortunately it's not exposed so we have to
2540
+ // replicate it in user space. null means that it has already loaded.
2541
+
2542
+ const chunkCache = new Map();
2543
+
2544
+ function requireAsyncModule(id) {
2545
+ // We've already loaded all the chunks. We can require the module.
2546
+ const promise = __webpack_require__(id);
2547
+
2548
+ if (typeof promise.then !== 'function') {
2549
+ // This wasn't a promise after all.
2550
+ return null;
2551
+ } else if (promise.status === 'fulfilled') {
2552
+ // This module was already resolved earlier.
2553
+ return null;
2554
+ } else {
2555
+ // Instrument the Promise to stash the result.
2556
+ promise.then(value => {
2557
+ const fulfilledThenable = promise;
2558
+ fulfilledThenable.status = 'fulfilled';
2559
+ fulfilledThenable.value = value;
2560
+ }, reason => {
2561
+ const rejectedThenable = promise;
2562
+ rejectedThenable.status = 'rejected';
2563
+ rejectedThenable.reason = reason;
2564
+ });
2565
+ return promise;
2566
+ }
2567
+ }
2568
+
2569
+ function ignoreReject() {// We rely on rejected promises to be handled by another listener.
2570
+ } // Start preloading the modules since we might need them soon.
2571
+ // This function doesn't suspend.
2572
+
2573
+
2574
+ function preloadModule(metadata) {
2575
+ const chunks = metadata[CHUNKS];
2576
+ const promises = [];
2577
+ let i = 0;
2578
+
2579
+ while (i < chunks.length) {
2580
+ const chunkId = chunks[i++];
2581
+ const chunkFilename = chunks[i++];
2582
+ const entry = chunkCache.get(chunkId);
2583
+
2584
+ if (entry === undefined) {
2585
+ const thenable = loadChunk(chunkId, chunkFilename);
2586
+ promises.push(thenable); // $FlowFixMe[method-unbinding]
2587
+
2588
+ const resolve = chunkCache.set.bind(chunkCache, chunkId, null);
2589
+ thenable.then(resolve, ignoreReject);
2590
+ chunkCache.set(chunkId, thenable);
2591
+ } else if (entry !== null) {
2592
+ promises.push(entry);
2593
+ }
2594
+ }
2595
+
2596
+ if (isAsyncImport(metadata)) {
2597
+ if (promises.length === 0) {
2598
+ return requireAsyncModule(metadata[ID]);
2599
+ } else {
2600
+ return Promise.all(promises).then(() => {
2601
+ return requireAsyncModule(metadata[ID]);
2602
+ });
2603
+ }
2604
+ } else if (promises.length > 0) {
2605
+ return Promise.all(promises);
2606
+ } else {
2607
+ return null;
2608
+ }
2609
+ } // Actually require the module or suspend if it's not yet ready.
2610
+ // Increase priority if necessary.
2611
+
2612
+ function requireModule(metadata) {
2613
+ let moduleExports = __webpack_require__(metadata[ID]);
2614
+
2615
+ if (isAsyncImport(metadata)) {
2616
+ if (typeof moduleExports.then !== 'function') ; else if (moduleExports.status === 'fulfilled') {
2617
+ // This Promise should've been instrumented by preloadModule.
2618
+ moduleExports = moduleExports.value;
2619
+ } else {
2620
+ throw moduleExports.reason;
2621
+ }
2622
+ }
2623
+
2624
+ if (metadata[NAME] === '*') {
2625
+ // This is a placeholder value that represents that the caller imported this
2626
+ // as a CommonJS module as is.
2627
+ return moduleExports;
2628
+ }
2629
+
2630
+ if (metadata[NAME] === '') {
2631
+ // This is a placeholder value that represents that the caller accessed the
2632
+ // default property of this if it was an ESM interop module.
2633
+ return moduleExports.__esModule ? moduleExports.default : moduleExports;
2634
+ }
2635
+
2636
+ return moduleExports[metadata[NAME]];
2637
+ }
2638
+
2639
+ const chunkMap = new Map();
2640
+ /**
2641
+ * We patch the chunk filename function in webpack to insert our own resolution
2642
+ * of chunks that come from Flight and may not be known to the webpack runtime
2643
+ */
2644
+
2645
+ const webpackGetChunkFilename = __webpack_require__.u;
2646
+
2647
+ __webpack_require__.u = function (chunkId) {
2648
+ const flightChunk = chunkMap.get(chunkId);
2649
+
2650
+ if (flightChunk !== undefined) {
2651
+ return flightChunk;
2652
+ }
2653
+
2654
+ return webpackGetChunkFilename(chunkId);
2655
+ };
2656
+
2657
+ function loadChunk(chunkId, filename) {
2658
+ chunkMap.set(chunkId, filename);
2659
+ return __webpack_chunk_load__(chunkId);
2660
+ }
2661
+
2662
+ // The server acts as a Client of itself when resolving Server References.
2663
+ const PENDING = 'pending';
2664
+ const BLOCKED = 'blocked';
2665
+ const RESOLVED_MODEL = 'resolved_model';
2666
+ const INITIALIZED = 'fulfilled';
2667
+ const ERRORED = 'rejected'; // $FlowFixMe[missing-this-annot]
2668
+
2669
+ function Chunk(status, value, reason, response) {
2670
+ this.status = status;
2671
+ this.value = value;
2672
+ this.reason = reason;
2673
+ this._response = response;
2674
+ } // We subclass Promise.prototype so that we get other methods like .catch
2675
+
2676
+
2677
+ Chunk.prototype = Object.create(Promise.prototype); // TODO: This doesn't return a new Promise chain unlike the real .then
2678
+
2679
+ Chunk.prototype.then = function (resolve, reject) {
2680
+ const chunk = this; // If we have resolved content, we try to initialize it first which
2681
+ // might put us back into one of the other states.
2682
+
2683
+ switch (chunk.status) {
2684
+ case RESOLVED_MODEL:
2685
+ initializeModelChunk(chunk);
2686
+ break;
2687
+ } // The status might have changed after initialization.
2688
+
2689
+
2690
+ switch (chunk.status) {
2691
+ case INITIALIZED:
2692
+ resolve(chunk.value);
2693
+ break;
2694
+
2695
+ case PENDING:
2696
+ case BLOCKED:
2697
+ if (resolve) {
2698
+ if (chunk.value === null) {
2699
+ chunk.value = [];
2700
+ }
2701
+
2702
+ chunk.value.push(resolve);
2703
+ }
2704
+
2705
+ if (reject) {
2706
+ if (chunk.reason === null) {
2707
+ chunk.reason = [];
2708
+ }
2709
+
2710
+ chunk.reason.push(reject);
2711
+ }
2712
+
2713
+ break;
2714
+
2715
+ default:
2716
+ reject(chunk.reason);
2717
+ break;
2718
+ }
2719
+ };
2720
+
2721
+ function getRoot(response) {
2722
+ const chunk = getChunk(response, 0);
2723
+ return chunk;
2724
+ }
2725
+
2726
+ function createPendingChunk(response) {
2727
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
2728
+ return new Chunk(PENDING, null, null, response);
2729
+ }
2730
+
2731
+ function wakeChunk(listeners, value) {
2732
+ for (let i = 0; i < listeners.length; i++) {
2733
+ const listener = listeners[i];
2734
+ listener(value);
2735
+ }
2736
+ }
2737
+
2738
+ function triggerErrorOnChunk(chunk, error) {
2739
+ if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
2740
+ // We already resolved. We didn't expect to see this.
2741
+ return;
2742
+ }
2743
+
2744
+ const listeners = chunk.reason;
2745
+ const erroredChunk = chunk;
2746
+ erroredChunk.status = ERRORED;
2747
+ erroredChunk.reason = error;
2748
+
2749
+ if (listeners !== null) {
2750
+ wakeChunk(listeners, error);
2751
+ }
2752
+ }
2753
+
2754
+ function createResolvedModelChunk(response, value) {
2755
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
2756
+ return new Chunk(RESOLVED_MODEL, value, null, response);
2757
+ }
2758
+
2759
+ function bindArgs$1(fn, args) {
2760
+ return fn.bind.apply(fn, [null].concat(args));
2761
+ }
2762
+
2763
+ function loadServerReference$1(response, id, bound, parentChunk, parentObject, key) {
2764
+ const serverReference = resolveServerReference(response._bundlerConfig, id); // We expect most servers to not really need this because you'd just have all
2765
+ // the relevant modules already loaded but it allows for lazy loading of code
2766
+ // if needed.
2767
+
2768
+ const preloadPromise = preloadModule(serverReference);
2769
+ let promise;
2770
+
2771
+ if (bound) {
2772
+ promise = Promise.all([bound, preloadPromise]).then((_ref) => {
2773
+ let args = _ref[0];
2774
+ return bindArgs$1(requireModule(serverReference), args);
2775
+ });
2776
+ } else {
2777
+ if (preloadPromise) {
2778
+ promise = Promise.resolve(preloadPromise).then(() => requireModule(serverReference));
2779
+ } else {
2780
+ // Synchronously available
2781
+ return requireModule(serverReference);
2782
+ }
2783
+ }
2784
+
2785
+ promise.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk)); // We need a placeholder value that will be replaced later.
2786
+
2787
+ return null;
2788
+ }
2789
+
2790
+ let initializingChunk = null;
2791
+ let initializingChunkBlockedModel = null;
2792
+
2793
+ function initializeModelChunk(chunk) {
2794
+ const prevChunk = initializingChunk;
2795
+ const prevBlocked = initializingChunkBlockedModel;
2796
+ initializingChunk = chunk;
2797
+ initializingChunkBlockedModel = null;
2798
+
2799
+ try {
2800
+ const value = JSON.parse(chunk.value, chunk._response._fromJSON);
2801
+
2802
+ if (initializingChunkBlockedModel !== null && initializingChunkBlockedModel.deps > 0) {
2803
+ initializingChunkBlockedModel.value = value; // We discovered new dependencies on modules that are not yet resolved.
2804
+ // We have to go the BLOCKED state until they're resolved.
2805
+
2806
+ const blockedChunk = chunk;
2807
+ blockedChunk.status = BLOCKED;
2808
+ blockedChunk.value = null;
2809
+ blockedChunk.reason = null;
2810
+ } else {
2811
+ const initializedChunk = chunk;
2812
+ initializedChunk.status = INITIALIZED;
2813
+ initializedChunk.value = value;
2814
+ }
2815
+ } catch (error) {
2816
+ const erroredChunk = chunk;
2817
+ erroredChunk.status = ERRORED;
2818
+ erroredChunk.reason = error;
2819
+ } finally {
2820
+ initializingChunk = prevChunk;
2821
+ initializingChunkBlockedModel = prevBlocked;
2822
+ }
2823
+ } // Report that any missing chunks in the model is now going to throw this
2824
+ // error upon read. Also notify any pending promises.
2825
+
2826
+
2827
+ function reportGlobalError(response, error) {
2828
+ response._chunks.forEach(chunk => {
2829
+ // If this chunk was already resolved or errored, it won't
2830
+ // trigger an error but if it wasn't then we need to
2831
+ // because we won't be getting any new data to resolve it.
2832
+ if (chunk.status === PENDING) {
2833
+ triggerErrorOnChunk(chunk, error);
2834
+ }
2835
+ });
2836
+ }
2837
+
2838
+ function getChunk(response, id) {
2839
+ const chunks = response._chunks;
2840
+ let chunk = chunks.get(id);
2841
+
2842
+ if (!chunk) {
2843
+ const prefix = response._prefix;
2844
+ const key = prefix + id; // Check if we have this field in the backing store already.
2845
+
2846
+ const backingEntry = response._formData.get(key);
2847
+
2848
+ if (backingEntry != null) {
2849
+ // We assume that this is a string entry for now.
2850
+ chunk = createResolvedModelChunk(response, backingEntry);
2851
+ } else {
2852
+ // We're still waiting on this entry to stream in.
2853
+ chunk = createPendingChunk(response);
2854
+ }
2855
+
2856
+ chunks.set(id, chunk);
2857
+ }
2858
+
2859
+ return chunk;
2860
+ }
2861
+
2862
+ function createModelResolver(chunk, parentObject, key) {
2863
+ let blocked;
2864
+
2865
+ if (initializingChunkBlockedModel) {
2866
+ blocked = initializingChunkBlockedModel;
2867
+ blocked.deps++;
2868
+ } else {
2869
+ blocked = initializingChunkBlockedModel = {
2870
+ deps: 1,
2871
+ value: null
2872
+ };
2873
+ }
2874
+
2875
+ return value => {
2876
+ parentObject[key] = value;
2877
+ blocked.deps--;
2878
+
2879
+ if (blocked.deps === 0) {
2880
+ if (chunk.status !== BLOCKED) {
2881
+ return;
2882
+ }
2883
+
2884
+ const resolveListeners = chunk.value;
2885
+ const initializedChunk = chunk;
2886
+ initializedChunk.status = INITIALIZED;
2887
+ initializedChunk.value = blocked.value;
2888
+
2889
+ if (resolveListeners !== null) {
2890
+ wakeChunk(resolveListeners, blocked.value);
2891
+ }
2892
+ }
2893
+ };
2894
+ }
2895
+
2896
+ function createModelReject(chunk) {
2897
+ return error => triggerErrorOnChunk(chunk, error);
2898
+ }
2899
+
2900
+ function getOutlinedModel(response, id) {
2901
+ const chunk = getChunk(response, id);
2902
+
2903
+ if (chunk.status === RESOLVED_MODEL) {
2904
+ initializeModelChunk(chunk);
2905
+ }
2906
+
2907
+ if (chunk.status !== INITIALIZED) {
2908
+ // We know that this is emitted earlier so otherwise it's an error.
2909
+ throw chunk.reason;
2910
+ }
2911
+
2912
+ return chunk.value;
2913
+ }
2914
+
2915
+ function parseModelString(response, parentObject, key, value) {
2916
+ if (value[0] === '$') {
2917
+ switch (value[1]) {
2918
+ case '$':
2919
+ {
2920
+ // This was an escaped string value.
2921
+ return value.slice(1);
2922
+ }
2923
+
2924
+ case '@':
2925
+ {
2926
+ // Promise
2927
+ const id = parseInt(value.slice(2), 16);
2928
+ const chunk = getChunk(response, id);
2929
+ return chunk;
2930
+ }
2931
+
2932
+ case 'F':
2933
+ {
2934
+ // Server Reference
2935
+ const id = parseInt(value.slice(2), 16); // TODO: Just encode this in the reference inline instead of as a model.
2936
+
2937
+ const metaData = getOutlinedModel(response, id);
2938
+ return loadServerReference$1(response, metaData.id, metaData.bound, initializingChunk, parentObject, key);
2939
+ }
2940
+
2941
+ case 'T':
2942
+ {
2943
+ // Temporary Reference
2944
+ return createTemporaryReference(value.slice(2));
2945
+ }
2946
+
2947
+ case 'Q':
2948
+ {
2949
+ // Map
2950
+ const id = parseInt(value.slice(2), 16);
2951
+ const data = getOutlinedModel(response, id);
2952
+ return new Map(data);
2953
+ }
2954
+
2955
+ case 'W':
2956
+ {
2957
+ // Set
2958
+ const id = parseInt(value.slice(2), 16);
2959
+ const data = getOutlinedModel(response, id);
2960
+ return new Set(data);
2961
+ }
2962
+
2963
+ case 'K':
2964
+ {
2965
+ // FormData
2966
+ const stringId = value.slice(2);
2967
+ const formPrefix = response._prefix + stringId + '_';
2968
+ const data = new FormData();
2969
+ const backingFormData = response._formData; // We assume that the reference to FormData always comes after each
2970
+ // entry that it references so we can assume they all exist in the
2971
+ // backing store already.
2972
+ // $FlowFixMe[prop-missing] FormData has forEach on it.
2973
+
2974
+ backingFormData.forEach((entry, entryKey) => {
2975
+ if (entryKey.startsWith(formPrefix)) {
2976
+ data.append(entryKey.slice(formPrefix.length), entry);
2977
+ }
2978
+ });
2979
+ return data;
2980
+ }
2981
+
2982
+ case 'I':
2983
+ {
2984
+ // $Infinity
2985
+ return Infinity;
2986
+ }
2987
+
2988
+ case '-':
2989
+ {
2990
+ // $-0 or $-Infinity
2991
+ if (value === '$-0') {
2992
+ return -0;
2993
+ } else {
2994
+ return -Infinity;
2995
+ }
2996
+ }
2997
+
2998
+ case 'N':
2999
+ {
3000
+ // $NaN
3001
+ return NaN;
3002
+ }
3003
+
3004
+ case 'u':
3005
+ {
3006
+ // matches "$undefined"
3007
+ // Special encoding for `undefined` which can't be serialized as JSON otherwise.
3008
+ return undefined;
3009
+ }
3010
+
3011
+ case 'D':
3012
+ {
3013
+ // Date
3014
+ return new Date(Date.parse(value.slice(2)));
3015
+ }
3016
+
3017
+ case 'n':
3018
+ {
3019
+ // BigInt
3020
+ return BigInt(value.slice(2));
3021
+ }
3022
+
3023
+ default:
3024
+ {
3025
+ // We assume that anything else is a reference ID.
3026
+ const id = parseInt(value.slice(1), 16);
3027
+ const chunk = getChunk(response, id);
3028
+
3029
+ switch (chunk.status) {
3030
+ case RESOLVED_MODEL:
3031
+ initializeModelChunk(chunk);
3032
+ break;
3033
+ } // The status might have changed after initialization.
3034
+
3035
+
3036
+ switch (chunk.status) {
3037
+ case INITIALIZED:
3038
+ return chunk.value;
3039
+
3040
+ case PENDING:
3041
+ case BLOCKED:
3042
+ const parentChunk = initializingChunk;
3043
+ chunk.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
3044
+ return null;
3045
+
3046
+ default:
3047
+ throw chunk.reason;
3048
+ }
3049
+ }
3050
+ }
3051
+ }
3052
+
3053
+ return value;
3054
+ }
3055
+
3056
+ function createResponse(bundlerConfig, formFieldPrefix) {
3057
+ let backingFormData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new FormData();
3058
+ const chunks = new Map();
3059
+ const response = {
3060
+ _bundlerConfig: bundlerConfig,
3061
+ _prefix: formFieldPrefix,
3062
+ _formData: backingFormData,
3063
+ _chunks: chunks,
3064
+ _fromJSON: function (key, value) {
3065
+ if (typeof value === 'string') {
3066
+ // We can't use .bind here because we need the "this" value.
3067
+ return parseModelString(response, this, key, value);
3068
+ }
3069
+
3070
+ return value;
3071
+ }
3072
+ };
3073
+ return response;
3074
+ }
3075
+ function close(response) {
3076
+ // In case there are any remaining unresolved chunks, they won't
3077
+ // be resolved now. So we need to issue an error to those.
3078
+ // Ideally we should be able to early bail out if we kept a
3079
+ // ref count of pending chunks.
3080
+ reportGlobalError(response, new Error('Connection closed.'));
3081
+ }
3082
+
3083
+ function bindArgs(fn, args) {
3084
+ return fn.bind.apply(fn, [null].concat(args));
3085
+ }
3086
+
3087
+ function loadServerReference(bundlerConfig, id, bound) {
3088
+ const serverReference = resolveServerReference(bundlerConfig, id); // We expect most servers to not really need this because you'd just have all
3089
+ // the relevant modules already loaded but it allows for lazy loading of code
3090
+ // if needed.
3091
+
3092
+ const preloadPromise = preloadModule(serverReference);
3093
+
3094
+ if (bound) {
3095
+ return Promise.all([bound, preloadPromise]).then((_ref) => {
3096
+ let args = _ref[0];
3097
+ return bindArgs(requireModule(serverReference), args);
3098
+ });
3099
+ } else if (preloadPromise) {
3100
+ return Promise.resolve(preloadPromise).then(() => requireModule(serverReference));
3101
+ } else {
3102
+ // Synchronously available
3103
+ return Promise.resolve(requireModule(serverReference));
3104
+ }
3105
+ }
3106
+
3107
+ function decodeBoundActionMetaData(body, serverManifest, formFieldPrefix) {
3108
+ // The data for this reference is encoded in multiple fields under this prefix.
3109
+ const actionResponse = createResponse(serverManifest, formFieldPrefix, body);
3110
+ close(actionResponse);
3111
+ const refPromise = getRoot(actionResponse); // Force it to initialize
3112
+ // $FlowFixMe
3113
+
3114
+ refPromise.then(() => {});
3115
+
3116
+ if (refPromise.status !== 'fulfilled') {
3117
+ // $FlowFixMe
3118
+ throw refPromise.reason;
3119
+ }
3120
+
3121
+ return refPromise.value;
3122
+ }
3123
+
3124
+ function decodeAction(body, serverManifest) {
3125
+ // We're going to create a new formData object that holds all the fields except
3126
+ // the implementation details of the action data.
3127
+ const formData = new FormData();
3128
+ let action = null; // $FlowFixMe[prop-missing]
3129
+
3130
+ body.forEach((value, key) => {
3131
+ if (!key.startsWith('$ACTION_')) {
3132
+ formData.append(key, value);
3133
+ return;
3134
+ } // Later actions may override earlier actions if a button is used to override the default
3135
+ // form action.
3136
+
3137
+
3138
+ if (key.startsWith('$ACTION_REF_')) {
3139
+ const formFieldPrefix = '$ACTION_' + key.slice(12) + ':';
3140
+ const metaData = decodeBoundActionMetaData(body, serverManifest, formFieldPrefix);
3141
+ action = loadServerReference(serverManifest, metaData.id, metaData.bound);
3142
+ return;
3143
+ }
3144
+
3145
+ if (key.startsWith('$ACTION_ID_')) {
3146
+ const id = key.slice(11);
3147
+ action = loadServerReference(serverManifest, id, null);
3148
+ return;
3149
+ }
3150
+ });
3151
+
3152
+ if (action === null) {
3153
+ return null;
3154
+ } // Return the action with the remaining FormData bound to the first argument.
3155
+
3156
+
3157
+ return action.then(fn => fn.bind(null, formData));
3158
+ }
3159
+ function decodeFormState(actionResult, body, serverManifest) {
3160
+ const keyPath = body.get('$ACTION_KEY');
3161
+
3162
+ if (typeof keyPath !== 'string') {
3163
+ // This form submission did not include any form state.
3164
+ return Promise.resolve(null);
3165
+ } // Search through the form data object to get the reference id and the number
3166
+ // of bound arguments. This repeats some of the work done in decodeAction.
3167
+
3168
+
3169
+ let metaData = null; // $FlowFixMe[prop-missing]
3170
+
3171
+ body.forEach((value, key) => {
3172
+ if (key.startsWith('$ACTION_REF_')) {
3173
+ const formFieldPrefix = '$ACTION_' + key.slice(12) + ':';
3174
+ metaData = decodeBoundActionMetaData(body, serverManifest, formFieldPrefix);
3175
+ } // We don't check for the simple $ACTION_ID_ case because form state actions
3176
+ // are always bound to the state argument.
3177
+
3178
+ });
3179
+
3180
+ if (metaData === null) {
3181
+ // Should be unreachable.
3182
+ return Promise.resolve(null);
3183
+ }
3184
+
3185
+ const referenceId = metaData.id;
3186
+ return Promise.resolve(metaData.bound).then(bound => {
3187
+ if (bound === null) {
3188
+ // Should be unreachable because form state actions are always bound to the
3189
+ // state argument.
3190
+ return null;
3191
+ } // The form action dispatch method is always bound to the initial state.
3192
+ // But when comparing signatures, we compare to the original unbound action.
3193
+ // Subtract one from the arity to account for this.
3194
+
3195
+
3196
+ const boundArity = bound.length - 1;
3197
+ return [actionResult, keyPath, referenceId, boundArity];
3198
+ });
3199
+ }
3200
+
3201
+ function renderToReadableStream(model, webpackMap, options) {
3202
+ const request = createRequest(model, webpackMap, options ? options.onError : undefined, options ? options.identifierPrefix : undefined, options ? options.onPostpone : undefined);
3203
+
3204
+ if (options && options.signal) {
3205
+ const signal = options.signal;
3206
+
3207
+ if (signal.aborted) {
3208
+ abort(request, signal.reason);
3209
+ } else {
3210
+ const listener = () => {
3211
+ abort(request, signal.reason);
3212
+ signal.removeEventListener('abort', listener);
3213
+ };
3214
+
3215
+ signal.addEventListener('abort', listener);
3216
+ }
3217
+ }
3218
+
3219
+ const stream = new ReadableStream({
3220
+ type: 'bytes',
3221
+ start: controller => {
3222
+ startWork(request);
3223
+ },
3224
+ pull: controller => {
3225
+ startFlowing(request, controller);
3226
+ },
3227
+ cancel: reason => {
3228
+ stopFlowing(request);
3229
+ abort(request, reason);
3230
+ }
3231
+ }, // $FlowFixMe[prop-missing] size() methods are not allowed on byte streams.
3232
+ {
3233
+ highWaterMark: 0
3234
+ });
3235
+ return stream;
3236
+ }
3237
+
3238
+ function decodeReply(body, webpackMap) {
3239
+ if (typeof body === 'string') {
3240
+ const form = new FormData();
3241
+ form.append('0', body);
3242
+ body = form;
3243
+ }
3244
+
3245
+ const response = createResponse(webpackMap, '', body);
3246
+ const root = getRoot(response);
3247
+ close(response);
3248
+ return root;
3249
+ }
3250
+
3251
+ exports.createClientModuleProxy = createClientModuleProxy;
3252
+ exports.decodeAction = decodeAction;
3253
+ exports.decodeFormState = decodeFormState;
3254
+ exports.decodeReply = decodeReply;
3255
+ exports.registerClientReference = registerClientReference;
3256
+ exports.registerServerReference = registerServerReference;
3257
+ exports.renderToReadableStream = renderToReadableStream;