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