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