react-server-dom-webpack 18.3.0-next-594093496-20230209 → 18.3.0-next-55542bc73-20230210

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.
@@ -10,250 +10,11 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- 'use strict';
14
-
15
- var path = require('path');
16
- var url = require('url');
17
- var asyncLib = require('neo-async');
18
- var ModuleDependency = require('webpack/lib/dependencies/ModuleDependency');
19
- var NullDependency = require('webpack/lib/dependencies/NullDependency');
20
- var Template = require('webpack/lib/Template');
21
- var webpack = require('webpack');
22
-
23
- var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
24
-
25
- function isArray(a) {
26
- return isArrayImpl(a);
27
- }
28
-
29
- class ClientReferenceDependency extends ModuleDependency {
30
- constructor(request) {
31
- super(request);
32
- }
33
-
34
- get type() {
35
- return 'client-reference';
36
- }
37
-
38
- } // This is the module that will be used to anchor all client references to.
39
- // I.e. it will have all the client files as async deps from this point on.
40
- // We use the Flight client implementation because you can't get to these
41
- // without the client runtime so it's the first time in the loading sequence
42
- // you might want them.
43
-
44
-
45
- var clientImportName = 'react-server-dom-webpack/client';
46
-
47
- var clientFileName = require.resolve('../client');
48
-
49
- var PLUGIN_NAME = 'React Server Plugin';
50
- class ReactFlightWebpackPlugin {
51
- constructor(options) {
52
- this.clientReferences = void 0;
53
- this.chunkName = void 0;
54
- this.manifestFilename = void 0;
55
-
56
- if (!options || typeof options.isServer !== 'boolean') {
57
- throw new Error(PLUGIN_NAME + ': You must specify the isServer option as a boolean.');
58
- }
59
-
60
- if (options.isServer) {
61
- throw new Error('TODO: Implement the server compiler.');
62
- }
63
-
64
- if (!options.clientReferences) {
65
- this.clientReferences = [{
66
- directory: '.',
67
- recursive: true,
68
- include: /\.(js|ts|jsx|tsx)$/
69
- }];
70
- } else if (typeof options.clientReferences === 'string' || !isArray(options.clientReferences)) {
71
- this.clientReferences = [options.clientReferences];
72
- } else {
73
- // $FlowFixMe[incompatible-type] found when upgrading Flow
74
- this.clientReferences = options.clientReferences;
75
- }
76
-
77
- if (typeof options.chunkName === 'string') {
78
- this.chunkName = options.chunkName;
79
-
80
- if (!/\[(index|request)\]/.test(this.chunkName)) {
81
- this.chunkName += '[index]';
82
- }
83
- } else {
84
- this.chunkName = 'client[index]';
85
- }
86
-
87
- this.manifestFilename = options.manifestFilename || 'react-client-manifest.json';
88
- }
89
-
90
- apply(compiler) {
91
- var _this = this;
92
-
93
- var resolvedClientReferences;
94
- var clientFileNameFound = false; // Find all client files on the file system
95
-
96
- compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, function (_ref, callback) {
97
- var contextModuleFactory = _ref.contextModuleFactory;
98
- var contextResolver = compiler.resolverFactory.get('context', {});
99
-
100
- _this.resolveAllClientFiles(compiler.context, contextResolver, compiler.inputFileSystem, contextModuleFactory, function (err, resolvedClientRefs) {
101
- if (err) {
102
- callback(err);
103
- return;
104
- }
105
-
106
- resolvedClientReferences = resolvedClientRefs;
107
- callback();
108
- });
109
- });
110
- compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function (compilation, _ref2) {
111
- var normalModuleFactory = _ref2.normalModuleFactory;
112
- compilation.dependencyFactories.set(ClientReferenceDependency, normalModuleFactory);
113
- compilation.dependencyTemplates.set(ClientReferenceDependency, new NullDependency.Template()); // $FlowFixMe[missing-local-annot]
114
-
115
- var handler = function (parser) {
116
- // We need to add all client references as dependency of something in the graph so
117
- // Webpack knows which entries need to know about the relevant chunks and include the
118
- // map in their runtime. The things that actually resolves the dependency is the Flight
119
- // client runtime. So we add them as a dependency of the Flight client runtime.
120
- // Anything that imports the runtime will be made aware of these chunks.
121
- parser.hooks.program.tap(PLUGIN_NAME, function () {
122
- var module = parser.state.module;
123
-
124
- if (module.resource !== clientFileName) {
125
- return;
126
- }
127
-
128
- clientFileNameFound = true;
129
-
130
- if (resolvedClientReferences) {
131
- // $FlowFixMe[incompatible-use] found when upgrading Flow
132
- for (var i = 0; i < resolvedClientReferences.length; i++) {
133
- // $FlowFixMe[incompatible-use] found when upgrading Flow
134
- var dep = resolvedClientReferences[i];
135
-
136
- var chunkName = _this.chunkName.replace(/\[index\]/g, '' + i).replace(/\[request\]/g, Template.toPath(dep.userRequest));
137
-
138
- var block = new webpack.AsyncDependenciesBlock({
139
- name: chunkName
140
- }, null, dep.request);
141
- block.addDependency(dep);
142
- module.addBlock(block);
143
- }
144
- }
145
- });
146
- };
147
-
148
- normalModuleFactory.hooks.parser.for('javascript/auto').tap('HarmonyModulesPlugin', handler);
149
- normalModuleFactory.hooks.parser.for('javascript/esm').tap('HarmonyModulesPlugin', handler);
150
- normalModuleFactory.hooks.parser.for('javascript/dynamic').tap('HarmonyModulesPlugin', handler);
151
- });
152
- compiler.hooks.make.tap(PLUGIN_NAME, function (compilation) {
153
- compilation.hooks.processAssets.tap({
154
- name: PLUGIN_NAME,
155
- stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
156
- }, function () {
157
- if (clientFileNameFound === false) {
158
- compilation.warnings.push(new webpack.WebpackError("Client runtime at " + clientImportName + " was not found. React Server Components module map file " + _this.manifestFilename + " was not created."));
159
- return;
160
- }
161
-
162
- var json = {};
163
- compilation.chunkGroups.forEach(function (chunkGroup) {
164
- var chunkIds = chunkGroup.chunks.map(function (c) {
165
- return c.id;
166
- }); // $FlowFixMe[missing-local-annot]
167
-
168
- function recordModule(id, module) {
169
- // TODO: Hook into deps instead of the target module.
170
- // That way we know by the type of dep whether to include.
171
- // It also resolves conflicts when the same module is in multiple chunks.
172
- if (!/\.(js|ts)x?$/.test(module.resource)) {
173
- return;
174
- }
175
-
176
- var moduleProvidedExports = compilation.moduleGraph.getExportsInfo(module).getProvidedExports();
177
- var moduleExports = {};
178
- ['', '*'].concat(Array.isArray(moduleProvidedExports) ? moduleProvidedExports : []).forEach(function (name) {
179
- moduleExports[name] = {
180
- id: id,
181
- chunks: chunkIds,
182
- name: name
183
- };
184
- });
185
- var href = url.pathToFileURL(module.resource).href;
186
-
187
- if (href !== undefined) {
188
- json[href] = moduleExports;
189
- }
190
- }
191
-
192
- chunkGroup.chunks.forEach(function (chunk) {
193
- var chunkModules = compilation.chunkGraph.getChunkModulesIterable(chunk);
194
- Array.from(chunkModules).forEach(function (module) {
195
- var moduleId = compilation.chunkGraph.getModuleId(module);
196
- recordModule(moduleId, module); // If this is a concatenation, register each child to the parent ID.
197
-
198
- if (module.modules) {
199
- module.modules.forEach(function (concatenatedMod) {
200
- recordModule(moduleId, concatenatedMod);
201
- });
202
- }
203
- });
204
- });
205
- });
206
- var output = JSON.stringify(json, null, 2);
207
- compilation.emitAsset(_this.manifestFilename, new webpack.sources.RawSource(output, false));
208
- });
209
- });
210
- } // This attempts to replicate the dynamic file path resolution used for other wildcard
211
- // resolution in Webpack is using.
212
-
213
-
214
- resolveAllClientFiles(context, contextResolver, fs, contextModuleFactory, callback) {
215
- asyncLib.map(this.clientReferences, function (clientReferencePath, cb) {
216
- if (typeof clientReferencePath === 'string') {
217
- cb(null, [new ClientReferenceDependency(clientReferencePath)]);
218
- return;
219
- }
220
-
221
- var clientReferenceSearch = clientReferencePath;
222
- contextResolver.resolve({}, context, clientReferencePath.directory, {}, function (err, resolvedDirectory) {
223
- if (err) return cb(err);
224
- var options = {
225
- resource: resolvedDirectory,
226
- resourceQuery: '',
227
- recursive: clientReferenceSearch.recursive === undefined ? true : clientReferenceSearch.recursive,
228
- regExp: clientReferenceSearch.include,
229
- include: undefined,
230
- exclude: clientReferenceSearch.exclude
231
- };
232
- contextModuleFactory.resolveDependencies(fs, options, function (err2, deps) {
233
- if (err2) return cb(err2);
234
- var clientRefDeps = deps.map(function (dep) {
235
- // use userRequest instead of request. request always end with undefined which is wrong
236
- var request = path.join(resolvedDirectory, dep.userRequest);
237
- var clientRefDep = new ClientReferenceDependency(request);
238
- clientRefDep.userRequest = dep.userRequest;
239
- return clientRefDep;
240
- });
241
- cb(null, clientRefDeps);
242
- });
243
- });
244
- }, function (err, result) {
245
- if (err) return callback(err);
246
- var flat = [];
247
-
248
- for (var i = 0; i < result.length; i++) {
249
- // $FlowFixMe[method-unbinding]
250
- flat.push.apply(flat, result[i]);
251
- }
252
-
253
- callback(null, flat);
254
- });
255
- }
256
-
257
- }
258
-
259
- module.exports = ReactFlightWebpackPlugin;
13
+ 'use strict';var k=require("path"),l=require("url"),n=require("neo-async"),p=require("webpack/lib/dependencies/ModuleDependency"),q=require("webpack/lib/dependencies/NullDependency"),r=require("webpack/lib/Template"),t=require("webpack");const u=Array.isArray;class v extends p{constructor(a){super(a)}get type(){return"client-reference"}}const w=require.resolve("../client");
14
+ class x{constructor(a){this.manifestFilename=this.chunkName=this.clientReferences=void 0;if(!a||"boolean"!==typeof a.isServer)throw Error("React Server Plugin: You must specify the isServer option as a boolean.");if(a.isServer)throw Error("TODO: Implement the server compiler.");a.clientReferences?"string"!==typeof a.clientReferences&&u(a.clientReferences)?this.clientReferences=a.clientReferences:this.clientReferences=[a.clientReferences]:this.clientReferences=[{directory:".",recursive:!0,include:/\.(js|ts|jsx|tsx)$/}];
15
+ "string"===typeof a.chunkName?(this.chunkName=a.chunkName,/\[(index|request)\]/.test(this.chunkName)||(this.chunkName+="[index]")):this.chunkName="client[index]";this.manifestFilename=a.manifestFilename||"react-client-manifest.json"}apply(a){const e=this;let f,m=!1;a.hooks.beforeCompile.tapAsync("React Server Plugin",(c,b)=>{c=c.contextModuleFactory;const d=a.resolverFactory.get("context",{});e.resolveAllClientFiles(a.context,d,a.inputFileSystem,c,function(a,c){a?b(a):(f=c,b())})});a.hooks.thisCompilation.tap("React Server Plugin",
16
+ (a,b)=>{b=b.normalModuleFactory;a.dependencyFactories.set(v,b);a.dependencyTemplates.set(v,new q.Template);a=a=>{a.hooks.program.tap("React Server Plugin",()=>{const b=a.state.module;if(b.resource===w&&(m=!0,f))for(let a=0;a<f.length;a++){const g=f[a];var c=e.chunkName.replace(/\[index\]/g,""+a).replace(/\[request\]/g,r.toPath(g.userRequest));c=new t.AsyncDependenciesBlock({name:c},null,g.request);c.addDependency(g);b.addBlock(c)}})};b.hooks.parser.for("javascript/auto").tap("HarmonyModulesPlugin",
17
+ a);b.hooks.parser.for("javascript/esm").tap("HarmonyModulesPlugin",a);b.hooks.parser.for("javascript/dynamic").tap("HarmonyModulesPlugin",a)});a.hooks.make.tap("React Server Plugin",a=>{a.hooks.processAssets.tap({name:"React Server Plugin",stage:t.Compilation.PROCESS_ASSETS_STAGE_REPORT},function(){if(!1===m)a.warnings.push(new t.WebpackError("Client runtime at react-server-dom-webpack/client was not found. React Server Components module map file "+e.manifestFilename+" was not created."));else{var b=
18
+ {};a.chunkGroups.forEach(function(c){function d(c,h){if(/\.(js|ts)x?$/.test(h.resource)){var d=a.moduleGraph.getExportsInfo(h).getProvidedExports(),g={};["","*"].concat(Array.isArray(d)?d:[]).forEach(function(a){g[a]={id:c,chunks:e,name:a}});h=l.pathToFileURL(h.resource).href;void 0!==h&&(b[h]=g)}}const e=c.chunks.map(function(a){return a.id});c.chunks.forEach(function(b){b=a.chunkGraph.getChunkModulesIterable(b);Array.from(b).forEach(function(b){const c=a.chunkGraph.getModuleId(b);d(c,b);b.modules&&
19
+ b.modules.forEach(a=>{d(c,a)})})})});var c=JSON.stringify(b,null,2);a.emitAsset(e.manifestFilename,new t.sources.RawSource(c,!1))}})})}resolveAllClientFiles(a,e,f,m,c){n.map(this.clientReferences,(b,c)=>{"string"===typeof b?c(null,[new v(b)]):e.resolve({},a,b.directory,{},(a,d)=>{if(a)return c(a);m.resolveDependencies(f,{resource:d,resourceQuery:"",recursive:void 0===b.recursive?!0:b.recursive,regExp:b.include,include:void 0,exclude:b.exclude},(a,b)=>{if(a)return c(a);a=b.map(a=>{var b=k.join(d,a.userRequest);
20
+ b=new v(b);b.userRequest=a.userRequest;return b});c(null,a)})})},(a,d)=>{if(a)return c(a);a=[];for(let b=0;b<d.length;b++)a.push.apply(a,d[b]);c(null,a)})}}module.exports=x;
@@ -200,21 +200,25 @@ function processReferenceChunk(request, id, reference) {
200
200
  var row = id.toString(16) + ':' + json + '\n';
201
201
  return stringToChunk(row);
202
202
  }
