react-server-dom-webpack 18.3.0-next-5dd90c562-20230502 → 19.0.0-canary-2b036d3f1-20240327
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/react-server-dom-webpack-client.browser.development.js +1768 -1188
- package/cjs/react-server-dom-webpack-client.browser.production.js +1739 -0
- package/cjs/react-server-dom-webpack-client.browser.production.min.js +40 -34
- package/cjs/react-server-dom-webpack-client.browser.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-client.edge.development.js +1755 -221
- package/cjs/react-server-dom-webpack-client.edge.production.js +1986 -0
- package/cjs/react-server-dom-webpack-client.edge.production.min.js +45 -28
- package/cjs/react-server-dom-webpack-client.edge.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-client.node.development.js +1743 -239
- package/cjs/react-server-dom-webpack-client.node.production.js +1942 -0
- package/cjs/react-server-dom-webpack-client.node.production.min.js +44 -28
- package/cjs/react-server-dom-webpack-client.node.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +1702 -194
- package/cjs/react-server-dom-webpack-client.node.unbundled.production.js +1895 -0
- package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +43 -26
- package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-node-register.js +12 -18
- package/cjs/react-server-dom-webpack-node-register.js.map +1 -0
- package/cjs/react-server-dom-webpack-plugin.js +22 -19
- package/cjs/react-server-dom-webpack-plugin.js.map +1 -0
- package/cjs/react-server-dom-webpack-server.browser.development.js +1588 -808
- package/cjs/react-server-dom-webpack-server.browser.production.js +3257 -0
- package/cjs/react-server-dom-webpack-server.browser.production.min.js +80 -62
- package/cjs/react-server-dom-webpack-server.browser.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-server.edge.development.js +1583 -811
- package/cjs/react-server-dom-webpack-server.edge.production.js +3261 -0
- package/cjs/react-server-dom-webpack-server.edge.production.min.js +82 -62
- package/cjs/react-server-dom-webpack-server.edge.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-server.node.development.js +1575 -805
- package/cjs/react-server-dom-webpack-server.node.production.js +3464 -0
- package/cjs/react-server-dom-webpack-server.node.production.min.js +85 -67
- package/cjs/react-server-dom-webpack-server.node.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1526 -761
- package/cjs/react-server-dom-webpack-server.node.unbundled.production.js +3391 -0
- package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +82 -65
- package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js.map +1 -0
- package/esm/react-server-dom-webpack-node-loader.production.min.js +19 -12
- package/package.json +7 -13
- package/umd/react-server-dom-webpack-client.browser.development.js +1770 -1189
- package/umd/react-server-dom-webpack-client.browser.production.min.js +26 -20
- package/umd/react-server-dom-webpack-server.browser.development.js +1589 -808
- package/umd/react-server-dom-webpack-server.browser.production.min.js +55 -42
@@ -17,6 +17,9 @@ if (process.env.NODE_ENV !== "production") {
|
|
17
17
|
var ReactDOM = require('react-dom');
|
18
18
|
var React = require('react');
|
19
19
|
|
20
|
+
// -----------------------------------------------------------------------------
|
21
|
+
var enableBinaryFlight = false;
|
22
|
+
|
20
23
|
function createStringDecoder() {
|
21
24
|
return new TextDecoder();
|
22
25
|
}
|
@@ -30,15 +33,77 @@ function readFinalStringChunk(decoder, buffer) {
|
|
30
33
|
return decoder.decode(buffer);
|
31
34
|
}
|
32
35
|
|
33
|
-
|
34
|
-
|
36
|
+
// This flips color using ANSI, then sets a color styling, then resets.
|
37
|
+
var badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c '; // Same badge styling as DevTools.
|
38
|
+
|
39
|
+
var badgeStyle = // We use a fixed background if light-dark is not supported, otherwise
|
40
|
+
// we use a transparent background.
|
41
|
+
'background: #e6e6e6;' + 'background: light-dark(rgba(0,0,0,0.1), rgba(255,255,255,0.25));' + 'color: #000000;' + 'color: light-dark(#000000, #ffffff);' + 'border-radius: 2px';
|
42
|
+
var resetStyle = '';
|
43
|
+
var pad = ' ';
|
44
|
+
function printToConsole(methodName, args, badgeName) {
|
45
|
+
var offset = 0;
|
46
|
+
|
47
|
+
switch (methodName) {
|
48
|
+
case 'dir':
|
49
|
+
case 'dirxml':
|
50
|
+
case 'groupEnd':
|
51
|
+
case 'table':
|
52
|
+
{
|
53
|
+
// These methods cannot be colorized because they don't take a formatting string.
|
54
|
+
// eslint-disable-next-line react-internal/no-production-logging
|
55
|
+
console[methodName].apply(console, args);
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
|
59
|
+
case 'assert':
|
60
|
+
{
|
61
|
+
// assert takes formatting options as the second argument.
|
62
|
+
offset = 1;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
var newArgs = args.slice(0);
|
67
|
+
|
68
|
+
if (typeof newArgs[offset] === 'string') {
|
69
|
+
newArgs.splice(offset, 1, badgeFormat + newArgs[offset], badgeStyle, pad + badgeName + pad, resetStyle);
|
70
|
+
} else {
|
71
|
+
newArgs.splice(offset, 0, badgeFormat, badgeStyle, pad + badgeName + pad, resetStyle);
|
72
|
+
} // eslint-disable-next-line react-internal/no-production-logging
|
73
|
+
|
74
|
+
|
75
|
+
console[methodName].apply(console, newArgs);
|
76
|
+
return;
|
35
77
|
}
|
36
78
|
|
37
|
-
//
|
79
|
+
// This is the parsed shape of the wire format which is why it is
|
80
|
+
// condensed to only the essentialy information
|
81
|
+
var ID = 0;
|
82
|
+
var CHUNKS = 1;
|
83
|
+
var NAME = 2; // export const ASYNC = 3;
|
84
|
+
// This logic is correct because currently only include the 4th tuple member
|
85
|
+
// when the module is async. If that changes we will need to actually assert
|
86
|
+
// the value is true. We don't index into the 4th slot because flow does not
|
87
|
+
// like the potential out of bounds access
|
88
|
+
|
89
|
+
function isAsyncImport(metadata) {
|
90
|
+
return metadata.length === 4;
|
91
|
+
}
|
92
|
+
|
93
|
+
// The reason this function needs to defined here in this file instead of just
|
94
|
+
// being exported directly from the WebpackDestination... file is because the
|
95
|
+
// ClientReferenceMetadata is opaque and we can't unwrap it there.
|
96
|
+
// This should get inlined and we could also just implement an unwrapping function
|
97
|
+
// though that risks it getting used in places it shouldn't be. This is unfortunate
|
98
|
+
// but currently it seems to be the best option we have.
|
99
|
+
|
100
|
+
function prepareDestinationForModule(moduleLoading, nonce, metadata) {
|
101
|
+
prepareDestinationWithChunks(moduleLoading, metadata[CHUNKS], nonce);
|
102
|
+
}
|
38
103
|
function resolveClientReference(bundlerConfig, metadata) {
|
39
104
|
if (bundlerConfig) {
|
40
|
-
var moduleExports = bundlerConfig[metadata
|
41
|
-
var resolvedModuleData = moduleExports[metadata
|
105
|
+
var moduleExports = bundlerConfig[metadata[ID]];
|
106
|
+
var resolvedModuleData = moduleExports[metadata[NAME]];
|
42
107
|
var name;
|
43
108
|
|
44
109
|
if (resolvedModuleData) {
|
@@ -49,18 +114,19 @@ function resolveClientReference(bundlerConfig, metadata) {
|
|
49
114
|
resolvedModuleData = moduleExports['*'];
|
50
115
|
|
51
116
|
if (!resolvedModuleData) {
|
52
|
-
throw new Error('Could not find the module "' + metadata
|
117
|
+
throw new Error('Could not find the module "' + metadata[ID] + '" in the React SSR Manifest. ' + 'This is probably a bug in the React Server Components bundler.');
|
53
118
|
}
|
54
119
|
|
55
|
-
name = metadata
|
120
|
+
name = metadata[NAME];
|
56
121
|
}
|
57
122
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
123
|
+
if (isAsyncImport(metadata)) {
|
124
|
+
return [resolvedModuleData.id, resolvedModuleData.chunks, name, 1
|
125
|
+
/* async */
|
126
|
+
];
|
127
|
+
} else {
|
128
|
+
return [resolvedModuleData.id, resolvedModuleData.chunks, name];
|
129
|
+
}
|
64
130
|
}
|
65
131
|
|
66
132
|
return metadata;
|
@@ -70,7 +136,31 @@ function resolveClientReference(bundlerConfig, metadata) {
|
|
70
136
|
// replicate it in user space. null means that it has already loaded.
|
71
137
|
|
72
138
|
var chunkCache = new Map();
|
73
|
-
|
139
|
+
|
140
|
+
function requireAsyncModule(id) {
|
141
|
+
// We've already loaded all the chunks. We can require the module.
|
142
|
+
var promise = __webpack_require__(id);
|
143
|
+
|
144
|
+
if (typeof promise.then !== 'function') {
|
145
|
+
// This wasn't a promise after all.
|
146
|
+
return null;
|
147
|
+
} else if (promise.status === 'fulfilled') {
|
148
|
+
// This module was already resolved earlier.
|
149
|
+
return null;
|
150
|
+
} else {
|
151
|
+
// Instrument the Promise to stash the result.
|
152
|
+
promise.then(function (value) {
|
153
|
+
var fulfilledThenable = promise;
|
154
|
+
fulfilledThenable.status = 'fulfilled';
|
155
|
+
fulfilledThenable.value = value;
|
156
|
+
}, function (reason) {
|
157
|
+
var rejectedThenable = promise;
|
158
|
+
rejectedThenable.status = 'rejected';
|
159
|
+
rejectedThenable.reason = reason;
|
160
|
+
});
|
161
|
+
return promise;
|
162
|
+
}
|
163
|
+
}
|
74
164
|
|
75
165
|
function ignoreReject() {// We rely on rejected promises to be handled by another listener.
|
76
166
|
} // Start preloading the modules since we might need them soon.
|
@@ -78,16 +168,17 @@ function ignoreReject() {// We rely on rejected promises to be handled by anothe
|
|
78
168
|
|
79
169
|
|
80
170
|
function preloadModule(metadata) {
|
81
|
-
var chunks = metadata
|
171
|
+
var chunks = metadata[CHUNKS];
|
82
172
|
var promises = [];
|
173
|
+
var i = 0;
|
83
174
|
|
84
|
-
|
85
|
-
var chunkId = chunks[i];
|
175
|
+
while (i < chunks.length) {
|
176
|
+
var chunkId = chunks[i++];
|
177
|
+
chunks[i++];
|
86
178
|
var entry = chunkCache.get(chunkId);
|
87
179
|
|
88
180
|
if (entry === undefined) {
|
89
|
-
var thenable =
|
90
|
-
|
181
|
+
var thenable = loadChunk(chunkId);
|
91
182
|
promises.push(thenable); // $FlowFixMe[method-unbinding]
|
92
183
|
|
93
184
|
var resolve = chunkCache.set.bind(chunkCache, chunkId, null);
|
@@ -98,30 +189,13 @@ function preloadModule(metadata) {
|
|
98
189
|
}
|
99
190
|
}
|
100
191
|
|
101
|
-
if (metadata
|
102
|
-
|
103
|
-
|
104
|
-
if (existingPromise) {
|
105
|
-
if (existingPromise.status === 'fulfilled') {
|
106
|
-
return null;
|
107
|
-
}
|
108
|
-
|
109
|
-
return existingPromise;
|
192
|
+
if (isAsyncImport(metadata)) {
|
193
|
+
if (promises.length === 0) {
|
194
|
+
return requireAsyncModule(metadata[ID]);
|
110
195
|
} else {
|
111
|
-
|
112
|
-
return
|
113
|
-
});
|
114
|
-
modulePromise.then(function (value) {
|
115
|
-
var fulfilledThenable = modulePromise;
|
116
|
-
fulfilledThenable.status = 'fulfilled';
|
117
|
-
fulfilledThenable.value = value;
|
118
|
-
}, function (reason) {
|
119
|
-
var rejectedThenable = modulePromise;
|
120
|
-
rejectedThenable.status = 'rejected';
|
121
|
-
rejectedThenable.reason = reason;
|
196
|
+
return Promise.all(promises).then(function () {
|
197
|
+
return requireAsyncModule(metadata[ID]);
|
122
198
|
});
|
123
|
-
asyncModuleCache.set(metadata.id, modulePromise);
|
124
|
-
return modulePromise;
|
125
199
|
}
|
126
200
|
} else if (promises.length > 0) {
|
127
201
|
return Promise.all(promises);
|
@@ -132,112 +206,1261 @@ function preloadModule(metadata) {
|
|
132
206
|
// Increase priority if necessary.
|
133
207
|
|
134
208
|
function requireModule(metadata) {
|
135
|
-
var moduleExports;
|
209
|
+
var moduleExports = __webpack_require__(metadata[ID]);
|
136
210
|
|
137
|
-
if (metadata
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
if (promise.status === 'fulfilled') {
|
143
|
-
moduleExports = promise.value;
|
211
|
+
if (isAsyncImport(metadata)) {
|
212
|
+
if (typeof moduleExports.then !== 'function') ; else if (moduleExports.status === 'fulfilled') {
|
213
|
+
// This Promise should've been instrumented by preloadModule.
|
214
|
+
moduleExports = moduleExports.value;
|
144
215
|
} else {
|
145
|
-
throw
|
216
|
+
throw moduleExports.reason;
|
146
217
|
}
|
147
|
-
} else {
|
148
|
-
moduleExports = __webpack_require__(metadata.id);
|
149
218
|
}
|
150
219
|
|
151
|
-
if (metadata
|
220
|
+
if (metadata[NAME] === '*') {
|
152
221
|
// This is a placeholder value that represents that the caller imported this
|
153
222
|
// as a CommonJS module as is.
|
154
223
|
return moduleExports;
|
155
224
|
}
|
156
225
|
|
157
|
-
if (metadata
|
158
|
-
// This is a placeholder value that represents that the caller accessed the
|
159
|
-
// default property of this if it was an ESM interop module.
|
160
|
-
return moduleExports.__esModule ? moduleExports.default : moduleExports;
|
226
|
+
if (metadata[NAME] === '') {
|
227
|
+
// This is a placeholder value that represents that the caller accessed the
|
228
|
+
// default property of this if it was an ESM interop module.
|
229
|
+
return moduleExports.__esModule ? moduleExports.default : moduleExports;
|
230
|
+
}
|
231
|
+
|
232
|
+
return moduleExports[metadata[NAME]];
|
233
|
+
}
|
234
|
+
|
235
|
+
function loadChunk(chunkId, filename) {
|
236
|
+
return __webpack_chunk_load__(chunkId);
|
237
|
+
}
|
238
|
+
|
239
|
+
function prepareDestinationWithChunks(moduleLoading, // Chunks are double-indexed [..., idx, filenamex, idy, filenamey, ...]
|
240
|
+
chunks, nonce) {
|
241
|
+
if (moduleLoading !== null) {
|
242
|
+
for (var i = 1; i < chunks.length; i += 2) {
|
243
|
+
preinitScriptForSSR(moduleLoading.prefix + chunks[i], nonce, moduleLoading.crossOrigin);
|
244
|
+
}
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
var ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
249
|
+
|
250
|
+
function getCrossOriginString(input) {
|
251
|
+
if (typeof input === 'string') {
|
252
|
+
return input === 'use-credentials' ? input : '';
|
253
|
+
}
|
254
|
+
|
255
|
+
return undefined;
|
256
|
+
}
|
257
|
+
|
258
|
+
// This client file is in the shared folder because it applies to both SSR and browser contexts.
|
259
|
+
var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
|
260
|
+
function dispatchHint(code, model) {
|
261
|
+
var dispatcher = ReactDOMCurrentDispatcher.current;
|
262
|
+
|
263
|
+
switch (code) {
|
264
|
+
case 'D':
|
265
|
+
{
|
266
|
+
var refined = refineModel(code, model);
|
267
|
+
var href = refined;
|
268
|
+
dispatcher.prefetchDNS(href);
|
269
|
+
return;
|
270
|
+
}
|
271
|
+
|
272
|
+
case 'C':
|
273
|
+
{
|
274
|
+
var _refined = refineModel(code, model);
|
275
|
+
|
276
|
+
if (typeof _refined === 'string') {
|
277
|
+
var _href = _refined;
|
278
|
+
dispatcher.preconnect(_href);
|
279
|
+
} else {
|
280
|
+
var _href2 = _refined[0];
|
281
|
+
var crossOrigin = _refined[1];
|
282
|
+
dispatcher.preconnect(_href2, crossOrigin);
|
283
|
+
}
|
284
|
+
|
285
|
+
return;
|
286
|
+
}
|
287
|
+
|
288
|
+
case 'L':
|
289
|
+
{
|
290
|
+
var _refined2 = refineModel(code, model);
|
291
|
+
|
292
|
+
var _href3 = _refined2[0];
|
293
|
+
var as = _refined2[1];
|
294
|
+
|
295
|
+
if (_refined2.length === 3) {
|
296
|
+
var options = _refined2[2];
|
297
|
+
dispatcher.preload(_href3, as, options);
|
298
|
+
} else {
|
299
|
+
dispatcher.preload(_href3, as);
|
300
|
+
}
|
301
|
+
|
302
|
+
return;
|
303
|
+
}
|
304
|
+
|
305
|
+
case 'm':
|
306
|
+
{
|
307
|
+
var _refined3 = refineModel(code, model);
|
308
|
+
|
309
|
+
if (typeof _refined3 === 'string') {
|
310
|
+
var _href4 = _refined3;
|
311
|
+
dispatcher.preloadModule(_href4);
|
312
|
+
} else {
|
313
|
+
var _href5 = _refined3[0];
|
314
|
+
var _options = _refined3[1];
|
315
|
+
dispatcher.preloadModule(_href5, _options);
|
316
|
+
}
|
317
|
+
|
318
|
+
return;
|
319
|
+
}
|
320
|
+
|
321
|
+
case 'S':
|
322
|
+
{
|
323
|
+
var _refined4 = refineModel(code, model);
|
324
|
+
|
325
|
+
if (typeof _refined4 === 'string') {
|
326
|
+
var _href6 = _refined4;
|
327
|
+
dispatcher.preinitStyle(_href6);
|
328
|
+
} else {
|
329
|
+
var _href7 = _refined4[0];
|
330
|
+
var precedence = _refined4[1] === 0 ? undefined : _refined4[1];
|
331
|
+
|
332
|
+
var _options2 = _refined4.length === 3 ? _refined4[2] : undefined;
|
333
|
+
|
334
|
+
dispatcher.preinitStyle(_href7, precedence, _options2);
|
335
|
+
}
|
336
|
+
|
337
|
+
return;
|
338
|
+
}
|
339
|
+
|
340
|
+
case 'X':
|
341
|
+
{
|
342
|
+
var _refined5 = refineModel(code, model);
|
343
|
+
|
344
|
+
if (typeof _refined5 === 'string') {
|
345
|
+
var _href8 = _refined5;
|
346
|
+
dispatcher.preinitScript(_href8);
|
347
|
+
} else {
|
348
|
+
var _href9 = _refined5[0];
|
349
|
+
var _options3 = _refined5[1];
|
350
|
+
dispatcher.preinitScript(_href9, _options3);
|
351
|
+
}
|
352
|
+
|
353
|
+
return;
|
354
|
+
}
|
355
|
+
|
356
|
+
case 'M':
|
357
|
+
{
|
358
|
+
var _refined6 = refineModel(code, model);
|
359
|
+
|
360
|
+
if (typeof _refined6 === 'string') {
|
361
|
+
var _href10 = _refined6;
|
362
|
+
dispatcher.preinitModuleScript(_href10);
|
363
|
+
} else {
|
364
|
+
var _href11 = _refined6[0];
|
365
|
+
var _options4 = _refined6[1];
|
366
|
+
dispatcher.preinitModuleScript(_href11, _options4);
|
367
|
+
}
|
368
|
+
|
369
|
+
return;
|
370
|
+
}
|
371
|
+
}
|
372
|
+
} // Flow is having trouble refining the HintModels so we help it a bit.
|
373
|
+
// This should be compiled out in the production build.
|
374
|
+
|
375
|
+
function refineModel(code, model) {
|
376
|
+
return model;
|
377
|
+
}
|
378
|
+
function preinitScriptForSSR(href, nonce, crossOrigin) {
|
379
|
+
var dispatcher = ReactDOMCurrentDispatcher.current;
|
380
|
+
|
381
|
+
if (dispatcher) {
|
382
|
+
dispatcher.preinitScript(href, {
|
383
|
+
crossOrigin: getCrossOriginString(crossOrigin),
|
384
|
+
nonce: nonce
|
385
|
+
});
|
386
|
+
}
|
387
|
+
}
|
388
|
+
|
389
|
+
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
390
|
+
|
391
|
+
function error(format) {
|
392
|
+
{
|
393
|
+
{
|
394
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
395
|
+
args[_key2 - 1] = arguments[_key2];
|
396
|
+
}
|
397
|
+
|
398
|
+
printWarning('error', format, args);
|
399
|
+
}
|
400
|
+
}
|
401
|
+
}
|
402
|
+
|
403
|
+
function printWarning(level, format, args) {
|
404
|
+
// When changing this logic, you might want to also
|
405
|
+
// update consoleWithStackDev.www.js as well.
|
406
|
+
{
|
407
|
+
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
408
|
+
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
409
|
+
|
410
|
+
if (stack !== '') {
|
411
|
+
format += '%s';
|
412
|
+
args = args.concat([stack]);
|
413
|
+
} // eslint-disable-next-line react-internal/safe-string-coercion
|
414
|
+
|
415
|
+
|
416
|
+
var argsWithFormat = args.map(function (item) {
|
417
|
+
return String(item);
|
418
|
+
}); // Careful: RN currently depends on this prefix
|
419
|
+
|
420
|
+
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
421
|
+
// breaks IE9: https://github.com/facebook/react/issues/13610
|
422
|
+
// eslint-disable-next-line react-internal/no-production-logging
|
423
|
+
|
424
|
+
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
// ATTENTION
|
429
|
+
// When adding new symbols to this file,
|
430
|
+
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
|
431
|
+
// The Symbol used to tag the ReactElement-like types.
|
432
|
+
var REACT_ELEMENT_TYPE = Symbol.for('react.element');
|
433
|
+
var REACT_PROVIDER_TYPE = Symbol.for('react.provider'); // TODO: Delete with enableRenderableContext
|
434
|
+
var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
|
435
|
+
var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
|
436
|
+
var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
|
437
|
+
var REACT_MEMO_TYPE = Symbol.for('react.memo');
|
438
|
+
var REACT_LAZY_TYPE = Symbol.for('react.lazy');
|
439
|
+
var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
|
440
|
+
var FAUX_ITERATOR_SYMBOL = '@@iterator';
|
441
|
+
function getIteratorFn(maybeIterable) {
|
442
|
+
if (maybeIterable === null || typeof maybeIterable !== 'object') {
|
443
|
+
return null;
|
444
|
+
}
|
445
|
+
|
446
|
+
var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
|
447
|
+
|
448
|
+
if (typeof maybeIterator === 'function') {
|
449
|
+
return maybeIterator;
|
450
|
+
}
|
451
|
+
|
452
|
+
return null;
|
453
|
+
}
|
454
|
+
|
455
|
+
var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
|
456
|
+
|
457
|
+
function isArray(a) {
|
458
|
+
return isArrayImpl(a);
|
459
|
+
}
|
460
|
+
|
461
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
462
|
+
|
463
|
+
// in case they error.
|
464
|
+
|
465
|
+
var jsxPropsParents = new WeakMap();
|
466
|
+
var jsxChildrenParents = new WeakMap();
|
467
|
+
|
468
|
+
function isObjectPrototype(object) {
|
469
|
+
if (!object) {
|
470
|
+
return false;
|
471
|
+
}
|
472
|
+
|
473
|
+
var ObjectPrototype = Object.prototype;
|
474
|
+
|
475
|
+
if (object === ObjectPrototype) {
|
476
|
+
return true;
|
477
|
+
} // It might be an object from a different Realm which is
|
478
|
+
// still just a plain simple object.
|
479
|
+
|
480
|
+
|
481
|
+
if (getPrototypeOf(object)) {
|
482
|
+
return false;
|
483
|
+
}
|
484
|
+
|
485
|
+
var names = Object.getOwnPropertyNames(object);
|
486
|
+
|
487
|
+
for (var i = 0; i < names.length; i++) {
|
488
|
+
if (!(names[i] in ObjectPrototype)) {
|
489
|
+
return false;
|
490
|
+
}
|
491
|
+
}
|
492
|
+
|
493
|
+
return true;
|
494
|
+
}
|
495
|
+
|
496
|
+
function isSimpleObject(object) {
|
497
|
+
if (!isObjectPrototype(getPrototypeOf(object))) {
|
498
|
+
return false;
|
499
|
+
}
|
500
|
+
|
501
|
+
var names = Object.getOwnPropertyNames(object);
|
502
|
+
|
503
|
+
for (var i = 0; i < names.length; i++) {
|
504
|
+
var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
|
505
|
+
|
506
|
+
if (!descriptor) {
|
507
|
+
return false;
|
508
|
+
}
|
509
|
+
|
510
|
+
if (!descriptor.enumerable) {
|
511
|
+
if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
|
512
|
+
// React adds key and ref getters to props objects to issue warnings.
|
513
|
+
// Those getters will not be transferred to the client, but that's ok,
|
514
|
+
// so we'll special case them.
|
515
|
+
continue;
|
516
|
+
}
|
517
|
+
|
518
|
+
return false;
|
519
|
+
}
|
520
|
+
}
|
521
|
+
|
522
|
+
return true;
|
523
|
+
}
|
524
|
+
function objectName(object) {
|
525
|
+
// $FlowFixMe[method-unbinding]
|
526
|
+
var name = Object.prototype.toString.call(object);
|
527
|
+
return name.replace(/^\[object (.*)\]$/, function (m, p0) {
|
528
|
+
return p0;
|
529
|
+
});
|
530
|
+
}
|
531
|
+
|
532
|
+
function describeKeyForErrorMessage(key) {
|
533
|
+
var encodedKey = JSON.stringify(key);
|
534
|
+
return '"' + key + '"' === encodedKey ? key : encodedKey;
|
535
|
+
}
|
536
|
+
|
537
|
+
function describeValueForErrorMessage(value) {
|
538
|
+
switch (typeof value) {
|
539
|
+
case 'string':
|
540
|
+
{
|
541
|
+
return JSON.stringify(value.length <= 10 ? value : value.slice(0, 10) + '...');
|
542
|
+
}
|
543
|
+
|
544
|
+
case 'object':
|
545
|
+
{
|
546
|
+
if (isArray(value)) {
|
547
|
+
return '[...]';
|
548
|
+
}
|
549
|
+
|
550
|
+
if (value !== null && value.$$typeof === CLIENT_REFERENCE_TAG) {
|
551
|
+
return describeClientReference();
|
552
|
+
}
|
553
|
+
|
554
|
+
var name = objectName(value);
|
555
|
+
|
556
|
+
if (name === 'Object') {
|
557
|
+
return '{...}';
|
558
|
+
}
|
559
|
+
|
560
|
+
return name;
|
561
|
+
}
|
562
|
+
|
563
|
+
case 'function':
|
564
|
+
{
|
565
|
+
if (value.$$typeof === CLIENT_REFERENCE_TAG) {
|
566
|
+
return describeClientReference();
|
567
|
+
}
|
568
|
+
|
569
|
+
var _name = value.displayName || value.name;
|
570
|
+
|
571
|
+
return _name ? 'function ' + _name : 'function';
|
572
|
+
}
|
573
|
+
|
574
|
+
default:
|
575
|
+
// eslint-disable-next-line react-internal/safe-string-coercion
|
576
|
+
return String(value);
|
577
|
+
}
|
578
|
+
}
|
579
|
+
|
580
|
+
function describeElementType(type) {
|
581
|
+
if (typeof type === 'string') {
|
582
|
+
return type;
|
583
|
+
}
|
584
|
+
|
585
|
+
switch (type) {
|
586
|
+
case REACT_SUSPENSE_TYPE:
|
587
|
+
return 'Suspense';
|
588
|
+
|
589
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
590
|
+
return 'SuspenseList';
|
591
|
+
}
|
592
|
+
|
593
|
+
if (typeof type === 'object') {
|
594
|
+
switch (type.$$typeof) {
|
595
|
+
case REACT_FORWARD_REF_TYPE:
|
596
|
+
return describeElementType(type.render);
|
597
|
+
|
598
|
+
case REACT_MEMO_TYPE:
|
599
|
+
return describeElementType(type.type);
|
600
|
+
|
601
|
+
case REACT_LAZY_TYPE:
|
602
|
+
{
|
603
|
+
var lazyComponent = type;
|
604
|
+
var payload = lazyComponent._payload;
|
605
|
+
var init = lazyComponent._init;
|
606
|
+
|
607
|
+
try {
|
608
|
+
// Lazy may contain any component type so we recursively resolve it.
|
609
|
+
return describeElementType(init(payload));
|
610
|
+
} catch (x) {}
|
611
|
+
}
|
612
|
+
}
|
613
|
+
}
|
614
|
+
|
615
|
+
return '';
|
616
|
+
}
|
617
|
+
|
618
|
+
var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
|
619
|
+
|
620
|
+
function describeClientReference(ref) {
|
621
|
+
return 'client';
|
622
|
+
}
|
623
|
+
|
624
|
+
function describeObjectForErrorMessage(objectOrArray, expandedName) {
|
625
|
+
var objKind = objectName(objectOrArray);
|
626
|
+
|
627
|
+
if (objKind !== 'Object' && objKind !== 'Array') {
|
628
|
+
return objKind;
|
629
|
+
}
|
630
|
+
|
631
|
+
var str = '';
|
632
|
+
var start = -1;
|
633
|
+
var length = 0;
|
634
|
+
|
635
|
+
if (isArray(objectOrArray)) {
|
636
|
+
if (jsxChildrenParents.has(objectOrArray)) {
|
637
|
+
// Print JSX Children
|
638
|
+
var type = jsxChildrenParents.get(objectOrArray);
|
639
|
+
str = '<' + describeElementType(type) + '>';
|
640
|
+
var array = objectOrArray;
|
641
|
+
|
642
|
+
for (var i = 0; i < array.length; i++) {
|
643
|
+
var value = array[i];
|
644
|
+
var substr = void 0;
|
645
|
+
|
646
|
+
if (typeof value === 'string') {
|
647
|
+
substr = value;
|
648
|
+
} else if (typeof value === 'object' && value !== null) {
|
649
|
+
substr = '{' + describeObjectForErrorMessage(value) + '}';
|
650
|
+
} else {
|
651
|
+
substr = '{' + describeValueForErrorMessage(value) + '}';
|
652
|
+
}
|
653
|
+
|
654
|
+
if ('' + i === expandedName) {
|
655
|
+
start = str.length;
|
656
|
+
length = substr.length;
|
657
|
+
str += substr;
|
658
|
+
} else if (substr.length < 15 && str.length + substr.length < 40) {
|
659
|
+
str += substr;
|
660
|
+
} else {
|
661
|
+
str += '{...}';
|
662
|
+
}
|
663
|
+
}
|
664
|
+
|
665
|
+
str += '</' + describeElementType(type) + '>';
|
666
|
+
} else {
|
667
|
+
// Print Array
|
668
|
+
str = '[';
|
669
|
+
var _array = objectOrArray;
|
670
|
+
|
671
|
+
for (var _i = 0; _i < _array.length; _i++) {
|
672
|
+
if (_i > 0) {
|
673
|
+
str += ', ';
|
674
|
+
}
|
675
|
+
|
676
|
+
var _value = _array[_i];
|
677
|
+
|
678
|
+
var _substr = void 0;
|
679
|
+
|
680
|
+
if (typeof _value === 'object' && _value !== null) {
|
681
|
+
_substr = describeObjectForErrorMessage(_value);
|
682
|
+
} else {
|
683
|
+
_substr = describeValueForErrorMessage(_value);
|
684
|
+
}
|
685
|
+
|
686
|
+
if ('' + _i === expandedName) {
|
687
|
+
start = str.length;
|
688
|
+
length = _substr.length;
|
689
|
+
str += _substr;
|
690
|
+
} else if (_substr.length < 10 && str.length + _substr.length < 40) {
|
691
|
+
str += _substr;
|
692
|
+
} else {
|
693
|
+
str += '...';
|
694
|
+
}
|
695
|
+
}
|
696
|
+
|
697
|
+
str += ']';
|
698
|
+
}
|
699
|
+
} else {
|
700
|
+
if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
|
701
|
+
str = '<' + describeElementType(objectOrArray.type) + '/>';
|
702
|
+
} else if (objectOrArray.$$typeof === CLIENT_REFERENCE_TAG) {
|
703
|
+
return describeClientReference();
|
704
|
+
} else if (jsxPropsParents.has(objectOrArray)) {
|
705
|
+
// Print JSX
|
706
|
+
var _type = jsxPropsParents.get(objectOrArray);
|
707
|
+
|
708
|
+
str = '<' + (describeElementType(_type) || '...');
|
709
|
+
var object = objectOrArray;
|
710
|
+
var names = Object.keys(object);
|
711
|
+
|
712
|
+
for (var _i2 = 0; _i2 < names.length; _i2++) {
|
713
|
+
str += ' ';
|
714
|
+
var name = names[_i2];
|
715
|
+
str += describeKeyForErrorMessage(name) + '=';
|
716
|
+
var _value2 = object[name];
|
717
|
+
|
718
|
+
var _substr2 = void 0;
|
719
|
+
|
720
|
+
if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
|
721
|
+
_substr2 = describeObjectForErrorMessage(_value2);
|
722
|
+
} else {
|
723
|
+
_substr2 = describeValueForErrorMessage(_value2);
|
724
|
+
}
|
725
|
+
|
726
|
+
if (typeof _value2 !== 'string') {
|
727
|
+
_substr2 = '{' + _substr2 + '}';
|
728
|
+
}
|
729
|
+
|
730
|
+
if (name === expandedName) {
|
731
|
+
start = str.length;
|
732
|
+
length = _substr2.length;
|
733
|
+
str += _substr2;
|
734
|
+
} else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
|
735
|
+
str += _substr2;
|
736
|
+
} else {
|
737
|
+
str += '...';
|
738
|
+
}
|
739
|
+
}
|
740
|
+
|
741
|
+
str += '>';
|
742
|
+
} else {
|
743
|
+
// Print Object
|
744
|
+
str = '{';
|
745
|
+
var _object = objectOrArray;
|
746
|
+
|
747
|
+
var _names = Object.keys(_object);
|
748
|
+
|
749
|
+
for (var _i3 = 0; _i3 < _names.length; _i3++) {
|
750
|
+
if (_i3 > 0) {
|
751
|
+
str += ', ';
|
752
|
+
}
|
753
|
+
|
754
|
+
var _name2 = _names[_i3];
|
755
|
+
str += describeKeyForErrorMessage(_name2) + ': ';
|
756
|
+
var _value3 = _object[_name2];
|
757
|
+
|
758
|
+
var _substr3 = void 0;
|
759
|
+
|
760
|
+
if (typeof _value3 === 'object' && _value3 !== null) {
|
761
|
+
_substr3 = describeObjectForErrorMessage(_value3);
|
762
|
+
} else {
|
763
|
+
_substr3 = describeValueForErrorMessage(_value3);
|
764
|
+
}
|
765
|
+
|
766
|
+
if (_name2 === expandedName) {
|
767
|
+
start = str.length;
|
768
|
+
length = _substr3.length;
|
769
|
+
str += _substr3;
|
770
|
+
} else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
|
771
|
+
str += _substr3;
|
772
|
+
} else {
|
773
|
+
str += '...';
|
774
|
+
}
|
775
|
+
}
|
776
|
+
|
777
|
+
str += '}';
|
778
|
+
}
|
779
|
+
}
|
780
|
+
|
781
|
+
if (expandedName === undefined) {
|
782
|
+
return str;
|
783
|
+
}
|
784
|
+
|
785
|
+
if (start > -1 && length > 0) {
|
786
|
+
var highlight = ' '.repeat(start) + '^'.repeat(length);
|
787
|
+
return '\n ' + str + '\n ' + highlight;
|
788
|
+
}
|
789
|
+
|
790
|
+
return '\n ' + str;
|
791
|
+
}
|
792
|
+
|
793
|
+
function createTemporaryReferenceSet() {
|
794
|
+
return [];
|
795
|
+
}
|
796
|
+
function writeTemporaryReference(set, object) {
|
797
|
+
// We always create a new entry regardless if we've already written the same
|
798
|
+
// object. This ensures that we always generate a deterministic encoding of
|
799
|
+
// each slot in the reply for cacheability.
|
800
|
+
var newId = set.length;
|
801
|
+
set.push(object);
|
802
|
+
return newId;
|
803
|
+
}
|
804
|
+
function readTemporaryReference(set, id) {
|
805
|
+
if (id < 0 || id >= set.length) {
|
806
|
+
throw new Error("The RSC response contained a reference that doesn't exist in the temporary reference set. " + 'Always pass the matching set that was used to create the reply when parsing its response.');
|
807
|
+
}
|
808
|
+
|
809
|
+
return set[id];
|
810
|
+
}
|
811
|
+
|
812
|
+
var ObjectPrototype = Object.prototype;
|
813
|
+
var knownServerReferences = new WeakMap(); // Serializable values
|
814
|
+
// Thenable<ReactServerValue>
|
815
|
+
|
816
|
+
function serializeByValueID(id) {
|
817
|
+
return '$' + id.toString(16);
|
818
|
+
}
|
819
|
+
|
820
|
+
function serializePromiseID(id) {
|
821
|
+
return '$@' + id.toString(16);
|
822
|
+
}
|
823
|
+
|
824
|
+
function serializeServerReferenceID(id) {
|
825
|
+
return '$F' + id.toString(16);
|
826
|
+
}
|
827
|
+
|
828
|
+
function serializeTemporaryReferenceID(id) {
|
829
|
+
return '$T' + id.toString(16);
|
830
|
+
}
|
831
|
+
|
832
|
+
function serializeFormDataReference(id) {
|
833
|
+
// Why K? F is "Function". D is "Date". What else?
|
834
|
+
return '$K' + id.toString(16);
|
835
|
+
}
|
836
|
+
|
837
|
+
function serializeNumber(number) {
|
838
|
+
if (Number.isFinite(number)) {
|
839
|
+
if (number === 0 && 1 / number === -Infinity) {
|
840
|
+
return '$-0';
|
841
|
+
} else {
|
842
|
+
return number;
|
843
|
+
}
|
844
|
+
} else {
|
845
|
+
if (number === Infinity) {
|
846
|
+
return '$Infinity';
|
847
|
+
} else if (number === -Infinity) {
|
848
|
+
return '$-Infinity';
|
849
|
+
} else {
|
850
|
+
return '$NaN';
|
851
|
+
}
|
852
|
+
}
|
853
|
+
}
|
854
|
+
|
855
|
+
function serializeUndefined() {
|
856
|
+
return '$undefined';
|
857
|
+
}
|
858
|
+
|
859
|
+
function serializeDateFromDateJSON(dateJSON) {
|
860
|
+
// JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
|
861
|
+
// We need only tack on a $D prefix.
|
862
|
+
return '$D' + dateJSON;
|
863
|
+
}
|
864
|
+
|
865
|
+
function serializeBigInt(n) {
|
866
|
+
return '$n' + n.toString(10);
|
867
|
+
}
|
868
|
+
|
869
|
+
function serializeMapID(id) {
|
870
|
+
return '$Q' + id.toString(16);
|
871
|
+
}
|
872
|
+
|
873
|
+
function serializeSetID(id) {
|
874
|
+
return '$W' + id.toString(16);
|
875
|
+
}
|
876
|
+
|
877
|
+
function escapeStringValue(value) {
|
878
|
+
if (value[0] === '$') {
|
879
|
+
// We need to escape $ prefixed strings since we use those to encode
|
880
|
+
// references to IDs and as special symbol values.
|
881
|
+
return '$' + value;
|
882
|
+
} else {
|
883
|
+
return value;
|
884
|
+
}
|
885
|
+
}
|
886
|
+
|
887
|
+
function processReply(root, formFieldPrefix, temporaryReferences, resolve, reject) {
|
888
|
+
var nextPartId = 1;
|
889
|
+
var pendingParts = 0;
|
890
|
+
var formData = null;
|
891
|
+
|
892
|
+
function resolveToJSON(key, value) {
|
893
|
+
var parent = this; // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
|
894
|
+
|
895
|
+
{
|
896
|
+
// $FlowFixMe[incompatible-use]
|
897
|
+
var originalValue = parent[key];
|
898
|
+
|
899
|
+
if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
|
900
|
+
if (objectName(originalValue) !== 'Object') {
|
901
|
+
error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
|
902
|
+
} else {
|
903
|
+
error('Only plain objects can be passed to Server Functions from the Client. ' + 'Objects with toJSON methods are not supported. Convert it manually ' + 'to a simple value before passing it to props.%s', describeObjectForErrorMessage(parent, key));
|
904
|
+
}
|
905
|
+
}
|
906
|
+
}
|
907
|
+
|
908
|
+
if (value === null) {
|
909
|
+
return null;
|
910
|
+
}
|
911
|
+
|
912
|
+
if (typeof value === 'object') {
|
913
|
+
switch (value.$$typeof) {
|
914
|
+
case REACT_ELEMENT_TYPE:
|
915
|
+
{
|
916
|
+
if (temporaryReferences === undefined) {
|
917
|
+
throw new Error('React Element cannot be passed to Server Functions from the Client without a ' + 'temporary reference set. Pass a TemporaryReferenceSet to the options.' + (describeObjectForErrorMessage(parent, key) ));
|
918
|
+
}
|
919
|
+
|
920
|
+
return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
|
921
|
+
}
|
922
|
+
|
923
|
+
case REACT_LAZY_TYPE:
|
924
|
+
{
|
925
|
+
// Resolve lazy as if it wasn't here. In the future this will be encoded as a Promise.
|
926
|
+
var lazy = value;
|
927
|
+
var payload = lazy._payload;
|
928
|
+
var init = lazy._init;
|
929
|
+
|
930
|
+
if (formData === null) {
|
931
|
+
// Upgrade to use FormData to allow us to stream this value.
|
932
|
+
formData = new FormData();
|
933
|
+
}
|
934
|
+
|
935
|
+
pendingParts++;
|
936
|
+
|
937
|
+
try {
|
938
|
+
var resolvedModel = init(payload); // We always outline this as a separate part even though we could inline it
|
939
|
+
// because it ensures a more deterministic encoding.
|
940
|
+
|
941
|
+
var lazyId = nextPartId++;
|
942
|
+
var partJSON = JSON.stringify(resolvedModel, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
943
|
+
|
944
|
+
var data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
|
945
|
+
|
946
|
+
data.append(formFieldPrefix + lazyId, partJSON);
|
947
|
+
return serializeByValueID(lazyId);
|
948
|
+
} catch (x) {
|
949
|
+
if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
|
950
|
+
// Suspended
|
951
|
+
pendingParts++;
|
952
|
+
|
953
|
+
var _lazyId = nextPartId++;
|
954
|
+
|
955
|
+
var thenable = x;
|
956
|
+
|
957
|
+
var retry = function () {
|
958
|
+
// While the first promise resolved, its value isn't necessarily what we'll
|
959
|
+
// resolve into because we might suspend again.
|
960
|
+
try {
|
961
|
+
var _partJSON = JSON.stringify(value, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
962
|
+
|
963
|
+
|
964
|
+
var _data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
|
965
|
+
|
966
|
+
_data.append(formFieldPrefix + _lazyId, _partJSON);
|
967
|
+
|
968
|
+
pendingParts--;
|
969
|
+
|
970
|
+
if (pendingParts === 0) {
|
971
|
+
resolve(_data);
|
972
|
+
}
|
973
|
+
} catch (reason) {
|
974
|
+
reject(reason);
|
975
|
+
}
|
976
|
+
};
|
977
|
+
|
978
|
+
thenable.then(retry, retry);
|
979
|
+
return serializeByValueID(_lazyId);
|
980
|
+
} else {
|
981
|
+
// In the future we could consider serializing this as an error
|
982
|
+
// that throws on the server instead.
|
983
|
+
reject(x);
|
984
|
+
return null;
|
985
|
+
}
|
986
|
+
} finally {
|
987
|
+
pendingParts--;
|
988
|
+
}
|
989
|
+
}
|
990
|
+
} // $FlowFixMe[method-unbinding]
|
991
|
+
|
992
|
+
|
993
|
+
if (typeof value.then === 'function') {
|
994
|
+
// We assume that any object with a .then property is a "Thenable" type,
|
995
|
+
// or a Promise type. Either of which can be represented by a Promise.
|
996
|
+
if (formData === null) {
|
997
|
+
// Upgrade to use FormData to allow us to stream this value.
|
998
|
+
formData = new FormData();
|
999
|
+
}
|
1000
|
+
|
1001
|
+
pendingParts++;
|
1002
|
+
var promiseId = nextPartId++;
|
1003
|
+
var _thenable = value;
|
1004
|
+
|
1005
|
+
_thenable.then(function (partValue) {
|
1006
|
+
try {
|
1007
|
+
var _partJSON2 = JSON.stringify(partValue, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
1008
|
+
|
1009
|
+
|
1010
|
+
var _data2 = formData; // eslint-disable-next-line react-internal/safe-string-coercion
|
1011
|
+
|
1012
|
+
_data2.append(formFieldPrefix + promiseId, _partJSON2);
|
1013
|
+
|
1014
|
+
pendingParts--;
|
1015
|
+
|
1016
|
+
if (pendingParts === 0) {
|
1017
|
+
resolve(_data2);
|
1018
|
+
}
|
1019
|
+
} catch (reason) {
|
1020
|
+
reject(reason);
|
1021
|
+
}
|
1022
|
+
}, function (reason) {
|
1023
|
+
// In the future we could consider serializing this as an error
|
1024
|
+
// that throws on the server instead.
|
1025
|
+
reject(reason);
|
1026
|
+
});
|
1027
|
+
|
1028
|
+
return serializePromiseID(promiseId);
|
1029
|
+
}
|
1030
|
+
|
1031
|
+
if (isArray(value)) {
|
1032
|
+
// $FlowFixMe[incompatible-return]
|
1033
|
+
return value;
|
1034
|
+
} // TODO: Should we the Object.prototype.toString.call() to test for cross-realm objects?
|
1035
|
+
|
1036
|
+
|
1037
|
+
if (value instanceof FormData) {
|
1038
|
+
if (formData === null) {
|
1039
|
+
// Upgrade to use FormData to allow us to use rich objects as its values.
|
1040
|
+
formData = new FormData();
|
1041
|
+
}
|
1042
|
+
|
1043
|
+
var _data3 = formData;
|
1044
|
+
var refId = nextPartId++; // Copy all the form fields with a prefix for this reference.
|
1045
|
+
// These must come first in the form order because we assume that all the
|
1046
|
+
// fields are available before this is referenced.
|
1047
|
+
|
1048
|
+
var prefix = formFieldPrefix + refId + '_'; // $FlowFixMe[prop-missing]: FormData has forEach.
|
1049
|
+
|
1050
|
+
value.forEach(function (originalValue, originalKey) {
|
1051
|
+
_data3.append(prefix + originalKey, originalValue);
|
1052
|
+
});
|
1053
|
+
return serializeFormDataReference(refId);
|
1054
|
+
}
|
1055
|
+
|
1056
|
+
if (value instanceof Map) {
|
1057
|
+
var _partJSON3 = JSON.stringify(Array.from(value), resolveToJSON);
|
1058
|
+
|
1059
|
+
if (formData === null) {
|
1060
|
+
formData = new FormData();
|
1061
|
+
}
|
1062
|
+
|
1063
|
+
var mapId = nextPartId++;
|
1064
|
+
formData.append(formFieldPrefix + mapId, _partJSON3);
|
1065
|
+
return serializeMapID(mapId);
|
1066
|
+
}
|
1067
|
+
|
1068
|
+
if (value instanceof Set) {
|
1069
|
+
var _partJSON4 = JSON.stringify(Array.from(value), resolveToJSON);
|
1070
|
+
|
1071
|
+
if (formData === null) {
|
1072
|
+
formData = new FormData();
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
var setId = nextPartId++;
|
1076
|
+
formData.append(formFieldPrefix + setId, _partJSON4);
|
1077
|
+
return serializeSetID(setId);
|
1078
|
+
}
|
1079
|
+
|
1080
|
+
var iteratorFn = getIteratorFn(value);
|
1081
|
+
|
1082
|
+
if (iteratorFn) {
|
1083
|
+
return Array.from(value);
|
1084
|
+
} // Verify that this is a simple plain object.
|
1085
|
+
|
1086
|
+
|
1087
|
+
var proto = getPrototypeOf(value);
|
1088
|
+
|
1089
|
+
if (proto !== ObjectPrototype && (proto === null || getPrototypeOf(proto) !== null)) {
|
1090
|
+
if (temporaryReferences === undefined) {
|
1091
|
+
throw new Error('Only plain objects, and a few built-ins, can be passed to Server Actions. ' + 'Classes or null prototypes are not supported.');
|
1092
|
+
} // We can serialize class instances as temporary references.
|
1093
|
+
|
1094
|
+
|
1095
|
+
return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
{
|
1099
|
+
if (value.$$typeof === (REACT_PROVIDER_TYPE)) {
|
1100
|
+
error('React Context Providers cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
|
1101
|
+
} else if (objectName(value) !== 'Object') {
|
1102
|
+
error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
|
1103
|
+
} else if (!isSimpleObject(value)) {
|
1104
|
+
error('Only plain objects can be passed to Server Functions from the Client. ' + 'Classes or other objects with methods are not supported.%s', describeObjectForErrorMessage(parent, key));
|
1105
|
+
} else if (Object.getOwnPropertySymbols) {
|
1106
|
+
var symbols = Object.getOwnPropertySymbols(value);
|
1107
|
+
|
1108
|
+
if (symbols.length > 0) {
|
1109
|
+
error('Only plain objects can be passed to Server Functions from the Client. ' + 'Objects with symbol properties like %s are not supported.%s', symbols[0].description, describeObjectForErrorMessage(parent, key));
|
1110
|
+
}
|
1111
|
+
}
|
1112
|
+
} // $FlowFixMe[incompatible-return]
|
1113
|
+
|
1114
|
+
|
1115
|
+
return value;
|
1116
|
+
}
|
1117
|
+
|
1118
|
+
if (typeof value === 'string') {
|
1119
|
+
// TODO: Maybe too clever. If we support URL there's no similar trick.
|
1120
|
+
if (value[value.length - 1] === 'Z') {
|
1121
|
+
// Possibly a Date, whose toJSON automatically calls toISOString
|
1122
|
+
// $FlowFixMe[incompatible-use]
|
1123
|
+
var _originalValue = parent[key];
|
1124
|
+
|
1125
|
+
if (_originalValue instanceof Date) {
|
1126
|
+
return serializeDateFromDateJSON(value);
|
1127
|
+
}
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
return escapeStringValue(value);
|
1131
|
+
}
|
1132
|
+
|
1133
|
+
if (typeof value === 'boolean') {
|
1134
|
+
return value;
|
1135
|
+
}
|
1136
|
+
|
1137
|
+
if (typeof value === 'number') {
|
1138
|
+
return serializeNumber(value);
|
1139
|
+
}
|
1140
|
+
|
1141
|
+
if (typeof value === 'undefined') {
|
1142
|
+
return serializeUndefined();
|
1143
|
+
}
|
1144
|
+
|
1145
|
+
if (typeof value === 'function') {
|
1146
|
+
var metaData = knownServerReferences.get(value);
|
1147
|
+
|
1148
|
+
if (metaData !== undefined) {
|
1149
|
+
var metaDataJSON = JSON.stringify(metaData, resolveToJSON);
|
1150
|
+
|
1151
|
+
if (formData === null) {
|
1152
|
+
// Upgrade to use FormData to allow us to stream this value.
|
1153
|
+
formData = new FormData();
|
1154
|
+
} // The reference to this function came from the same client so we can pass it back.
|
1155
|
+
|
1156
|
+
|
1157
|
+
var _refId = nextPartId++; // eslint-disable-next-line react-internal/safe-string-coercion
|
1158
|
+
|
1159
|
+
|
1160
|
+
formData.set(formFieldPrefix + _refId, metaDataJSON);
|
1161
|
+
return serializeServerReferenceID(_refId);
|
1162
|
+
}
|
1163
|
+
|
1164
|
+
if (temporaryReferences === undefined) {
|
1165
|
+
throw new Error('Client Functions cannot be passed directly to Server Functions. ' + 'Only Functions passed from the Server can be passed back again.');
|
1166
|
+
}
|
1167
|
+
|
1168
|
+
return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
if (typeof value === 'symbol') {
|
1172
|
+
if (temporaryReferences === undefined) {
|
1173
|
+
throw new Error('Symbols cannot be passed to a Server Function without a ' + 'temporary reference set. Pass a TemporaryReferenceSet to the options.' + (describeObjectForErrorMessage(parent, key) ));
|
1174
|
+
}
|
1175
|
+
|
1176
|
+
return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
|
1177
|
+
}
|
1178
|
+
|
1179
|
+
if (typeof value === 'bigint') {
|
1180
|
+
return serializeBigInt(value);
|
1181
|
+
}
|
1182
|
+
|
1183
|
+
throw new Error("Type " + typeof value + " is not supported as an argument to a Server Function.");
|
1184
|
+
} // $FlowFixMe[incompatible-type] it's not going to be undefined because we'll encode it.
|
1185
|
+
|
1186
|
+
|
1187
|
+
var json = JSON.stringify(root, resolveToJSON);
|
1188
|
+
|
1189
|
+
if (formData === null) {
|
1190
|
+
// If it's a simple data structure, we just use plain JSON.
|
1191
|
+
resolve(json);
|
1192
|
+
} else {
|
1193
|
+
// Otherwise, we use FormData to let us stream in the result.
|
1194
|
+
formData.set(formFieldPrefix + '0', json);
|
1195
|
+
|
1196
|
+
if (pendingParts === 0) {
|
1197
|
+
// $FlowFixMe[incompatible-call] this has already been refined.
|
1198
|
+
resolve(formData);
|
1199
|
+
}
|
1200
|
+
}
|
1201
|
+
}
|
1202
|
+
var boundCache = new WeakMap();
|
1203
|
+
|
1204
|
+
function encodeFormData(reference) {
|
1205
|
+
var resolve, reject; // We need to have a handle on the thenable so that we can synchronously set
|
1206
|
+
// its status from processReply, when it can complete synchronously.
|
1207
|
+
|
1208
|
+
var thenable = new Promise(function (res, rej) {
|
1209
|
+
resolve = res;
|
1210
|
+
reject = rej;
|
1211
|
+
});
|
1212
|
+
processReply(reference, '', undefined, // TODO: This means React Elements can't be used as state in progressive enhancement.
|
1213
|
+
function (body) {
|
1214
|
+
if (typeof body === 'string') {
|
1215
|
+
var data = new FormData();
|
1216
|
+
data.append('0', body);
|
1217
|
+
body = data;
|
1218
|
+
}
|
1219
|
+
|
1220
|
+
var fulfilled = thenable;
|
1221
|
+
fulfilled.status = 'fulfilled';
|
1222
|
+
fulfilled.value = body;
|
1223
|
+
resolve(body);
|
1224
|
+
}, function (e) {
|
1225
|
+
var rejected = thenable;
|
1226
|
+
rejected.status = 'rejected';
|
1227
|
+
rejected.reason = e;
|
1228
|
+
reject(e);
|
1229
|
+
});
|
1230
|
+
return thenable;
|
1231
|
+
}
|
1232
|
+
|
1233
|
+
function defaultEncodeFormAction(identifierPrefix) {
|
1234
|
+
var reference = knownServerReferences.get(this);
|
1235
|
+
|
1236
|
+
if (!reference) {
|
1237
|
+
throw new Error('Tried to encode a Server Action from a different instance than the encoder is from. ' + 'This is a bug in React.');
|
1238
|
+
}
|
1239
|
+
|
1240
|
+
var data = null;
|
1241
|
+
var name;
|
1242
|
+
var boundPromise = reference.bound;
|
1243
|
+
|
1244
|
+
if (boundPromise !== null) {
|
1245
|
+
var thenable = boundCache.get(reference);
|
1246
|
+
|
1247
|
+
if (!thenable) {
|
1248
|
+
thenable = encodeFormData(reference);
|
1249
|
+
boundCache.set(reference, thenable);
|
1250
|
+
}
|
1251
|
+
|
1252
|
+
if (thenable.status === 'rejected') {
|
1253
|
+
throw thenable.reason;
|
1254
|
+
} else if (thenable.status !== 'fulfilled') {
|
1255
|
+
throw thenable;
|
1256
|
+
}
|
1257
|
+
|
1258
|
+
var encodedFormData = thenable.value; // This is hacky but we need the identifier prefix to be added to
|
1259
|
+
// all fields but the suspense cache would break since we might get
|
1260
|
+
// a new identifier each time. So we just append it at the end instead.
|
1261
|
+
|
1262
|
+
var prefixedData = new FormData(); // $FlowFixMe[prop-missing]
|
1263
|
+
|
1264
|
+
encodedFormData.forEach(function (value, key) {
|
1265
|
+
prefixedData.append('$ACTION_' + identifierPrefix + ':' + key, value);
|
1266
|
+
});
|
1267
|
+
data = prefixedData; // We encode the name of the prefix containing the data.
|
1268
|
+
|
1269
|
+
name = '$ACTION_REF_' + identifierPrefix;
|
1270
|
+
} else {
|
1271
|
+
// This is the simple case so we can just encode the ID.
|
1272
|
+
name = '$ACTION_ID_' + reference.id;
|
1273
|
+
}
|
1274
|
+
|
1275
|
+
return {
|
1276
|
+
name: name,
|
1277
|
+
method: 'POST',
|
1278
|
+
encType: 'multipart/form-data',
|
1279
|
+
data: data
|
1280
|
+
};
|
1281
|
+
}
|
1282
|
+
|
1283
|
+
function customEncodeFormAction(proxy, identifierPrefix, encodeFormAction) {
|
1284
|
+
var reference = knownServerReferences.get(proxy);
|
1285
|
+
|
1286
|
+
if (!reference) {
|
1287
|
+
throw new Error('Tried to encode a Server Action from a different instance than the encoder is from. ' + 'This is a bug in React.');
|
1288
|
+
}
|
1289
|
+
|
1290
|
+
var boundPromise = reference.bound;
|
1291
|
+
|
1292
|
+
if (boundPromise === null) {
|
1293
|
+
boundPromise = Promise.resolve([]);
|
161
1294
|
}
|
162
1295
|
|
163
|
-
return
|
1296
|
+
return encodeFormAction(reference.id, boundPromise);
|
164
1297
|
}
|
165
1298
|
|
166
|
-
|
1299
|
+
function isSignatureEqual(referenceId, numberOfBoundArgs) {
|
1300
|
+
var reference = knownServerReferences.get(this);
|
167
1301
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
var dispatcher = ReactDOMCurrentDispatcher.current;
|
1302
|
+
if (!reference) {
|
1303
|
+
throw new Error('Tried to encode a Server Action from a different instance than the encoder is from. ' + 'This is a bug in React.');
|
1304
|
+
}
|
172
1305
|
|
173
|
-
if (
|
174
|
-
|
1306
|
+
if (reference.id !== referenceId) {
|
1307
|
+
// These are different functions.
|
1308
|
+
return false;
|
1309
|
+
} // Now check if the number of bound arguments is the same.
|
175
1310
|
|
176
|
-
if (typeof model === 'string') {
|
177
|
-
href = model;
|
178
|
-
} else {
|
179
|
-
href = model[0];
|
180
|
-
options = model[1];
|
181
|
-
}
|
182
1311
|
|
183
|
-
|
184
|
-
case 'D':
|
185
|
-
{
|
186
|
-
// $FlowFixMe[prop-missing] options are not refined to their types by code
|
187
|
-
dispatcher.prefetchDNS(href, options);
|
188
|
-
return;
|
189
|
-
}
|
1312
|
+
var boundPromise = reference.bound;
|
190
1313
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
1314
|
+
if (boundPromise === null) {
|
1315
|
+
// No bound arguments.
|
1316
|
+
return numberOfBoundArgs === 0;
|
1317
|
+
} // Unwrap the bound arguments array by suspending, if necessary. As with
|
1318
|
+
// encodeFormData, this means isSignatureEqual can only be called while React
|
1319
|
+
// is rendering.
|
197
1320
|
|
198
|
-
case 'L':
|
199
|
-
{
|
200
|
-
// $FlowFixMe[prop-missing] options are not refined to their types by code
|
201
|
-
// $FlowFixMe[incompatible-call] options are not refined to their types by code
|
202
|
-
dispatcher.preload(href, options);
|
203
|
-
return;
|
204
|
-
}
|
205
1321
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
1322
|
+
switch (boundPromise.status) {
|
1323
|
+
case 'fulfilled':
|
1324
|
+
{
|
1325
|
+
var boundArgs = boundPromise.value;
|
1326
|
+
return boundArgs.length === numberOfBoundArgs;
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
case 'pending':
|
1330
|
+
{
|
1331
|
+
throw boundPromise;
|
1332
|
+
}
|
1333
|
+
|
1334
|
+
case 'rejected':
|
1335
|
+
{
|
1336
|
+
throw boundPromise.reason;
|
1337
|
+
}
|
1338
|
+
|
1339
|
+
default:
|
1340
|
+
{
|
1341
|
+
if (typeof boundPromise.status === 'string') ; else {
|
1342
|
+
var pendingThenable = boundPromise;
|
1343
|
+
pendingThenable.status = 'pending';
|
1344
|
+
pendingThenable.then(function (boundArgs) {
|
1345
|
+
var fulfilledThenable = boundPromise;
|
1346
|
+
fulfilledThenable.status = 'fulfilled';
|
1347
|
+
fulfilledThenable.value = boundArgs;
|
1348
|
+
}, function (error) {
|
1349
|
+
var rejectedThenable = boundPromise;
|
1350
|
+
rejectedThenable.status = 'rejected';
|
1351
|
+
rejectedThenable.reason = error;
|
1352
|
+
});
|
212
1353
|
}
|
213
|
-
|
1354
|
+
|
1355
|
+
throw boundPromise;
|
1356
|
+
}
|
214
1357
|
}
|
215
1358
|
}
|
216
1359
|
|
217
|
-
|
1360
|
+
function registerServerReference(proxy, reference, encodeFormAction) {
|
1361
|
+
// Expose encoder for use by SSR, as well as a special bind that can be used to
|
1362
|
+
// keep server capabilities.
|
1363
|
+
{
|
1364
|
+
// Only expose this in builds that would actually use it. Not needed on the client.
|
1365
|
+
var $$FORM_ACTION = encodeFormAction === undefined ? defaultEncodeFormAction : function (identifierPrefix) {
|
1366
|
+
return customEncodeFormAction(this, identifierPrefix, encodeFormAction);
|
1367
|
+
};
|
1368
|
+
Object.defineProperties(proxy, {
|
1369
|
+
$$FORM_ACTION: {
|
1370
|
+
value: $$FORM_ACTION
|
1371
|
+
},
|
1372
|
+
$$IS_SIGNATURE_EQUAL: {
|
1373
|
+
value: isSignatureEqual
|
1374
|
+
},
|
1375
|
+
bind: {
|
1376
|
+
value: bind
|
1377
|
+
}
|
1378
|
+
});
|
1379
|
+
}
|
218
1380
|
|
219
|
-
|
220
|
-
//
|
221
|
-
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
|
222
|
-
// The Symbol used to tag the ReactElement-like types.
|
223
|
-
var REACT_ELEMENT_TYPE = Symbol.for('react.element');
|
224
|
-
var REACT_LAZY_TYPE = Symbol.for('react.lazy');
|
225
|
-
var REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for('react.default_value');
|
1381
|
+
knownServerReferences.set(proxy, reference);
|
1382
|
+
} // $FlowFixMe[method-unbinding]
|
226
1383
|
|
227
|
-
var
|
1384
|
+
var FunctionBind = Function.prototype.bind; // $FlowFixMe[method-unbinding]
|
1385
|
+
|
1386
|
+
var ArraySlice = Array.prototype.slice;
|
1387
|
+
|
1388
|
+
function bind() {
|
1389
|
+
// $FlowFixMe[unsupported-syntax]
|
1390
|
+
var newFn = FunctionBind.apply(this, arguments);
|
1391
|
+
var reference = knownServerReferences.get(this);
|
1392
|
+
|
1393
|
+
if (reference) {
|
1394
|
+
{
|
1395
|
+
var thisBind = arguments[0];
|
1396
|
+
|
1397
|
+
if (thisBind != null) {
|
1398
|
+
// This doesn't warn in browser environments since it's not instrumented outside
|
1399
|
+
// usedWithSSR. This makes this an SSR only warning which we don't generally do.
|
1400
|
+
// TODO: Consider a DEV only instrumentation in the browser.
|
1401
|
+
error('Cannot bind "this" of a Server Action. Pass null or undefined as the first argument to .bind().');
|
1402
|
+
}
|
1403
|
+
}
|
1404
|
+
|
1405
|
+
var args = ArraySlice.call(arguments, 1);
|
1406
|
+
var boundPromise = null;
|
1407
|
+
|
1408
|
+
if (reference.bound !== null) {
|
1409
|
+
boundPromise = Promise.resolve(reference.bound).then(function (boundArgs) {
|
1410
|
+
return boundArgs.concat(args);
|
1411
|
+
});
|
1412
|
+
} else {
|
1413
|
+
boundPromise = Promise.resolve(args);
|
1414
|
+
} // Expose encoder for use by SSR, as well as a special bind that can be used to
|
1415
|
+
// keep server capabilities.
|
1416
|
+
|
1417
|
+
|
1418
|
+
{
|
1419
|
+
// Only expose this in builds that would actually use it. Not needed on the client.
|
1420
|
+
Object.defineProperties(newFn, {
|
1421
|
+
$$FORM_ACTION: {
|
1422
|
+
value: this.$$FORM_ACTION
|
1423
|
+
},
|
1424
|
+
$$IS_SIGNATURE_EQUAL: {
|
1425
|
+
value: isSignatureEqual
|
1426
|
+
},
|
1427
|
+
bind: {
|
1428
|
+
value: bind
|
1429
|
+
}
|
1430
|
+
});
|
1431
|
+
}
|
228
1432
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
|
1433
|
+
knownServerReferences.set(newFn, {
|
1434
|
+
id: reference.id,
|
1435
|
+
bound: boundPromise
|
1436
|
+
});
|
234
1437
|
}
|
235
1438
|
|
236
|
-
return
|
1439
|
+
return newFn;
|
1440
|
+
}
|
1441
|
+
|
1442
|
+
function createServerReference$1(id, callServer, encodeFormAction) {
|
1443
|
+
var proxy = function () {
|
1444
|
+
// $FlowFixMe[method-unbinding]
|
1445
|
+
var args = Array.prototype.slice.call(arguments);
|
1446
|
+
return callServer(id, args);
|
1447
|
+
};
|
1448
|
+
|
1449
|
+
registerServerReference(proxy, {
|
1450
|
+
id: id,
|
1451
|
+
bound: null
|
1452
|
+
}, encodeFormAction);
|
1453
|
+
return proxy;
|
237
1454
|
}
|
238
1455
|
|
1456
|
+
var ROW_ID = 0;
|
1457
|
+
var ROW_TAG = 1;
|
1458
|
+
var ROW_LENGTH = 2;
|
1459
|
+
var ROW_CHUNK_BY_NEWLINE = 3;
|
1460
|
+
var ROW_CHUNK_BY_LENGTH = 4;
|
239
1461
|
var PENDING = 'pending';
|
240
1462
|
var BLOCKED = 'blocked';
|
1463
|
+
var CYCLIC = 'cyclic';
|
241
1464
|
var RESOLVED_MODEL = 'resolved_model';
|
242
1465
|
var RESOLVED_MODULE = 'resolved_module';
|
243
1466
|
var INITIALIZED = 'fulfilled';
|
@@ -248,6 +1471,10 @@ function Chunk(status, value, reason, response) {
|
|
248
1471
|
this.value = value;
|
249
1472
|
this.reason = reason;
|
250
1473
|
this._response = response;
|
1474
|
+
|
1475
|
+
{
|
1476
|
+
this._debugInfo = null;
|
1477
|
+
}
|
251
1478
|
} // We subclass Promise.prototype so that we get other methods like .catch
|
252
1479
|
|
253
1480
|
|
@@ -275,6 +1502,7 @@ Chunk.prototype.then = function (resolve, reject) {
|
|
275
1502
|
|
276
1503
|
case PENDING:
|
277
1504
|
case BLOCKED:
|
1505
|
+
case CYCLIC:
|
278
1506
|
if (resolve) {
|
279
1507
|
if (chunk.value === null) {
|
280
1508
|
chunk.value = [];
|
@@ -319,6 +1547,7 @@ function readChunk(chunk) {
|
|
319
1547
|
|
320
1548
|
case PENDING:
|
321
1549
|
case BLOCKED:
|
1550
|
+
case CYCLIC:
|
322
1551
|
// eslint-disable-next-line no-throw-literal
|
323
1552
|
throw chunk;
|
324
1553
|
|
@@ -362,6 +1591,7 @@ function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
|
|
362
1591
|
|
363
1592
|
case PENDING:
|
364
1593
|
case BLOCKED:
|
1594
|
+
case CYCLIC:
|
365
1595
|
chunk.value = resolveListeners;
|
366
1596
|
chunk.reason = rejectListeners;
|
367
1597
|
break;
|
@@ -401,6 +1631,11 @@ function createResolvedModuleChunk(response, value) {
|
|
401
1631
|
return new Chunk(RESOLVED_MODULE, value, null, response);
|
402
1632
|
}
|
403
1633
|
|
1634
|
+
function createInitializedTextChunk(response, value) {
|
1635
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
1636
|
+
return new Chunk(INITIALIZED, value, null, response);
|
1637
|
+
}
|
1638
|
+
|
404
1639
|
function resolveModelChunk(chunk, value) {
|
405
1640
|
if (chunk.status !== PENDING) {
|
406
1641
|
// We already resolved. We didn't expect to see this.
|
@@ -449,9 +1684,17 @@ function initializeModelChunk(chunk) {
|
|
449
1684
|
var prevBlocked = initializingChunkBlockedModel;
|
450
1685
|
initializingChunk = chunk;
|
451
1686
|
initializingChunkBlockedModel = null;
|
1687
|
+
var resolvedModel = chunk.value; // We go to the CYCLIC state until we've fully resolved this.
|
1688
|
+
// We do this before parsing in case we try to initialize the same chunk
|
1689
|
+
// while parsing the model. Such as in a cyclic reference.
|
1690
|
+
|
1691
|
+
var cyclicChunk = chunk;
|
1692
|
+
cyclicChunk.status = CYCLIC;
|
1693
|
+
cyclicChunk.value = null;
|
1694
|
+
cyclicChunk.reason = null;
|
452
1695
|
|
453
1696
|
try {
|
454
|
-
var value = parseModel(chunk._response,
|
1697
|
+
var value = parseModel(chunk._response, resolvedModel);
|
455
1698
|
|
456
1699
|
if (initializingChunkBlockedModel !== null && initializingChunkBlockedModel.deps > 0) {
|
457
1700
|
initializingChunkBlockedModel.value = value; // We discovered new dependencies on modules that are not yet resolved.
|
@@ -462,9 +1705,14 @@ function initializeModelChunk(chunk) {
|
|
462
1705
|
blockedChunk.value = null;
|
463
1706
|
blockedChunk.reason = null;
|
464
1707
|
} else {
|
1708
|
+
var resolveListeners = cyclicChunk.value;
|
465
1709
|
var initializedChunk = chunk;
|
466
1710
|
initializedChunk.status = INITIALIZED;
|
467
1711
|
initializedChunk.value = value;
|
1712
|
+
|
1713
|
+
if (resolveListeners !== null) {
|
1714
|
+
wakeChunk(resolveListeners, value);
|
1715
|
+
}
|
468
1716
|
}
|
469
1717
|
} catch (error) {
|
470
1718
|
var erroredChunk = chunk;
|
@@ -503,17 +1751,20 @@ function reportGlobalError(response, error) {
|
|
503
1751
|
}
|
504
1752
|
|
505
1753
|
function createElement(type, key, props) {
|
506
|
-
var element
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
1754
|
+
var element;
|
1755
|
+
|
1756
|
+
{
|
1757
|
+
element = {
|
1758
|
+
// This tag allows us to uniquely identify this as a React Element
|
1759
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
1760
|
+
type: type,
|
1761
|
+
key: key,
|
1762
|
+
ref: null,
|
1763
|
+
props: props,
|
1764
|
+
// Record the component responsible for creating this element.
|
1765
|
+
_owner: null
|
1766
|
+
};
|
1767
|
+
}
|
517
1768
|
|
518
1769
|
{
|
519
1770
|
// We don't really need to add any of these but keeping them for good measure.
|
@@ -526,17 +1777,12 @@ function createElement(type, key, props) {
|
|
526
1777
|
writable: true,
|
527
1778
|
value: true // This element has already been validated on the server.
|
528
1779
|
|
529
|
-
});
|
530
|
-
|
531
|
-
|
532
|
-
enumerable: false,
|
533
|
-
writable: false,
|
534
|
-
value: null
|
535
|
-
});
|
536
|
-
Object.defineProperty(element, '_source', {
|
1780
|
+
}); // debugInfo contains Server Component debug information.
|
1781
|
+
|
1782
|
+
Object.defineProperty(element, '_debugInfo', {
|
537
1783
|
configurable: false,
|
538
1784
|
enumerable: false,
|
539
|
-
writable:
|
1785
|
+
writable: true,
|
540
1786
|
value: null
|
541
1787
|
});
|
542
1788
|
}
|
@@ -550,6 +1796,13 @@ function createLazyChunkWrapper(chunk) {
|
|
550
1796
|
_payload: chunk,
|
551
1797
|
_init: readChunk
|
552
1798
|
};
|
1799
|
+
|
1800
|
+
{
|
1801
|
+
// Ensure we have a live array to track future debug info.
|
1802
|
+
var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
|
1803
|
+
lazyType._debugInfo = chunkDebugInfo;
|
1804
|
+
}
|
1805
|
+
|
553
1806
|
return lazyType;
|
554
1807
|
}
|
555
1808
|
|
@@ -565,15 +1818,18 @@ function getChunk(response, id) {
|
|
565
1818
|
return chunk;
|
566
1819
|
}
|
567
1820
|
|
568
|
-
function createModelResolver(chunk, parentObject, key) {
|
1821
|
+
function createModelResolver(chunk, parentObject, key, cyclic) {
|
569
1822
|
var blocked;
|
570
1823
|
|
571
1824
|
if (initializingChunkBlockedModel) {
|
572
1825
|
blocked = initializingChunkBlockedModel;
|
573
|
-
|
1826
|
+
|
1827
|
+
if (!cyclic) {
|
1828
|
+
blocked.deps++;
|
1829
|
+
}
|
574
1830
|
} else {
|
575
1831
|
blocked = initializingChunkBlockedModel = {
|
576
|
-
deps: 1,
|
1832
|
+
deps: cyclic ? 0 : 1,
|
577
1833
|
value: null
|
578
1834
|
};
|
579
1835
|
}
|
@@ -629,10 +1885,32 @@ function createServerReferenceProxy(response, metaData) {
|
|
629
1885
|
});
|
630
1886
|
};
|
631
1887
|
|
632
|
-
|
1888
|
+
registerServerReference(proxy, metaData, response._encodeFormAction);
|
633
1889
|
return proxy;
|
634
1890
|
}
|
635
1891
|
|
1892
|
+
function getOutlinedModel(response, id) {
|
1893
|
+
var chunk = getChunk(response, id);
|
1894
|
+
|
1895
|
+
switch (chunk.status) {
|
1896
|
+
case RESOLVED_MODEL:
|
1897
|
+
initializeModelChunk(chunk);
|
1898
|
+
break;
|
1899
|
+
} // The status might have changed after initialization.
|
1900
|
+
|
1901
|
+
|
1902
|
+
switch (chunk.status) {
|
1903
|
+
case INITIALIZED:
|
1904
|
+
{
|
1905
|
+
return chunk.value;
|
1906
|
+
}
|
1907
|
+
// We always encode it first in the stream so it won't be pending.
|
1908
|
+
|
1909
|
+
default:
|
1910
|
+
throw chunk.reason;
|
1911
|
+
}
|
1912
|
+
}
|
1913
|
+
|
636
1914
|
function parseModelString(response, parentObject, key, value) {
|
637
1915
|
if (value[0] === '$') {
|
638
1916
|
if (value === '$') {
|
@@ -660,6 +1938,11 @@ function parseModelString(response, parentObject, key, value) {
|
|
660
1938
|
case '@':
|
661
1939
|
{
|
662
1940
|
// Promise
|
1941
|
+
if (value.length === 2) {
|
1942
|
+
// Infinite promise that never resolves.
|
1943
|
+
return new Promise(function () {});
|
1944
|
+
}
|
1945
|
+
|
663
1946
|
var _id = parseInt(value.slice(2), 16);
|
664
1947
|
|
665
1948
|
var _chunk = getChunk(response, _id);
|
@@ -673,37 +1956,46 @@ function parseModelString(response, parentObject, key, value) {
|
|
673
1956
|
return Symbol.for(value.slice(2));
|
674
1957
|
}
|
675
1958
|
|
676
|
-
case 'P':
|
677
|
-
{
|
678
|
-
// Server Context Provider
|
679
|
-
return getOrCreateServerContext(value.slice(2)).Provider;
|
680
|
-
}
|
681
|
-
|
682
1959
|
case 'F':
|
683
1960
|
{
|
684
1961
|
// Server Reference
|
685
1962
|
var _id2 = parseInt(value.slice(2), 16);
|
686
1963
|
|
687
|
-
var
|
688
|
-
|
689
|
-
|
690
|
-
case RESOLVED_MODEL:
|
691
|
-
initializeModelChunk(_chunk2);
|
692
|
-
break;
|
693
|
-
} // The status might have changed after initialization.
|
1964
|
+
var metadata = getOutlinedModel(response, _id2);
|
1965
|
+
return createServerReferenceProxy(response, metadata);
|
1966
|
+
}
|
694
1967
|
|
1968
|
+
case 'T':
|
1969
|
+
{
|
1970
|
+
// Temporary Reference
|
1971
|
+
var _id3 = parseInt(value.slice(2), 16);
|
695
1972
|
|
696
|
-
|
697
|
-
case INITIALIZED:
|
698
|
-
{
|
699
|
-
var metadata = _chunk2.value;
|
700
|
-
return createServerReferenceProxy(response, metadata);
|
701
|
-
}
|
702
|
-
// We always encode it first in the stream so it won't be pending.
|
1973
|
+
var temporaryReferences = response._tempRefs;
|
703
1974
|
|
704
|
-
|
705
|
-
|
1975
|
+
if (temporaryReferences == null) {
|
1976
|
+
throw new Error('Missing a temporary reference set but the RSC response returned a temporary reference. ' + 'Pass a temporaryReference option with the set that was used with the reply.');
|
706
1977
|
}
|
1978
|
+
|
1979
|
+
return readTemporaryReference(temporaryReferences, _id3);
|
1980
|
+
}
|
1981
|
+
|
1982
|
+
case 'Q':
|
1983
|
+
{
|
1984
|
+
// Map
|
1985
|
+
var _id4 = parseInt(value.slice(2), 16);
|
1986
|
+
|
1987
|
+
var data = getOutlinedModel(response, _id4);
|
1988
|
+
return new Map(data);
|
1989
|
+
}
|
1990
|
+
|
1991
|
+
case 'W':
|
1992
|
+
{
|
1993
|
+
// Set
|
1994
|
+
var _id5 = parseInt(value.slice(2), 16);
|
1995
|
+
|
1996
|
+
var _data = getOutlinedModel(response, _id5);
|
1997
|
+
|
1998
|
+
return new Set(_data);
|
707
1999
|
}
|
708
2000
|
|
709
2001
|
case 'I':
|
@@ -747,38 +2039,78 @@ function parseModelString(response, parentObject, key, value) {
|
|
747
2039
|
return BigInt(value.slice(2));
|
748
2040
|
}
|
749
2041
|
|
2042
|
+
case 'E':
|
2043
|
+
{
|
2044
|
+
{
|
2045
|
+
// In DEV mode we allow indirect eval to produce functions for logging.
|
2046
|
+
// This should not compile to eval() because then it has local scope access.
|
2047
|
+
try {
|
2048
|
+
// eslint-disable-next-line no-eval
|
2049
|
+
return (0, eval)(value.slice(2));
|
2050
|
+
} catch (x) {
|
2051
|
+
// We currently use this to express functions so we fail parsing it,
|
2052
|
+
// let's just return a blank function as a place holder.
|
2053
|
+
return function () {};
|
2054
|
+
}
|
2055
|
+
} // Fallthrough
|
2056
|
+
|
2057
|
+
}
|
2058
|
+
|
750
2059
|
default:
|
751
2060
|
{
|
752
2061
|
// We assume that anything else is a reference ID.
|
753
|
-
var
|
2062
|
+
var _id6 = parseInt(value.slice(1), 16);
|
754
2063
|
|
755
|
-
var
|
2064
|
+
var _chunk2 = getChunk(response, _id6);
|
756
2065
|
|
757
|
-
switch (
|
2066
|
+
switch (_chunk2.status) {
|
758
2067
|
case RESOLVED_MODEL:
|
759
|
-
initializeModelChunk(
|
2068
|
+
initializeModelChunk(_chunk2);
|
760
2069
|
break;
|
761
2070
|
|
762
2071
|
case RESOLVED_MODULE:
|
763
|
-
initializeModuleChunk(
|
2072
|
+
initializeModuleChunk(_chunk2);
|
764
2073
|
break;
|
765
2074
|
} // The status might have changed after initialization.
|
766
2075
|
|
767
2076
|
|
768
|
-
switch (
|
2077
|
+
switch (_chunk2.status) {
|
769
2078
|
case INITIALIZED:
|
770
|
-
|
2079
|
+
var chunkValue = _chunk2.value;
|
2080
|
+
|
2081
|
+
if (_chunk2._debugInfo) {
|
2082
|
+
// If we have a direct reference to an object that was rendered by a synchronous
|
2083
|
+
// server component, it might have some debug info about how it was rendered.
|
2084
|
+
// We forward this to the underlying object. This might be a React Element or
|
2085
|
+
// an Array fragment.
|
2086
|
+
// If this was a string / number return value we lose the debug info. We choose
|
2087
|
+
// that tradeoff to allow sync server components to return plain values and not
|
2088
|
+
// use them as React Nodes necessarily. We could otherwise wrap them in a Lazy.
|
2089
|
+
if (typeof chunkValue === 'object' && chunkValue !== null && (Array.isArray(chunkValue) || chunkValue.$$typeof === REACT_ELEMENT_TYPE) && !chunkValue._debugInfo) {
|
2090
|
+
// We should maybe use a unique symbol for arrays but this is a React owned array.
|
2091
|
+
// $FlowFixMe[prop-missing]: This should be added to elements.
|
2092
|
+
Object.defineProperty(chunkValue, '_debugInfo', {
|
2093
|
+
configurable: false,
|
2094
|
+
enumerable: false,
|
2095
|
+
writable: true,
|
2096
|
+
value: _chunk2._debugInfo
|
2097
|
+
});
|
2098
|
+
}
|
2099
|
+
}
|
2100
|
+
|
2101
|
+
return chunkValue;
|
771
2102
|
|
772
2103
|
case PENDING:
|
773
2104
|
case BLOCKED:
|
2105
|
+
case CYCLIC:
|
774
2106
|
var parentChunk = initializingChunk;
|
775
2107
|
|
776
|
-
|
2108
|
+
_chunk2.then(createModelResolver(parentChunk, parentObject, key, _chunk2.status === CYCLIC), createModelReject(parentChunk));
|
777
2109
|
|
778
2110
|
return null;
|
779
2111
|
|
780
2112
|
default:
|
781
|
-
throw
|
2113
|
+
throw _chunk2.reason;
|
782
2114
|
}
|
783
2115
|
}
|
784
2116
|
}
|
@@ -786,6 +2118,7 @@ function parseModelString(response, parentObject, key, value) {
|
|
786
2118
|
|
787
2119
|
return value;
|
788
2120
|
}
|
2121
|
+
|
789
2122
|
function parseModelTuple(response, value) {
|
790
2123
|
var tuple = value;
|
791
2124
|
|
@@ -802,15 +2135,29 @@ function missingCall() {
|
|
802
2135
|
throw new Error('Trying to call a function from "use server" but the callServer option ' + 'was not implemented in your router runtime.');
|
803
2136
|
}
|
804
2137
|
|
805
|
-
function createResponse
|
2138
|
+
function createResponse(bundlerConfig, moduleLoading, callServer, encodeFormAction, nonce, temporaryReferences) {
|
806
2139
|
var chunks = new Map();
|
807
2140
|
var response = {
|
808
2141
|
_bundlerConfig: bundlerConfig,
|
2142
|
+
_moduleLoading: moduleLoading,
|
809
2143
|
_callServer: callServer !== undefined ? callServer : missingCall,
|
810
|
-
|
811
|
-
|
2144
|
+
_encodeFormAction: encodeFormAction,
|
2145
|
+
_nonce: nonce,
|
2146
|
+
_chunks: chunks,
|
2147
|
+
_stringDecoder: createStringDecoder(),
|
2148
|
+
_fromJSON: null,
|
2149
|
+
_rowState: 0,
|
2150
|
+
_rowID: 0,
|
2151
|
+
_rowTag: 0,
|
2152
|
+
_rowLength: 0,
|
2153
|
+
_buffer: [],
|
2154
|
+
_tempRefs: temporaryReferences
|
2155
|
+
}; // Don't inline this call because it causes closure to outline the call above.
|
2156
|
+
|
2157
|
+
response._fromJSON = createFromJSONCallback(response);
|
812
2158
|
return response;
|
813
2159
|
}
|
2160
|
+
|
814
2161
|
function resolveModel(response, id, model) {
|
815
2162
|
var chunks = response._chunks;
|
816
2163
|
var chunk = chunks.get(id);
|
@@ -821,11 +2168,20 @@ function resolveModel(response, id, model) {
|
|
821
2168
|
resolveModelChunk(chunk, model);
|
822
2169
|
}
|
823
2170
|
}
|
2171
|
+
|
2172
|
+
function resolveText(response, id, text) {
|
2173
|
+
var chunks = response._chunks; // We assume that we always reference large strings after they've been
|
2174
|
+
// emitted.
|
2175
|
+
|
2176
|
+
chunks.set(id, createInitializedTextChunk(response, text));
|
2177
|
+
}
|
2178
|
+
|
824
2179
|
function resolveModule(response, id, model) {
|
825
2180
|
var chunks = response._chunks;
|
826
2181
|
var chunk = chunks.get(id);
|
827
2182
|
var clientReferenceMetadata = parseModel(response, model);
|
828
|
-
var clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata);
|
2183
|
+
var clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata);
|
2184
|
+
prepareDestinationForModule(response._moduleLoading, response._nonce, clientReferenceMetadata); // TODO: Add an option to encode modules that are lazy loaded.
|
829
2185
|
// For now we preload all modules as early as possible since it's likely
|
830
2186
|
// that we'll need them.
|
831
2187
|
|
@@ -861,6 +2217,7 @@ function resolveModule(response, id, model) {
|
|
861
2217
|
}
|
862
2218
|
}
|
863
2219
|
}
|
2220
|
+
|
864
2221
|
function resolveErrorDev(response, id, digest, message, stack) {
|
865
2222
|
|
866
2223
|
|
@@ -877,47 +2234,64 @@ function resolveErrorDev(response, id, digest, message, stack) {
|
|
877
2234
|
triggerErrorOnChunk(chunk, errorWithDigest);
|
878
2235
|
}
|
879
2236
|
}
|
2237
|
+
|
880
2238
|
function resolveHint(response, code, model) {
|
881
2239
|
var hintModel = parseModel(response, model);
|
882
2240
|
dispatchHint(code, hintModel);
|
883
2241
|
}
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
2242
|
+
|
2243
|
+
function resolveDebugInfo(response, id, debugInfo) {
|
2244
|
+
|
2245
|
+
var chunk = getChunk(response, id);
|
2246
|
+
var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
|
2247
|
+
chunkDebugInfo.push(debugInfo);
|
890
2248
|
}
|
891
2249
|
|
892
|
-
function
|
893
|
-
|
894
|
-
|
2250
|
+
function resolveConsoleEntry(response, value) {
|
2251
|
+
|
2252
|
+
var payload = parseModel(response, value);
|
2253
|
+
var methodName = payload[0]; // TODO: Restore the fake stack before logging.
|
2254
|
+
// const stackTrace = payload[1];
|
2255
|
+
|
2256
|
+
var env = payload[2];
|
2257
|
+
var args = payload.slice(3);
|
2258
|
+
printToConsole(methodName, args, env);
|
2259
|
+
}
|
2260
|
+
|
2261
|
+
function processFullRow(response, id, tag, buffer, chunk) {
|
2262
|
+
|
2263
|
+
var stringDecoder = response._stringDecoder;
|
2264
|
+
var row = '';
|
2265
|
+
|
2266
|
+
for (var i = 0; i < buffer.length; i++) {
|
2267
|
+
row += readPartialStringChunk(stringDecoder, buffer[i]);
|
895
2268
|
}
|
896
2269
|
|
897
|
-
|
898
|
-
var id = parseInt(row.slice(0, colon), 16);
|
899
|
-
var tag = row[colon + 1]; // When tags that are not text are added, check them here before
|
900
|
-
// parsing the row as text.
|
901
|
-
// switch (tag) {
|
902
|
-
// }
|
2270
|
+
row += readFinalStringChunk(stringDecoder, chunk);
|
903
2271
|
|
904
2272
|
switch (tag) {
|
905
|
-
case
|
2273
|
+
case 73
|
2274
|
+
/* "I" */
|
2275
|
+
:
|
906
2276
|
{
|
907
|
-
resolveModule(response, id, row
|
2277
|
+
resolveModule(response, id, row);
|
908
2278
|
return;
|
909
2279
|
}
|
910
2280
|
|
911
|
-
case
|
2281
|
+
case 72
|
2282
|
+
/* "H" */
|
2283
|
+
:
|
912
2284
|
{
|
913
|
-
var code = row[
|
914
|
-
resolveHint(response, code, row.slice(
|
2285
|
+
var code = row[0];
|
2286
|
+
resolveHint(response, code, row.slice(1));
|
915
2287
|
return;
|
916
2288
|
}
|
917
2289
|
|
918
|
-
case
|
2290
|
+
case 69
|
2291
|
+
/* "E" */
|
2292
|
+
:
|
919
2293
|
{
|
920
|
-
var errorInfo = JSON.parse(row
|
2294
|
+
var errorInfo = JSON.parse(row);
|
921
2295
|
|
922
2296
|
{
|
923
2297
|
resolveErrorDev(response, id, errorInfo.digest, errorInfo.message, errorInfo.stack);
|
@@ -926,28 +2300,186 @@ function processFullRow(response, row) {
|
|
926
2300
|
return;
|
927
2301
|
}
|
928
2302
|
|
2303
|
+
case 84
|
2304
|
+
/* "T" */
|
2305
|
+
:
|
2306
|
+
{
|
2307
|
+
resolveText(response, id, row);
|
2308
|
+
return;
|
2309
|
+
}
|
2310
|
+
|
2311
|
+
case 68
|
2312
|
+
/* "D" */
|
2313
|
+
:
|
2314
|
+
{
|
2315
|
+
{
|
2316
|
+
var debugInfo = JSON.parse(row);
|
2317
|
+
resolveDebugInfo(response, id, debugInfo);
|
2318
|
+
return;
|
2319
|
+
} // Fallthrough to share the error with Console entries.
|
2320
|
+
|
2321
|
+
}
|
2322
|
+
|
2323
|
+
case 87
|
2324
|
+
/* "W" */
|
2325
|
+
:
|
2326
|
+
{
|
2327
|
+
{
|
2328
|
+
resolveConsoleEntry(response, row);
|
2329
|
+
return;
|
2330
|
+
}
|
2331
|
+
}
|
2332
|
+
|
2333
|
+
case 80
|
2334
|
+
/* "P" */
|
2335
|
+
:
|
2336
|
+
// Fallthrough
|
2337
|
+
|
929
2338
|
default:
|
2339
|
+
/* """ "{" "[" "t" "f" "n" "0" - "9" */
|
930
2340
|
{
|
931
2341
|
// We assume anything else is JSON.
|
932
|
-
resolveModel(response, id, row
|
2342
|
+
resolveModel(response, id, row);
|
933
2343
|
return;
|
934
2344
|
}
|
935
2345
|
}
|
936
2346
|
}
|
2347
|
+
|
937
2348
|
function processBinaryChunk(response, chunk) {
|
2349
|
+
var i = 0;
|
2350
|
+
var rowState = response._rowState;
|
2351
|
+
var rowID = response._rowID;
|
2352
|
+
var rowTag = response._rowTag;
|
2353
|
+
var rowLength = response._rowLength;
|
2354
|
+
var buffer = response._buffer;
|
2355
|
+
var chunkLength = chunk.length;
|
2356
|
+
|
2357
|
+
while (i < chunkLength) {
|
2358
|
+
var lastIdx = -1;
|
2359
|
+
|
2360
|
+
switch (rowState) {
|
2361
|
+
case ROW_ID:
|
2362
|
+
{
|
2363
|
+
var byte = chunk[i++];
|
2364
|
+
|
2365
|
+
if (byte === 58
|
2366
|
+
/* ":" */
|
2367
|
+
) {
|
2368
|
+
// Finished the rowID, next we'll parse the tag.
|
2369
|
+
rowState = ROW_TAG;
|
2370
|
+
} else {
|
2371
|
+
rowID = rowID << 4 | (byte > 96 ? byte - 87 : byte - 48);
|
2372
|
+
}
|
938
2373
|
|
939
|
-
|
940
|
-
|
2374
|
+
continue;
|
2375
|
+
}
|
2376
|
+
|
2377
|
+
case ROW_TAG:
|
2378
|
+
{
|
2379
|
+
var resolvedRowTag = chunk[i];
|
2380
|
+
|
2381
|
+
if (resolvedRowTag === 84
|
2382
|
+
/* "T" */
|
2383
|
+
|| enableBinaryFlight
|
2384
|
+
/* "V" */
|
2385
|
+
) {
|
2386
|
+
rowTag = resolvedRowTag;
|
2387
|
+
rowState = ROW_LENGTH;
|
2388
|
+
i++;
|
2389
|
+
} else if (resolvedRowTag > 64 && resolvedRowTag < 91
|
2390
|
+
/* "A"-"Z" */
|
2391
|
+
) {
|
2392
|
+
rowTag = resolvedRowTag;
|
2393
|
+
rowState = ROW_CHUNK_BY_NEWLINE;
|
2394
|
+
i++;
|
2395
|
+
} else {
|
2396
|
+
rowTag = 0;
|
2397
|
+
rowState = ROW_CHUNK_BY_NEWLINE; // This was an unknown tag so it was probably part of the data.
|
2398
|
+
}
|
2399
|
+
|
2400
|
+
continue;
|
2401
|
+
}
|
2402
|
+
|
2403
|
+
case ROW_LENGTH:
|
2404
|
+
{
|
2405
|
+
var _byte = chunk[i++];
|
2406
|
+
|
2407
|
+
if (_byte === 44
|
2408
|
+
/* "," */
|
2409
|
+
) {
|
2410
|
+
// Finished the rowLength, next we'll buffer up to that length.
|
2411
|
+
rowState = ROW_CHUNK_BY_LENGTH;
|
2412
|
+
} else {
|
2413
|
+
rowLength = rowLength << 4 | (_byte > 96 ? _byte - 87 : _byte - 48);
|
2414
|
+
}
|
2415
|
+
|
2416
|
+
continue;
|
2417
|
+
}
|
2418
|
+
|
2419
|
+
case ROW_CHUNK_BY_NEWLINE:
|
2420
|
+
{
|
2421
|
+
// We're looking for a newline
|
2422
|
+
lastIdx = chunk.indexOf(10
|
2423
|
+
/* "\n" */
|
2424
|
+
, i);
|
2425
|
+
break;
|
2426
|
+
}
|
2427
|
+
|
2428
|
+
case ROW_CHUNK_BY_LENGTH:
|
2429
|
+
{
|
2430
|
+
// We're looking for the remaining byte length
|
2431
|
+
lastIdx = i + rowLength;
|
2432
|
+
|
2433
|
+
if (lastIdx > chunk.length) {
|
2434
|
+
lastIdx = -1;
|
2435
|
+
}
|
941
2436
|
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
2437
|
+
break;
|
2438
|
+
}
|
2439
|
+
}
|
2440
|
+
|
2441
|
+
var offset = chunk.byteOffset + i;
|
2442
|
+
|
2443
|
+
if (lastIdx > -1) {
|
2444
|
+
// We found the last chunk of the row
|
2445
|
+
var length = lastIdx - i;
|
2446
|
+
var lastChunk = new Uint8Array(chunk.buffer, offset, length);
|
2447
|
+
processFullRow(response, rowID, rowTag, buffer, lastChunk); // Reset state machine for a new row
|
2448
|
+
|
2449
|
+
i = lastIdx;
|
2450
|
+
|
2451
|
+
if (rowState === ROW_CHUNK_BY_NEWLINE) {
|
2452
|
+
// If we're trailing by a newline we need to skip it.
|
2453
|
+
i++;
|
2454
|
+
}
|
2455
|
+
|
2456
|
+
rowState = ROW_ID;
|
2457
|
+
rowTag = 0;
|
2458
|
+
rowID = 0;
|
2459
|
+
rowLength = 0;
|
2460
|
+
buffer.length = 0;
|
2461
|
+
} else {
|
2462
|
+
// The rest of this row is in a future chunk. We stash the rest of the
|
2463
|
+
// current chunk until we can process the full row.
|
2464
|
+
var _length = chunk.byteLength - i;
|
2465
|
+
|
2466
|
+
var remainingSlice = new Uint8Array(chunk.buffer, offset, _length);
|
2467
|
+
buffer.push(remainingSlice); // Update how many bytes we're still waiting for. If we're looking for
|
2468
|
+
// a newline, this doesn't hurt since we'll just ignore it.
|
2469
|
+
|
2470
|
+
rowLength -= remainingSlice.byteLength;
|
2471
|
+
break;
|
2472
|
+
}
|
948
2473
|
}
|
949
2474
|
|
950
|
-
response.
|
2475
|
+
response._rowState = rowState;
|
2476
|
+
response._rowID = rowID;
|
2477
|
+
response._rowTag = rowTag;
|
2478
|
+
response._rowLength = rowLength;
|
2479
|
+
}
|
2480
|
+
|
2481
|
+
function parseModel(response, json) {
|
2482
|
+
return JSON.parse(json, response._fromJSON);
|
951
2483
|
}
|
952
2484
|
|
953
2485
|
function createFromJSONCallback(response) {
|
@@ -966,20 +2498,12 @@ function createFromJSONCallback(response) {
|
|
966
2498
|
};
|
967
2499
|
}
|
968
2500
|
|
969
|
-
function
|
970
|
-
//
|
971
|
-
//
|
972
|
-
|
973
|
-
|
974
|
-
response
|
975
|
-
|
976
|
-
{
|
977
|
-
response._stringDecoder = stringDecoder;
|
978
|
-
} // Don't inline this call because it causes closure to outline the call above.
|
979
|
-
|
980
|
-
|
981
|
-
response._fromJSON = createFromJSONCallback(response);
|
982
|
-
return response;
|
2501
|
+
function close(response) {
|
2502
|
+
// In case there are any remaining unresolved chunks, they won't
|
2503
|
+
// be resolved now. So we need to issue an error to those.
|
2504
|
+
// Ideally we should be able to early bail out if we kept a
|
2505
|
+
// ref count of pending chunks.
|
2506
|
+
reportGlobalError(response, new Error('Connection closed.'));
|
983
2507
|
}
|
984
2508
|
|
985
2509
|
function noServerCall() {
|
@@ -987,11 +2511,11 @@ function noServerCall() {
|
|
987
2511
|
}
|
988
2512
|
|
989
2513
|
function createServerReference(id, callServer) {
|
990
|
-
return noServerCall;
|
2514
|
+
return createServerReference$1(id, noServerCall);
|
991
2515
|
}
|
992
2516
|
|
993
2517
|
function createResponseFromOptions(options) {
|
994
|
-
return createResponse(options
|
2518
|
+
return createResponse(options.ssrManifest.moduleMap, options.ssrManifest.moduleLoading, noServerCall, options.encodeFormAction, typeof options.nonce === 'string' ? options.nonce : undefined, options && options.temporaryReferences ? options.temporaryReferences : undefined);
|
995
2519
|
}
|
996
2520
|
|
997
2521
|
function startReadingFromStream(response, stream) {
|
@@ -1034,8 +2558,18 @@ function createFromFetch(promiseForResponse, options) {
|
|
1034
2558
|
return getRoot(response);
|
1035
2559
|
}
|
1036
2560
|
|
2561
|
+
function encodeReply(value, options)
|
2562
|
+
/* We don't use URLSearchParams yet but maybe */
|
2563
|
+
{
|
2564
|
+
return new Promise(function (resolve, reject) {
|
2565
|
+
processReply(value, '', options && options.temporaryReferences ? options.temporaryReferences : undefined, resolve, reject);
|
2566
|
+
});
|
2567
|
+
}
|
2568
|
+
|
1037
2569
|
exports.createFromFetch = createFromFetch;
|
1038
2570
|
exports.createFromReadableStream = createFromReadableStream;
|
1039
2571
|
exports.createServerReference = createServerReference;
|
2572
|
+
exports.createTemporaryReferenceSet = createTemporaryReferenceSet;
|
2573
|
+
exports.encodeReply = encodeReply;
|
1040
2574
|
})();
|
1041
2575
|
}
|