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.
- package/cjs/react-server-dom-webpack-client.development.js +96 -39
- package/cjs/react-server-dom-webpack-client.production.min.js +11 -9
- package/cjs/react-server-dom-webpack-node-register.js +9 -273
- package/cjs/react-server-dom-webpack-plugin.js +8 -247
- package/cjs/react-server-dom-webpack-server.browser.development.js +69 -29
- package/cjs/react-server-dom-webpack-server.browser.production.min.js +42 -40
- package/cjs/react-server-dom-webpack-server.edge.development.js +69 -29
- package/cjs/react-server-dom-webpack-server.edge.production.min.js +44 -43
- package/cjs/react-server-dom-webpack-server.node.development.js +69 -29
- package/cjs/react-server-dom-webpack-server.node.production.min.js +46 -45
- package/esm/react-server-dom-webpack-node-loader.js +195 -116
- package/package.json +3 -3
- package/umd/react-server-dom-webpack-client.development.js +96 -39
- package/umd/react-server-dom-webpack-client.production.min.js +13 -12
- package/umd/react-server-dom-webpack-server.browser.development.js +69 -29
- package/umd/react-server-dom-webpack-server.browser.production.min.js +40 -39
@@ -8,58 +8,13 @@
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
9
9
|
*/
|
10
10
|
|
11
|
-
import { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } from 'react';
|
12
11
|
import { parse } from 'acorn';
|
13
12
|
|
14
|
-
|
13
|
+
const assign = Object.assign;
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
// they are left as they are instead.
|
20
|
-
|
21
|
-
function warn(format) {
|
22
|
-
{
|
23
|
-
{
|
24
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
25
|
-
args[_key - 1] = arguments[_key];
|
26
|
-
}
|
27
|
-
|
28
|
-
printWarning('warn', format, args);
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
function printWarning(level, format, args) {
|
34
|
-
// When changing this logic, you might want to also
|
35
|
-
// update consoleWithStackDev.www.js as well.
|
36
|
-
{
|
37
|
-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
38
|
-
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
39
|
-
|
40
|
-
if (stack !== '') {
|
41
|
-
format += '%s';
|
42
|
-
args = args.concat([stack]);
|
43
|
-
} // eslint-disable-next-line react-internal/safe-string-coercion
|
44
|
-
|
45
|
-
|
46
|
-
var argsWithFormat = args.map(function (item) {
|
47
|
-
return String(item);
|
48
|
-
}); // Careful: RN currently depends on this prefix
|
49
|
-
|
50
|
-
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
51
|
-
// breaks IE9: https://github.com/facebook/react/issues/13610
|
52
|
-
// eslint-disable-next-line react-internal/no-production-logging
|
53
|
-
|
54
|
-
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
var assign = Object.assign;
|
59
|
-
|
60
|
-
var warnedAboutConditionsFlag = false;
|
61
|
-
var stashedGetSource = null;
|
62
|
-
var stashedResolve = null;
|
15
|
+
let warnedAboutConditionsFlag = false;
|
16
|
+
let stashedGetSource = null;
|
17
|
+
let stashedResolve = null;
|
63
18
|
async function resolve(specifier, context, defaultResolve) {
|
64
19
|
// We stash this in case we end up needing to resolve export * statements later.
|
65
20
|
stashedResolve = defaultResolve;
|
@@ -72,7 +27,7 @@ async function resolve(specifier, context, defaultResolve) {
|
|
72
27
|
if (!warnedAboutConditionsFlag) {
|
73
28
|
warnedAboutConditionsFlag = true; // eslint-disable-next-line react-internal/no-production-logging
|
74
29
|
|
75
|
-
warn('You did not run Node.js with the `--conditions react-server` flag. ' + 'Any "react-server" override will only work with ESM imports.');
|
30
|
+
console.warn('You did not run Node.js with the `--conditions react-server` flag. ' + 'Any "react-server" override will only work with ESM imports.');
|
76
31
|
}
|
77
32
|
}
|
78
33
|
|
@@ -84,6 +39,116 @@ async function getSource(url, context, defaultGetSource) {
|
|
84
39
|
return defaultGetSource(url, context, defaultGetSource);
|
85
40
|
}
|
86
41
|
|
42
|
+
function addLocalExportedNames(names, node) {
|
43
|
+
switch (node.type) {
|
44
|
+
case 'Identifier':
|
45
|
+
names.set(node.name, node.name);
|
46
|
+
return;
|
47
|
+
|
48
|
+
case 'ObjectPattern':
|
49
|
+
for (let i = 0; i < node.properties.length; i++) addLocalExportedNames(names, node.properties[i]);
|
50
|
+
|
51
|
+
return;
|
52
|
+
|
53
|
+
case 'ArrayPattern':
|
54
|
+
for (let i = 0; i < node.elements.length; i++) {
|
55
|
+
const element = node.elements[i];
|
56
|
+
if (element) addLocalExportedNames(names, element);
|
57
|
+
}
|
58
|
+
|
59
|
+
return;
|
60
|
+
|
61
|
+
case 'Property':
|
62
|
+
addLocalExportedNames(names, node.value);
|
63
|
+
return;
|
64
|
+
|
65
|
+
case 'AssignmentPattern':
|
66
|
+
addLocalExportedNames(names, node.left);
|
67
|
+
return;
|
68
|
+
|
69
|
+
case 'RestElement':
|
70
|
+
addLocalExportedNames(names, node.argument);
|
71
|
+
return;
|
72
|
+
|
73
|
+
case 'ParenthesizedExpression':
|
74
|
+
addLocalExportedNames(names, node.expression);
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
function transformServerModule(source, body, url, loader) {
|
80
|
+
// If the same local name is exported more than once, we only need one of the names.
|
81
|
+
const localNames = new Map();
|
82
|
+
const localTypes = new Map();
|
83
|
+
|
84
|
+
for (let i = 0; i < body.length; i++) {
|
85
|
+
const node = body[i];
|
86
|
+
|
87
|
+
switch (node.type) {
|
88
|
+
case 'ExportAllDeclaration':
|
89
|
+
// If export * is used, the other file needs to explicitly opt into "use server" too.
|
90
|
+
break;
|
91
|
+
|
92
|
+
case 'ExportDefaultDeclaration':
|
93
|
+
if (node.declaration.type === 'Identifier') {
|
94
|
+
localNames.set(node.declaration.name, 'default');
|
95
|
+
} else if (node.declaration.type === 'FunctionDeclaration') {
|
96
|
+
if (node.declaration.id) {
|
97
|
+
localNames.set(node.declaration.id.name, 'default');
|
98
|
+
localTypes.set(node.declaration.id.name, 'function');
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
continue;
|
103
|
+
|
104
|
+
case 'ExportNamedDeclaration':
|
105
|
+
if (node.declaration) {
|
106
|
+
if (node.declaration.type === 'VariableDeclaration') {
|
107
|
+
const declarations = node.declaration.declarations;
|
108
|
+
|
109
|
+
for (let j = 0; j < declarations.length; j++) {
|
110
|
+
addLocalExportedNames(localNames, declarations[j].id);
|
111
|
+
}
|
112
|
+
} else {
|
113
|
+
const name = node.declaration.id.name;
|
114
|
+
localNames.set(name, name);
|
115
|
+
|
116
|
+
if (node.declaration.type === 'FunctionDeclaration') {
|
117
|
+
localTypes.set(name, 'function');
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
if (node.specifiers) {
|
123
|
+
const specifiers = node.specifiers;
|
124
|
+
|
125
|
+
for (let j = 0; j < specifiers.length; j++) {
|
126
|
+
const specifier = specifiers[j];
|
127
|
+
localNames.set(specifier.local.name, specifier.exported.name);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
continue;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
let newSrc = source + '\n\n;';
|
136
|
+
localNames.forEach(function (exported, local) {
|
137
|
+
if (localTypes.get(local) !== 'function') {
|
138
|
+
// We first check if the export is a function and if so annotate it.
|
139
|
+
newSrc += 'if (typeof ' + local + ' === "function") ';
|
140
|
+
}
|
141
|
+
|
142
|
+
newSrc += 'Object.defineProperties(' + local + ',{';
|
143
|
+
newSrc += '$$typeof: {value: Symbol.for("react.server.reference")},';
|
144
|
+
newSrc += '$$filepath: {value: ' + JSON.stringify(url) + '},';
|
145
|
+
newSrc += '$$name: { value: ' + JSON.stringify(exported) + '},';
|
146
|
+
newSrc += '$$bound: { value: [] }';
|
147
|
+
newSrc += '});\n';
|
148
|
+
});
|
149
|
+
return newSrc;
|
150
|
+
}
|
151
|
+
|
87
152
|
function addExportNames(names, node) {
|
88
153
|
switch (node.type) {
|
89
154
|
case 'Identifier':
|
@@ -91,15 +156,13 @@ function addExportNames(names, node) {
|
|
91
156
|
return;
|
92
157
|
|
93
158
|
case 'ObjectPattern':
|
94
|
-
for (
|
95
|
-
addExportNames(names, node.properties[i]);
|
96
|
-
}
|
159
|
+
for (let i = 0; i < node.properties.length; i++) addExportNames(names, node.properties[i]);
|
97
160
|
|
98
161
|
return;
|
99
162
|
|
100
163
|
case 'ArrayPattern':
|
101
|
-
for (
|
102
|
-
|
164
|
+
for (let i = 0; i < node.elements.length; i++) {
|
165
|
+
const element = node.elements[i];
|
103
166
|
if (element) addExportNames(names, element);
|
104
167
|
}
|
105
168
|
|
@@ -129,21 +192,21 @@ function resolveClientImport(specifier, parentURL) {
|
|
129
192
|
// This resolution algorithm will not necessarily have the same configuration
|
130
193
|
// as the actual client loader. It should mostly work and if it doesn't you can
|
131
194
|
// always convert to explicit exported names instead.
|
132
|
-
|
195
|
+
const conditions = ['node', 'import'];
|
133
196
|
|
134
197
|
if (stashedResolve === null) {
|
135
198
|
throw new Error('Expected resolve to have been called before transformSource');
|
136
199
|
}
|
137
200
|
|
138
201
|
return stashedResolve(specifier, {
|
139
|
-
conditions
|
140
|
-
parentURL
|
202
|
+
conditions,
|
203
|
+
parentURL
|
141
204
|
}, stashedResolve);
|
142
205
|
}
|
143
206
|
|
144
207
|
async function parseExportNamesInto(body, names, parentURL, loader) {
|
145
|
-
for (
|
146
|
-
|
208
|
+
for (let i = 0; i < body.length; i++) {
|
209
|
+
const node = body[i];
|
147
210
|
|
148
211
|
switch (node.type) {
|
149
212
|
case 'ExportAllDeclaration':
|
@@ -151,25 +214,25 @@ async function parseExportNamesInto(body, names, parentURL, loader) {
|
|
151
214
|
addExportNames(names, node.exported);
|
152
215
|
continue;
|
153
216
|
} else {
|
154
|
-
|
155
|
-
|
217
|
+
const _await$resolveClientI = await resolveClientImport(node.source.value, parentURL),
|
218
|
+
url = _await$resolveClientI.url;
|
156
219
|
|
157
|
-
|
220
|
+
const _await$loader = await loader(url, {
|
158
221
|
format: 'module',
|
159
222
|
conditions: [],
|
160
223
|
importAssertions: {}
|
161
224
|
}, loader),
|
162
|
-
|
225
|
+
source = _await$loader.source;
|
163
226
|
|
164
227
|
if (typeof source !== 'string') {
|
165
228
|
throw new Error('Expected the transformed source to be a string.');
|
166
229
|
}
|
167
230
|
|
168
|
-
|
231
|
+
const _acorn$parse = parse(source, {
|
169
232
|
ecmaVersion: '2019',
|
170
233
|
sourceType: 'module'
|
171
234
|
}),
|
172
|
-
|
235
|
+
childBody = _acorn$parse.body;
|
173
236
|
|
174
237
|
await parseExportNamesInto(childBody, names, url, loader);
|
175
238
|
continue;
|
@@ -182,9 +245,9 @@ async function parseExportNamesInto(body, names, parentURL, loader) {
|
|
182
245
|
case 'ExportNamedDeclaration':
|
183
246
|
if (node.declaration) {
|
184
247
|
if (node.declaration.type === 'VariableDeclaration') {
|
185
|
-
|
248
|
+
const declarations = node.declaration.declarations;
|
186
249
|
|
187
|
-
for (
|
250
|
+
for (let j = 0; j < declarations.length; j++) {
|
188
251
|
addExportNames(names, declarations[j].id);
|
189
252
|
}
|
190
253
|
} else {
|
@@ -193,10 +256,10 @@ async function parseExportNamesInto(body, names, parentURL, loader) {
|
|
193
256
|
}
|
194
257
|
|
195
258
|
if (node.specifiers) {
|
196
|
-
|
259
|
+
const specifiers = node.specifiers;
|
197
260
|
|
198
|
-
for (
|
199
|
-
addExportNames(names, specifiers[
|
261
|
+
for (let j = 0; j < specifiers.length; j++) {
|
262
|
+
addExportNames(names, specifiers[j].exported);
|
200
263
|
}
|
201
264
|
}
|
202
265
|
|
@@ -205,44 +268,13 @@ async function parseExportNamesInto(body, names, parentURL, loader) {
|
|
205
268
|
}
|
206
269
|
}
|
207
270
|
|
208
|
-
async function transformClientModule(
|
209
|
-
|
210
|
-
// bother parsing.
|
211
|
-
|
212
|
-
if (source.indexOf('use client') === -1) {
|
213
|
-
return source;
|
214
|
-
}
|
215
|
-
|
216
|
-
var _acorn$parse2 = parse(source, {
|
217
|
-
ecmaVersion: '2019',
|
218
|
-
sourceType: 'module'
|
219
|
-
}),
|
220
|
-
body = _acorn$parse2.body;
|
221
|
-
|
222
|
-
var useClient = false;
|
223
|
-
|
224
|
-
for (var i = 0; i < body.length; i++) {
|
225
|
-
var node = body[i];
|
226
|
-
|
227
|
-
if (node.type !== 'ExpressionStatement' || !node.directive) {
|
228
|
-
break;
|
229
|
-
}
|
230
|
-
|
231
|
-
if (node.directive === 'use client') {
|
232
|
-
useClient = true;
|
233
|
-
break;
|
234
|
-
}
|
235
|
-
}
|
236
|
-
|
237
|
-
if (!useClient) {
|
238
|
-
return source;
|
239
|
-
}
|
240
|
-
|
271
|
+
async function transformClientModule(body, url, loader) {
|
272
|
+
const names = [];
|
241
273
|
await parseExportNamesInto(body, names, url, loader);
|
242
|
-
|
274
|
+
let newSrc = "const CLIENT_REFERENCE = Symbol.for('react.client.reference');\n";
|
243
275
|
|
244
|
-
for (
|
245
|
-
|
276
|
+
for (let i = 0; i < names.length; i++) {
|
277
|
+
const name = names[i];
|
246
278
|
|
247
279
|
if (name === 'default') {
|
248
280
|
newSrc += 'export default ';
|
@@ -270,14 +302,14 @@ async function loadClientImport(url, defaultTransformSource) {
|
|
270
302
|
} // TODO: Validate that this is another module by calling getFormat.
|
271
303
|
|
272
304
|
|
273
|
-
|
305
|
+
const _await$stashedGetSour = await stashedGetSource(url, {
|
274
306
|
format: 'module'
|
275
307
|
}, stashedGetSource),
|
276
|
-
|
308
|
+
source = _await$stashedGetSour.source;
|
277
309
|
|
278
|
-
|
310
|
+
const result = await defaultTransformSource(source, {
|
279
311
|
format: 'module',
|
280
|
-
url
|
312
|
+
url
|
281
313
|
}, defaultTransformSource);
|
282
314
|
return {
|
283
315
|
format: 'module',
|
@@ -285,17 +317,64 @@ async function loadClientImport(url, defaultTransformSource) {
|
|
285
317
|
};
|
286
318
|
}
|
287
319
|
|
320
|
+
async function transformModuleIfNeeded(source, url, loader) {
|
321
|
+
// Do a quick check for the exact string. If it doesn't exist, don't
|
322
|
+
// bother parsing.
|
323
|
+
if (source.indexOf('use client') === -1 && source.indexOf('use server') === -1) {
|
324
|
+
return source;
|
325
|
+
}
|
326
|
+
|
327
|
+
const _acorn$parse2 = parse(source, {
|
328
|
+
ecmaVersion: '2019',
|
329
|
+
sourceType: 'module'
|
330
|
+
}),
|
331
|
+
body = _acorn$parse2.body;
|
332
|
+
|
333
|
+
let useClient = false;
|
334
|
+
let useServer = false;
|
335
|
+
|
336
|
+
for (let i = 0; i < body.length; i++) {
|
337
|
+
const node = body[i];
|
338
|
+
|
339
|
+
if (node.type !== 'ExpressionStatement' || !node.directive) {
|
340
|
+
break;
|
341
|
+
}
|
342
|
+
|
343
|
+
if (node.directive === 'use client') {
|
344
|
+
useClient = true;
|
345
|
+
}
|
346
|
+
|
347
|
+
if (node.directive === 'use server') {
|
348
|
+
useServer = true;
|
349
|
+
}
|
350
|
+
}
|
351
|
+
|
352
|
+
if (!useClient && !useServer) {
|
353
|
+
return source;
|
354
|
+
}
|
355
|
+
|
356
|
+
if (useClient && useServer) {
|
357
|
+
throw new Error('Cannot have both "use client" and "use server" directives in the same file.');
|
358
|
+
}
|
359
|
+
|
360
|
+
if (useClient) {
|
361
|
+
return transformClientModule(body, url, loader);
|
362
|
+
}
|
363
|
+
|
364
|
+
return transformServerModule(source, body, url);
|
365
|
+
}
|
366
|
+
|
288
367
|
async function transformSource(source, context, defaultTransformSource) {
|
289
|
-
|
368
|
+
const transformed = await defaultTransformSource(source, context, defaultTransformSource);
|
290
369
|
|
291
370
|
if (context.format === 'module') {
|
292
|
-
|
371
|
+
const transformedSource = transformed.source;
|
293
372
|
|
294
373
|
if (typeof transformedSource !== 'string') {
|
295
374
|
throw new Error('Expected source to have been transformed to a string.');
|
296
375
|
}
|
297
376
|
|
298
|
-
|
377
|
+
const newSrc = await transformModuleIfNeeded(transformedSource, context.url, (url, ctx, defaultLoad) => {
|
299
378
|
return loadClientImport(url, defaultTransformSource);
|
300
379
|
});
|
301
380
|
return {
|
@@ -307,13 +386,13 @@ async function transformSource(source, context, defaultTransformSource) {
|
|
307
386
|
}
|
308
387
|
async function load(url, context, defaultLoad) {
|
309
388
|
if (context.format === 'module') {
|
310
|
-
|
389
|
+
const result = await defaultLoad(url, context, defaultLoad);
|
311
390
|
|
312
391
|
if (typeof result.source !== 'string') {
|
313
392
|
throw new Error('Expected source to have been loaded into a string.');
|
314
393
|
}
|
315
394
|
|
316
|
-
|
395
|
+
const newSrc = await transformModuleIfNeeded(result.source, url, defaultLoad);
|
317
396
|
return {
|
318
397
|
format: 'module',
|
319
398
|
source: newSrc
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-server-dom-webpack",
|
3
3
|
"description": "React Server Components bindings for DOM using Webpack. This is intended to be integrated into meta-frameworks. It is not intended to be imported directly.",
|
4
|
-
"version": "18.3.0-next-
|
4
|
+
"version": "18.3.0-next-55542bc73-20230210",
|
5
5
|
"keywords": [
|
6
6
|
"react"
|
7
7
|
],
|
@@ -54,8 +54,8 @@
|
|
54
54
|
"node": ">=0.10.0"
|
55
55
|
},
|
56
56
|
"peerDependencies": {
|
57
|
-
"react": "18.3.0-next-
|
58
|
-
"react-dom": "18.3.0-next-
|
57
|
+
"react": "18.3.0-next-55542bc73-20230210",
|
58
|
+
"react-dom": "18.3.0-next-55542bc73-20230210",
|
59
59
|
"webpack": "^5.59.0"
|
60
60
|
},
|
61
61
|
"dependencies": {
|