react-server-dom-webpack 19.0.0-canary-657428a9e-20240416 → 19.0.0-canary-33a32441e9-20240418

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