203
- function processModuleChunk(request, id, moduleMetaData) {
204
- var json = stringify(moduleMetaData);
203
+ function processImportChunk(request, id, clientReferenceMetadata) {
204
+ var json = stringify(clientReferenceMetadata);
205
205
  var row = serializeRowHeader('I', id) + json + '\n';
206
206
  return stringToChunk(row);
207
207
  }
208
208
 
209
209
  // eslint-disable-next-line no-unused-vars
210
210
  var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
211
+ var SERVER_REFERENCE_TAG = Symbol.for('react.server.reference');
211
212
  function getClientReferenceKey(reference) {
212
213
  return reference.filepath + '#' + reference.name + (reference.async ? '#async' : '');
213
214
  }
214
215
  function isClientReference(reference) {
215
216
  return reference.$$typeof === CLIENT_REFERENCE_TAG;
216
217
  }
217
- function resolveModuleMetaData(config, clientReference) {
218
+ function isServerReference(reference) {
219
+ return reference.$$typeof === SERVER_REFERENCE_TAG;
220
+ }
221
+ function resolveClientReferenceMetadata(config, clientReference) {
218
222
  var resolvedModuleData = config[clientReference.filepath][clientReference.name];
219
223
 
220
224
  if (clientReference.async) {
@@ -228,6 +232,13 @@ function resolveModuleMetaData(config, clientReference) {
228
232
  return resolvedModuleData;
229
233
  }
230
234
  }
235
+ function resolveServerReferenceMetadata(config, serverReference) {
236
+ return {
237
+ id: serverReference.$$filepath,
238
+ name: serverReference.$$name,
239
+ bound: Promise.resolve(serverReference.$$bound)
240
+ };
241
+ }
231
242
 
232
243
  // ATTENTION
233
244
  // When adding new symbols to this file,
@@ -552,7 +563,7 @@ function isArray(a) {
552
563
  // Run `yarn generate-inline-fizz-runtime` to generate.
553
564
  var clientRenderBoundary = '$RX=function(b,c,d,e){var a=document.getElementById(b);a&&(b=a.previousSibling,b.data="$!",a=a.dataset,c&&(a.dgst=c),d&&(a.msg=d),e&&(a.stck=e),b._reactRetry&&b._reactRetry())};';
554
565
  var completeBoundary = '$RC=function(b,c,e){c=document.getElementById(c);c.parentNode.removeChild(c);var a=document.getElementById(b);if(a){b=a.previousSibling;if(e)b.data="$!",a.setAttribute("data-dgst",e);else{e=b.parentNode;a=b.nextSibling;var f=0;do{if(a&&8===a.nodeType){var d=a.data;if("/$"===d)if(0===f)break;else f--;else"$"!==d&&"$?"!==d&&"$!"!==d||f++}d=a.nextSibling;e.removeChild(a);a=d}while(a);for(;c.firstChild;)e.insertBefore(c.firstChild,a);b.data="$"}b._reactRetry&&b._reactRetry()}};';
555
- var completeBoundaryWithStyles = '$RM=new Map;\n$RR=function(p,q,v){function r(l){this.s=l}for(var t=$RC,u=$RM,m=new Map,n=document,g,e,f=n.querySelectorAll("link[data-precedence],style[data-precedence]"),d=0;e=f[d++];)m.set(e.dataset.precedence,g=e);e=0;f=[];for(var c,h,b,a;c=v[e++];){var k=0;h=c[k++];if(b=u.get(h))"l"!==b.s&&f.push(b);else{a=n.createElement("link");a.href=h;a.rel="stylesheet";for(a.dataset.precedence=d=c[k++];b=c[k++];)a.setAttribute(b,c[k++]);b=a._p=new Promise(function(l,w){a.onload=l;a.onerror=w});b.then(r.bind(b,\n"l"),r.bind(b,"e"));u.set(h,b);f.push(b);c=m.get(d)||g;c===g&&(g=a);m.set(d,a);c?c.parentNode.insertBefore(a,c.nextSibling):(d=n.head,d.insertBefore(a,d.firstChild))}}Promise.all(f).then(t.bind(null,p,q,""),t.bind(null,p,q,"Resource failed to load"))};';
566
+ var completeBoundaryWithStyles = '$RM=new Map;\n$RR=function(p,q,w){function r(l){this.s=l}for(var t=$RC,m=$RM,u=new Map,n=new Map,g=document,h,e,f=g.querySelectorAll("template[data-precedence]"),c=0;e=f[c++];){for(var b=e.content.firstChild;b;b=b.nextSibling)u.set(b.getAttribute("data-href"),b);e.parentNode.removeChild(e)}f=g.querySelectorAll("link[data-precedence],style[data-precedence]");for(c=0;e=f[c++];)m.set(e.getAttribute("STYLE"===e.nodeName?"data-href":"href"),e),n.set(e.dataset.precedence,h=e);e=0;f=[];for(var d,\nv,a;d=w[e++];){var k=0;b=d[k++];if(!(a=m.get(b))){if(a=u.get(b))c=a.getAttribute("data-precedence");else{a=g.createElement("link");a.href=b;a.rel="stylesheet";for(a.dataset.precedence=c=d[k++];v=d[k++];)a.setAttribute(v,d[k++]);d=a._p=new Promise(function(l,x){a.onload=l;a.onerror=x});d.then(r.bind(d,"l"),r.bind(d,"e"))}m.set(b,a);b=n.get(c)||h;b===h&&(h=a);n.set(c,a);b?b.parentNode.insertBefore(a,b.nextSibling):(c=g.head,c.insertBefore(a,c.firstChild))}d=a._p;c=a.getAttribute("media");!d||"l"===\nd.s||c&&!matchMedia(c).matches||f.push(d)}Promise.all(f).then(t.bind(null,p,q,""),t.bind(null,p,q,"Resource failed to load"))};';
556
567
  var completeSegment = '$RS=function(a,b){a=document.getElementById(a);b=document.getElementById(b);for(a.parentNode.removeChild(a);a.firstChild;)b.parentNode.insertBefore(a.firstChild,b);b.parentNode.removeChild(b)};';
557
568
 
558
569
  var ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
@@ -633,10 +644,10 @@ var completeSegmentScript2 = stringToPrecomputedChunk('","');
633
644
  var completeSegmentScriptEnd = stringToPrecomputedChunk('")</script>');
634
645
  var completeSegmentData1 = stringToPrecomputedChunk('<template data-rsi="" data-sid="');
635
646
  var completeSegmentData2 = stringToPrecomputedChunk('" data-pid="');
636
- var completeBoundaryScript1Full = stringToPrecomputedChunk(completeBoundary + ';$RC("');
647
+ var completeBoundaryScript1Full = stringToPrecomputedChunk(completeBoundary + '$RC("');
637
648
  var completeBoundaryScript1Partial = stringToPrecomputedChunk('$RC("');
638
- var completeBoundaryWithStylesScript1FullBoth = stringToPrecomputedChunk(completeBoundary + ';' + completeBoundaryWithStyles + ';$RR("');
639
- var completeBoundaryWithStylesScript1FullPartial = stringToPrecomputedChunk(completeBoundaryWithStyles + ';$RR("');
649
+ var completeBoundaryWithStylesScript1FullBoth = stringToPrecomputedChunk(completeBoundary + completeBoundaryWithStyles + '$RR("');
650
+ var completeBoundaryWithStylesScript1FullPartial = stringToPrecomputedChunk(completeBoundaryWithStyles + '$RR("');
640
651
  var completeBoundaryWithStylesScript1Partial = stringToPrecomputedChunk('$RR("');
641
652
  var completeBoundaryScript2 = stringToPrecomputedChunk('","');
642
653
  var completeBoundaryScript3a = stringToPrecomputedChunk('",');
@@ -656,6 +667,8 @@ var clientRenderData2 = stringToPrecomputedChunk('" data-dgst="');
656
667
  var clientRenderData3 = stringToPrecomputedChunk('" data-msg="');
657
668
  var clientRenderData4 = stringToPrecomputedChunk('" data-stck="');
658
669
 
670
+ var styleTagTemplateOpen = stringToPrecomputedChunk('<template data-precedence="">');
671
+ var styleTagTemplateClose = stringToPrecomputedChunk('</template>'); // Tracks whether we wrote any late style tags. We use this to determine
659
672
  var precedencePlaceholderStart = stringToPrecomputedChunk('<style data-precedence="');
660
673
  var precedencePlaceholderEnd = stringToPrecomputedChunk('"></style>');
661
674
 
@@ -1182,11 +1195,12 @@ function createRequest(model, bundlerConfig, onError, context, identifierPrefix)
1182
1195
  pendingChunks: 0,
1183
1196
  abortableTasks: abortSet,
1184
1197
  pingedTasks: pingedTasks,
1185
- completedModuleChunks: [],
1198
+ completedImportChunks: [],
1186
1199
  completedJSONChunks: [],
1187
1200
  completedErrorChunks: [],
1188
1201
  writtenSymbols: new Map(),
1189
- writtenModules: new Map(),
1202
+ writtenClientReferences: new Map(),
1203
+ writtenServerReferences: new Map(),
1190
1204
  writtenProviders: new Map(),
1191
1205
  identifierPrefix: identifierPrefix || '',
1192
1206
  identifierCount: 1,
@@ -1497,6 +1511,10 @@ function serializePromiseID(id) {
1497
1511
  return '$@' + id.toString(16);
1498
1512
  }
1499
1513
 
1514
+ function serializeServerReferenceID(id) {
1515
+ return '$F' + id.toString(16);
1516
+ }
1517
+
1500
1518
  function serializeSymbolReference(name) {
1501
1519
  return '$S' + name;
1502
1520
  }
@@ -1505,10 +1523,10 @@ function serializeProviderReference(name) {
1505
1523
  return '$P' + name;
1506
1524
  }
1507
1525
 
1508
- function serializeClientReference(request, parent, key, moduleReference) {
1509
- var moduleKey = getClientReferenceKey(moduleReference);
1510
- var writtenModules = request.writtenModules;
1511
- var existingId = writtenModules.get(moduleKey);
1526
+ function serializeClientReference(request, parent, key, clientReference) {
1527
+ var clientReferenceKey = getClientReferenceKey(clientReference);
1528
+ var writtenClientReferences = request.writtenClientReferences;
1529
+ var existingId = writtenClientReferences.get(clientReferenceKey);
1512
1530
 
1513
1531
  if (existingId !== undefined) {
1514
1532
  if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
@@ -1524,11 +1542,11 @@ function serializeClientReference(request, parent, key, moduleReference) {
1524
1542
  }
1525
1543
 
1526
1544
  try {
1527
- var moduleMetaData = resolveModuleMetaData(request.bundlerConfig, moduleReference);
1545
+ var clientReferenceMetadata = resolveClientReferenceMetadata(request.bundlerConfig, clientReference);
1528
1546
  request.pendingChunks++;
1529
- var moduleId = request.nextChunkId++;
1530
- emitModuleChunk(request, moduleId, moduleMetaData);
1531
- writtenModules.set(moduleKey, moduleId);
1547
+ var importId = request.nextChunkId++;
1548
+ emitImportChunk(request, importId, clientReferenceMetadata);
1549
+ writtenClientReferences.set(clientReferenceKey, importId);
1532
1550
 
1533
1551
  if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1534
1552
  // If we're encoding the "type" of an element, we can refer
@@ -1536,10 +1554,10 @@ function serializeClientReference(request, parent, key, moduleReference) {
1536
1554
  // knows how to deal with lazy values. This lets us suspend
1537
1555
  // on this component rather than its parent until the code has
1538
1556
  // loaded.
1539
- return serializeLazyID(moduleId);
1557
+ return serializeLazyID(importId);
1540
1558
  }
1541
1559
 
1542
- return serializeByValueID(moduleId);
1560
+ return serializeByValueID(importId);
1543
1561
  } catch (x) {
1544
1562
  request.pendingChunks++;
1545
1563
  var errorId = request.nextChunkId++;
@@ -1557,6 +1575,24 @@ function serializeClientReference(request, parent, key, moduleReference) {
1557
1575
  }
1558
1576
  }
1559
1577
 
1578
+ function serializeServerReference(request, parent, key, serverReference) {
1579
+ var writtenServerReferences = request.writtenServerReferences;
1580
+ var existingId = writtenServerReferences.get(serverReference);
1581
+
1582
+ if (existingId !== undefined) {
1583
+ return serializeServerReferenceID(existingId);
1584
+ }
1585
+
1586
+ var serverReferenceMetadata = resolveServerReferenceMetadata(request.bundlerConfig, serverReference);
1587
+ request.pendingChunks++;
1588
+ var metadataId = request.nextChunkId++; // We assume that this object doesn't suspend.
1589
+
1590
+ var processedChunk = processModelChunk(request, metadataId, serverReferenceMetadata);
1591
+ request.completedJSONChunks.push(processedChunk);
1592
+ writtenServerReferences.set(serverReference, metadataId);
1593
+ return serializeServerReferenceID(metadataId);
1594
+ }
1595
+
1560
1596
  function escapeStringValue(value) {
1561
1597
  if (value[0] === '$') {
1562
1598
  // We need to escape $ or @ prefixed strings since we use those to encode
@@ -1985,7 +2021,7 @@ function resolveModelToJSON(request, parent, key, value) {
1985
2021
 
1986
2022
  if (typeof value === 'object') {
1987
2023
  if (isClientReference(value)) {
1988
- return serializeClientReference(request, parent, key, value);
2024
+ return serializeClientReference(request, parent, key, value); // $FlowFixMe[method-unbinding]
1989
2025
  } else if (typeof value.then === 'function') {
1990
2026
  // We assume that any object with a .then property is a "Thenable" type,
1991
2027
  // or a Promise type. Either of which can be represented by a Promise.
@@ -2049,10 +2085,14 @@ function resolveModelToJSON(request, parent, key, value) {
2049
2085
  return serializeClientReference(request, parent, key, value);
2050
2086
  }
2051
2087
 
2088
+ if (isServerReference(value)) {
2089
+ return serializeServerReference(request, parent, key, value);
2090
+ }
2091
+
2052
2092
  if (/^on[A-Z]/.test(key)) {
2053
2093
  throw new Error('Event handlers cannot be passed to Client Component props.' + describeObjectForErrorMessage(parent, key) + '\nIf you need interactivity, consider converting part of this to a Client Component.');
2054
2094
  } else {
2055
- throw new Error('Functions cannot be passed directly to Client Components ' + "because they're not serializable." + describeObjectForErrorMessage(parent, key));
2095
+ throw new Error('Functions cannot be passed directly to Client Components ' + 'unless you explicitly expose it by marking it with "use server".' + describeObjectForErrorMessage(parent, key));
2056
2096
  }
2057
2097
  }
2058
2098
 
@@ -2144,15 +2184,15 @@ function emitErrorChunkDev(request, id, digest, message, stack) {
2144
2184
  request.completedErrorChunks.push(processedChunk);
2145
2185
  }
2146
2186
 
2147
- function emitModuleChunk(request, id, moduleMetaData) {
2148
- var processedChunk = processModuleChunk(request, id, moduleMetaData);
2149
- request.completedModuleChunks.push(processedChunk);
2187
+ function emitImportChunk(request, id, clientReferenceMetadata) {
2188
+ var processedChunk = processImportChunk(request, id, clientReferenceMetadata);
2189
+ request.completedImportChunks.push(processedChunk);
2150
2190
  }
2151
2191
 
2152
2192
  function emitSymbolChunk(request, id, name) {
2153
2193
  var symbolReference = serializeSymbolReference(name);
2154
2194
  var processedChunk = processReferenceChunk(request, id, symbolReference);
2155
- request.completedModuleChunks.push(processedChunk);
2195
+ request.completedImportChunks.push(processedChunk);
2156
2196
  }
2157
2197
 
2158
2198
  function emitProviderChunk(request, id, contextName) {
@@ -2275,12 +2315,12 @@ function flushCompletedChunks(request, destination) {
2275
2315
  try {
2276
2316
  // We emit module chunks first in the stream so that
2277
2317
  // they can be preloaded as early as possible.
2278
- var moduleChunks = request.completedModuleChunks;
2318
+ var importsChunks = request.completedImportChunks;
2279
2319
  var i = 0;
2280
2320
 
2281
- for (; i < moduleChunks.length; i++) {
2321
+ for (; i < importsChunks.length; i++) {
2282
2322
  request.pendingChunks--;
2283
- var chunk = moduleChunks[i];
2323
+ var chunk = importsChunks[i];
2284
2324
  var keepWriting = writeChunkAndReturn(destination, chunk);
2285
2325
 
2286
2326
  if (!keepWriting) {
@@ -2290,7 +2330,7 @@ function flushCompletedChunks(request, destination) {
2290
2330
  }
2291
2331
  }
2292
2332
 
2293
- moduleChunks.splice(0, i); // Next comes model data.
2333
+ importsChunks.splice(0, i); // Next comes model data.
2294
2334
 
2295
2335
  var jsonChunks = request.completedJSONChunks;
2296
2336
  i = 0;