react-server-dom-webpack 18.3.0-next-6ddcbd4f9-20230209 → 18.3.0-next-4a4ef2706-20230212
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 +95 -37
- package/cjs/react-server-dom-webpack-client.production.min.js +11 -9
- package/cjs/react-server-dom-webpack-node-register.js +9 -271
- 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 +95 -37
- 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
@@ -34,11 +34,11 @@ function parseModel(response, json) {
|
|
34
34
|
}
|
35
35
|
|
36
36
|
// eslint-disable-next-line no-unused-vars
|
37
|
-
function resolveClientReference(bundlerConfig,
|
37
|
+
function resolveClientReference(bundlerConfig, metadata) {
|
38
38
|
if (bundlerConfig) {
|
39
|
-
var resolvedModuleData = bundlerConfig[
|
39
|
+
var resolvedModuleData = bundlerConfig[metadata.id][metadata.name];
|
40
40
|
|
41
|
-
if (
|
41
|
+
if (metadata.async) {
|
42
42
|
return {
|
43
43
|
id: resolvedModuleData.id,
|
44
44
|
chunks: resolvedModuleData.chunks,
|
@@ -50,7 +50,7 @@ function resolveClientReference(bundlerConfig, moduleData) {
|
|
50
50
|
}
|
51
51
|
}
|
52
52
|
|
53
|
-
return
|
53
|
+
return metadata;
|
54
54
|
} // The chunk cache contains all the chunks we've preloaded so far.
|
55
55
|
// If they're still pending they're a thenable. This map also exists
|
56
56
|
// in Webpack but unfortunately it's not exposed so we have to
|
@@ -64,8 +64,8 @@ function ignoreReject() {// We rely on rejected promises to be handled by anothe
|
|
64
64
|
// This function doesn't suspend.
|
65
65
|
|
66
66
|
|
67
|
-
function preloadModule(
|
68
|
-
var chunks =
|
67
|
+
function preloadModule(metadata) {
|
68
|
+
var chunks = metadata.chunks;
|
69
69
|
var promises = [];
|
70
70
|
|
71
71
|
for (var i = 0; i < chunks.length; i++) {
|
@@ -85,8 +85,8 @@ function preloadModule(moduleData) {
|
|
85
85
|
}
|
86
86
|
}
|
87
87
|
|
88
|
-
if (
|
89
|
-
var existingPromise = asyncModuleCache.get(
|
88
|
+
if (metadata.async) {
|
89
|
+
var existingPromise = asyncModuleCache.get(metadata.id);
|
90
90
|
|
91
91
|
if (existingPromise) {
|
92
92
|
if (existingPromise.status === 'fulfilled') {
|
@@ -96,7 +96,7 @@ function preloadModule(moduleData) {
|
|
96
96
|
return existingPromise;
|
97
97
|
} else {
|
98
98
|
var modulePromise = Promise.all(promises).then(function () {
|
99
|
-
return __webpack_require__(
|
99
|
+
return __webpack_require__(metadata.id);
|
100
100
|
});
|
101
101
|
modulePromise.then(function (value) {
|
102
102
|
var fulfilledThenable = modulePromise;
|
@@ -107,7 +107,7 @@ function preloadModule(moduleData) {
|
|
107
107
|
rejectedThenable.status = 'rejected';
|
108
108
|
rejectedThenable.reason = reason;
|
109
109
|
});
|
110
|
-
asyncModuleCache.set(
|
110
|
+
asyncModuleCache.set(metadata.id, modulePromise);
|
111
111
|
return modulePromise;
|
112
112
|
}
|
113
113
|
} else if (promises.length > 0) {
|
@@ -118,13 +118,13 @@ function preloadModule(moduleData) {
|
|
118
118
|
} // Actually require the module or suspend if it's not yet ready.
|
119
119
|
// Increase priority if necessary.
|
120
120
|
|
121
|
-
function requireModule(
|
121
|
+
function requireModule(metadata) {
|
122
122
|
var moduleExports;
|
123
123
|
|
124
|
-
if (
|
124
|
+
if (metadata.async) {
|
125
125
|
// We assume that preloadModule has been called before, which
|
126
126
|
// should have added something to the module cache.
|
127
|
-
var promise = asyncModuleCache.get(
|
127
|
+
var promise = asyncModuleCache.get(metadata.id);
|
128
128
|
|
129
129
|
if (promise.status === 'fulfilled') {
|
130
130
|
moduleExports = promise.value;
|
@@ -132,22 +132,22 @@ function requireModule(moduleData) {
|
|
132
132
|
throw promise.reason;
|
133
133
|
}
|
134
134
|
} else {
|
135
|
-
moduleExports = __webpack_require__(
|
135
|
+
moduleExports = __webpack_require__(metadata.id);
|
136
136
|
}
|
137
137
|
|
138
|
-
if (
|
138
|
+
if (metadata.name === '*') {
|
139
139
|
// This is a placeholder value that represents that the caller imported this
|
140
140
|
// as a CommonJS module as is.
|
141
141
|
return moduleExports;
|
142
142
|
}
|
143
143
|
|
144
|
-
if (
|
144
|
+
if (metadata.name === '') {
|
145
145
|
// This is a placeholder value that represents that the caller accessed the
|
146
146
|
// default property of this if it was an ESM interop module.
|
147
147
|
return moduleExports.__esModule ? moduleExports.default : moduleExports;
|
148
148
|
}
|
149
149
|
|
150
|
-
return moduleExports[
|
150
|
+
return moduleExports[metadata.name];
|
151
151
|
}
|
152
152
|
|
153
153
|
// ATTENTION
|
@@ -539,6 +539,29 @@ function createModelReject(chunk) {
|
|
539
539
|
};
|
540
540
|
}
|
541
541
|
|
542
|
+
function createServerReferenceProxy(response, metaData) {
|
543
|
+
var callServer = response._callServer;
|
544
|
+
|
545
|
+
var proxy = function () {
|
546
|
+
// $FlowFixMe[method-unbinding]
|
547
|
+
var args = Array.prototype.slice.call(arguments);
|
548
|
+
var p = metaData.bound;
|
549
|
+
|
550
|
+
if (p.status === INITIALIZED) {
|
551
|
+
var bound = p.value;
|
552
|
+
return callServer(metaData, bound.concat(args));
|
553
|
+
} // Since this is a fake Promise whose .then doesn't chain, we have to wrap it.
|
554
|
+
// TODO: Remove the wrapper once that's fixed.
|
555
|
+
|
556
|
+
|
557
|
+
return Promise.resolve(p).then(function (bound) {
|
558
|
+
return callServer(metaData, bound.concat(args));
|
559
|
+
});
|
560
|
+
};
|
561
|
+
|
562
|
+
return proxy;
|
563
|
+
}
|
564
|
+
|
542
565
|
function parseModelString(response, parentObject, key, value) {
|
543
566
|
if (value[0] === '$') {
|
544
567
|
if (value === '$') {
|
@@ -575,18 +598,20 @@ function parseModelString(response, parentObject, key, value) {
|
|
575
598
|
|
576
599
|
case 'S':
|
577
600
|
{
|
601
|
+
// Symbol
|
578
602
|
return Symbol.for(value.substring(2));
|
579
603
|
}
|
580
604
|
|
581
605
|
case 'P':
|
582
606
|
{
|
607
|
+
// Server Context Provider
|
583
608
|
return getOrCreateServerContext(value.substring(2)).Provider;
|
584
609
|
}
|
585
610
|
|
586
|
-
|
611
|
+
case 'F':
|
587
612
|
{
|
588
|
-
//
|
589
|
-
var _id2 = parseInt(value.substring(
|
613
|
+
// Server Reference
|
614
|
+
var _id2 = parseInt(value.substring(2), 16);
|
590
615
|
|
591
616
|
var _chunk2 = getChunk(response, _id2);
|
592
617
|
|
@@ -594,27 +619,54 @@ function parseModelString(response, parentObject, key, value) {
|
|
594
619
|
case RESOLVED_MODEL:
|
595
620
|
initializeModelChunk(_chunk2);
|
596
621
|
break;
|
622
|
+
} // The status might have changed after initialization.
|
623
|
+
|
624
|
+
|
625
|
+
switch (_chunk2.status) {
|
626
|
+
case INITIALIZED:
|
627
|
+
{
|
628
|
+
var metadata = _chunk2.value;
|
629
|
+
return createServerReferenceProxy(response, metadata);
|
630
|
+
}
|
631
|
+
// We always encode it first in the stream so it won't be pending.
|
632
|
+
|
633
|
+
default:
|
634
|
+
throw _chunk2.reason;
|
635
|
+
}
|
636
|
+
}
|
637
|
+
|
638
|
+
default:
|
639
|
+
{
|
640
|
+
// We assume that anything else is a reference ID.
|
641
|
+
var _id3 = parseInt(value.substring(1), 16);
|
642
|
+
|
643
|
+
var _chunk3 = getChunk(response, _id3);
|
644
|
+
|
645
|
+
switch (_chunk3.status) {
|
646
|
+
case RESOLVED_MODEL:
|
647
|
+
initializeModelChunk(_chunk3);
|
648
|
+
break;
|
597
649
|
|
598
650
|
case RESOLVED_MODULE:
|
599
|
-
initializeModuleChunk(
|
651
|
+
initializeModuleChunk(_chunk3);
|
600
652
|
break;
|
601
653
|
} // The status might have changed after initialization.
|
602
654
|
|
603
655
|
|
604
|
-
switch (
|
656
|
+
switch (_chunk3.status) {
|
605
657
|
case INITIALIZED:
|
606
|
-
return
|
658
|
+
return _chunk3.value;
|
607
659
|
|
608
660
|
case PENDING:
|
609
661
|
case BLOCKED:
|
610
662
|
var parentChunk = initializingChunk;
|
611
663
|
|
612
|
-
|
664
|
+
_chunk3.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
|
613
665
|
|
614
666
|
return null;
|
615
667
|
|
616
668
|
default:
|
617
|
-
throw
|
669
|
+
throw _chunk3.reason;
|
618
670
|
}
|
619
671
|
}
|
620
672
|
}
|
@@ -633,10 +685,16 @@ function parseModelTuple(response, value) {
|
|
633
685
|
|
634
686
|
return value;
|
635
687
|
}
|
636
|
-
|
688
|
+
|
689
|
+
function missingCall() {
|
690
|
+
throw new Error('Trying to call a function from "use server" but the callServer option ' + 'was not implemented in your router runtime.');
|
691
|
+
}
|
692
|
+
|
693
|
+
function createResponse(bundlerConfig, callServer) {
|
637
694
|
var chunks = new Map();
|
638
695
|
var response = {
|
639
696
|
_bundlerConfig: bundlerConfig,
|
697
|
+
_callServer: callServer !== undefined ? callServer : missingCall,
|
640
698
|
_chunks: chunks
|
641
699
|
};
|
642
700
|
return response;
|
@@ -654,12 +712,12 @@ function resolveModel(response, id, model) {
|
|
654
712
|
function resolveModule(response, id, model) {
|
655
713
|
var chunks = response._chunks;
|
656
714
|
var chunk = chunks.get(id);
|
657
|
-
var
|
658
|
-
var
|
715
|
+
var clientReferenceMetadata = parseModel(response, model);
|
716
|
+
var clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata); // TODO: Add an option to encode modules that are lazy loaded.
|
659
717
|
// For now we preload all modules as early as possible since it's likely
|
660
718
|
// that we'll need them.
|
661
719
|
|
662
|
-
var promise = preloadModule(
|
720
|
+
var promise = preloadModule(clientReference);
|
663
721
|
|
664
722
|
if (promise) {
|
665
723
|
var blockedChunk;
|
@@ -677,17 +735,17 @@ function resolveModule(response, id, model) {
|
|
677
735
|
}
|
678
736
|
|
679
737
|
promise.then(function () {
|
680
|
-
return resolveModuleChunk(blockedChunk,
|
738
|
+
return resolveModuleChunk(blockedChunk, clientReference);
|
681
739
|
}, function (error) {
|
682
740
|
return triggerErrorOnChunk(blockedChunk, error);
|
683
741
|
});
|
684
742
|
} else {
|
685
743
|
if (!chunk) {
|
686
|
-
chunks.set(id, createResolvedModuleChunk(response,
|
744
|
+
chunks.set(id, createResolvedModuleChunk(response, clientReference));
|
687
745
|
} else {
|
688
746
|
// This can't actually happen because we don't have any forward
|
689
747
|
// references to modules.
|
690
|
-
resolveModuleChunk(chunk,
|
748
|
+
resolveModuleChunk(chunk, clientReference);
|
691
749
|
}
|
692
750
|
}
|
693
751
|
}
|
@@ -799,11 +857,11 @@ function createFromJSONCallback(response) {
|
|
799
857
|
};
|
800
858
|
}
|
801
859
|
|
802
|
-
function createResponse$1(bundlerConfig) {
|
860
|
+
function createResponse$1(bundlerConfig, callServer) {
|
803
861
|
// NOTE: CHECK THE COMPILER OUTPUT EACH TIME YOU CHANGE THIS.
|
804
862
|
// It should be inlined to one object literal but minor changes can break it.
|
805
863
|
var stringDecoder = createStringDecoder() ;
|
806
|
-
var response = createResponse(bundlerConfig);
|
864
|
+
var response = createResponse(bundlerConfig, callServer);
|
807
865
|
response._partialRow = '';
|
808
866
|
|
809
867
|
{
|
@@ -840,13 +898,13 @@ function startReadingFromStream(response, stream) {
|
|
840
898
|
}
|
841
899
|
|
842
900
|
function createFromReadableStream(stream, options) {
|
843
|
-
var response = createResponse$1(options && options.moduleMap ? options.moduleMap : null);
|
901
|
+
var response = createResponse$1(options && options.moduleMap ? options.moduleMap : null, options && options.callServer ? options.callServer : undefined);
|
844
902
|
startReadingFromStream(response, stream);
|
845
903
|
return getRoot(response);
|
846
904
|
}
|
847
905
|
|
848
906
|
function createFromFetch(promiseForResponse, options) {
|
849
|
-
var response = createResponse$1(options && options.moduleMap ? options.moduleMap : null);
|
907
|
+
var response = createResponse$1(options && options.moduleMap ? options.moduleMap : null, options && options.callServer ? options.callServer : undefined);
|
850
908
|
promiseForResponse.then(function (r) {
|
851
909
|
startReadingFromStream(response, r.body);
|
852
910
|
}, function (e) {
|
@@ -856,7 +914,7 @@ function createFromFetch(promiseForResponse, options) {
|
|
856
914
|
}
|
857
915
|
|
858
916
|
function createFromXHR(request, options) {
|
859
|
-
var response = createResponse$1(options && options.moduleMap ? options.moduleMap : null);
|
917
|
+
var response = createResponse$1(options && options.moduleMap ? options.moduleMap : null, options && options.callServer ? options.callServer : undefined);
|
860
918
|
var processedLength = 0;
|
861
919
|
|
862
920
|
function progress(e) {
|
@@ -15,12 +15,14 @@ function B(a){switch(a.status){case "resolved_model":y(a);break;case "resolved_m
|
|
15
15
|
function E(a,b){if("pending"===a.status||"blocked"===a.status){var c=a.reason;a.status="rejected";a.reason=b;null!==c&&C(c,b)}}function F(a,b){if("pending"===a.status||"blocked"===a.status){var c=a.value,d=a.reason;a.status="resolved_module";a.value=b;null!==c&&(z(a),D(a,c,d))}}var G=null,H=null;
|
16
16
|
function y(a){var b=G,c=H;G=a;H=null;try{var d=JSON.parse(a.value,a._response._fromJSON);null!==H&&0<H.deps?(H.value=d,a.status="blocked",a.value=null,a.reason=null):(a.status="fulfilled",a.value=d)}catch(e){a.status="rejected",a.reason=e}finally{G=b,H=c}}
|
17
17
|
function z(a){try{var b=a.value;if(b.async){var c=p.get(b.id);if("fulfilled"===c.status)var d=c.value;else throw c.reason;}else d=__webpack_require__(b.id);var e="*"===b.name?d:""===b.name?d.__esModule?d.default:d:d[b.name];a.status="fulfilled";a.value=e}catch(f){a.status="rejected",a.reason=f}}function I(a,b){a._chunks.forEach(function(a){"pending"===a.status&&E(a,b)})}function J(a,b){var c=a._chunks,d=c.get(b);d||(d=new x("pending",null,null,a),c.set(b,d));return d}
|
18
|
-
function K(a,b,c){if(H){var d=H;d.deps++}else d=H={deps:1,value:null};return function(e){b[c]=e;d.deps--;0===d.deps&&"blocked"===a.status&&(e=a.value,a.status="fulfilled",a.value=d.value,null!==e&&C(e,d.value))}}function M(a){return function(b){return E(a,b)}}
|
19
|
-
function
|
20
|
-
case "pending":case "blocked":return d=G,a.then(K(d,b,c),M(d)),null;default:throw a.reason;}}}return d}function
|
21
|
-
function Q(a,b){
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
0)};
|
18
|
+
function K(a,b,c){if(H){var d=H;d.deps++}else d=H={deps:1,value:null};return function(e){b[c]=e;d.deps--;0===d.deps&&"blocked"===a.status&&(e=a.value,a.status="fulfilled",a.value=d.value,null!==e&&C(e,d.value))}}function M(a){return function(b){return E(a,b)}}function N(a,b){var c=a._callServer;return function(){var a=Array.prototype.slice.call(arguments),e=b.bound;return"fulfilled"===e.status?c(b,e.value.concat(a)):Promise.resolve(e).then(function(d){return c(b,d.concat(a))})}}
|
19
|
+
function O(a,b,c,d){if("$"===d[0]){if("$"===d)return t;switch(d[1]){case "$":return d.substring(1);case "L":return b=parseInt(d.substring(2),16),a=J(a,b),{$$typeof:u,_payload:a,_init:B};case "@":return b=parseInt(d.substring(2),16),J(a,b);case "S":return Symbol.for(d.substring(2));case "P":return a=d.substring(2),w[a]||(w[a]=h.createServerContext(a,v)),w[a].Provider;case "F":b=parseInt(d.substring(2),16);b=J(a,b);switch(b.status){case "resolved_model":y(b)}switch(b.status){case "fulfilled":return N(a,
|
20
|
+
b.value);default:throw b.reason;}default:d=parseInt(d.substring(1),16);a=J(a,d);switch(a.status){case "resolved_model":y(a);break;case "resolved_module":z(a)}switch(a.status){case "fulfilled":return a.value;case "pending":case "blocked":return d=G,a.then(K(d,b,c),M(d)),null;default:throw a.reason;}}}return d}function P(){throw Error('Trying to call a function from "use server" but the callServer option was not implemented in your router runtime.');}
|
21
|
+
function Q(a,b,c){var d=a._chunks,e=d.get(b);c=JSON.parse(c,a._fromJSON);var f=m(a._bundlerConfig,c);if(c=r(f)){if(e){var k=e;k.status="blocked"}else k=new x("blocked",null,null,a),d.set(b,k);c.then(function(){return F(k,f)},function(a){return E(k,a)})}else e?F(e,f):d.set(b,new x("resolved_module",f,null,a))}function R(a){I(a,Error("Connection closed."))}
|
22
|
+
function S(a,b){if(""!==b){var c=b.indexOf(":",0),d=parseInt(b.substring(0,c),16);switch(b[c+1]){case "I":Q(a,d,b.substring(c+2));break;case "E":c=JSON.parse(b.substring(c+2)).digest;b=Error("An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.");b.stack="Error: "+b.message;b.digest=c;c=a._chunks;
|
23
|
+
var e=c.get(d);e?E(e,b):c.set(d,new x("rejected",null,b,a));break;default:b=b.substring(c+1),e=a._chunks,(c=e.get(d))?"pending"===c.status&&(a=c.value,d=c.reason,c.status="resolved_model",c.value=b,null!==a&&(y(c),D(c,a,d))):e.set(d,new x("resolved_model",b,null,a))}}}function T(a){return function(b,c){return"string"===typeof c?O(a,this,b,c):"object"===typeof c&&null!==c?(b=c[0]===t?{$$typeof:t,type:c[1],key:c[2],ref:null,props:c[3],_owner:null}:c,b):c}}
|
24
|
+
function U(a,b){var c=new TextDecoder,d=new Map;a={_bundlerConfig:a,_callServer:void 0!==b?b:P,_chunks:d,_partialRow:"",_stringDecoder:c};a._fromJSON=T(a);return a}
|
25
|
+
function V(a,b){function c(b){var f=b.value;if(b.done)R(a);else{b=f;f=a._stringDecoder;for(var g=b.indexOf(10);-1<g;){var L=a._partialRow;var A=b.subarray(0,g);A=f.decode(A);S(a,L+A);a._partialRow="";b=b.subarray(g+1);g=b.indexOf(10)}a._partialRow+=f.decode(b,l);return e.read().then(c).catch(d)}}function d(b){I(a,b)}var e=b.getReader();e.read().then(c).catch(d)}
|
26
|
+
exports.createFromFetch=function(a,b){var c=U(b&&b.moduleMap?b.moduleMap:null,b&&b.callServer?b.callServer:void 0);a.then(function(a){V(c,a.body)},function(a){I(c,a)});return J(c,0)};exports.createFromReadableStream=function(a,b){b=U(b&&b.moduleMap?b.moduleMap:null,b&&b.callServer?b.callServer:void 0);V(b,a);return J(b,0)};
|
27
|
+
exports.createFromXHR=function(a,b){function c(){for(var b=a.responseText,c=f,d=b.indexOf("\n",c);-1<d;)c=e._partialRow+b.substring(c,d),S(e,c),e._partialRow="",c=d+1,d=b.indexOf("\n",c);e._partialRow+=b.substring(c);f=b.length}function d(){I(e,new TypeError("Network error"))}var e=U(b&&b.moduleMap?b.moduleMap:null,b&&b.callServer?b.callServer:void 0),f=0;a.addEventListener("progress",c);a.addEventListener("load",function(){c();R(e)});a.addEventListener("error",d);a.addEventListener("abort",d);a.addEventListener("timeout",
|
28
|
+
d);return J(e,0)};
|
@@ -10,274 +10,12 @@
|
|
10
10
|
|
11
11
|
'use strict';
|
12
12
|
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
var CLIENT_REFERENCE = Symbol.for('react.client.reference');
|
23
|
-
var PROMISE_PROTOTYPE = Promise.prototype;
|
24
|
-
var deepProxyHandlers = {
|
25
|
-
get: function (target, name, receiver) {
|
26
|
-
switch (name) {
|
27
|
-
// These names are read by the Flight runtime if you end up using the exports object.
|
28
|
-
case '$$typeof':
|
29
|
-
// These names are a little too common. We should probably have a way to
|
30
|
-
// have the Flight runtime extract the inner target instead.
|
31
|
-
return target.$$typeof;
|
32
|
-
|
33
|
-
case 'filepath':
|
34
|
-
return target.filepath;
|
35
|
-
|
36
|
-
case 'name':
|
37
|
-
return target.name;
|
38
|
-
|
39
|
-
case 'async':
|
40
|
-
return target.async;
|
41
|
-
// We need to special case this because createElement reads it if we pass this
|
42
|
-
// reference.
|
43
|
-
|
44
|
-
case 'defaultProps':
|
45
|
-
return undefined;
|
46
|
-
// Avoid this attempting to be serialized.
|
47
|
-
|
48
|
-
case 'toJSON':
|
49
|
-
return undefined;
|
50
|
-
|
51
|
-
case Symbol.toPrimitive:
|
52
|
-
// $FlowFixMe[prop-missing]
|
53
|
-
return Object.prototype[Symbol.toPrimitive];
|
54
|
-
|
55
|
-
case 'Provider':
|
56
|
-
throw new Error("Cannot render a Client Context Provider on the Server. " + "Instead, you can export a Client Component wrapper " + "that itself renders a Client Context Provider.");
|
57
|
-
}
|
58
|
-
|
59
|
-
var expression;
|
60
|
-
|
61
|
-
switch (target.name) {
|
62
|
-
case '':
|
63
|
-
// eslint-disable-next-line react-internal/safe-string-coercion
|
64
|
-
expression = String(name);
|
65
|
-
break;
|
66
|
-
|
67
|
-
case '*':
|
68
|
-
// eslint-disable-next-line react-internal/safe-string-coercion
|
69
|
-
expression = String(name);
|
70
|
-
break;
|
71
|
-
|
72
|
-
default:
|
73
|
-
// eslint-disable-next-line react-internal/safe-string-coercion
|
74
|
-
expression = String(target.name) + '.' + String(name);
|
75
|
-
}
|
76
|
-
|
77
|
-
throw new Error("Cannot access " + expression + " on the server. " + 'You cannot dot into a client module from a server component. ' + 'You can only pass the imported name through.');
|
78
|
-
},
|
79
|
-
set: function () {
|
80
|
-
throw new Error('Cannot assign to a client module from a server module.');
|
81
|
-
}
|
82
|
-
};
|
83
|
-
var proxyHandlers = {
|
84
|
-
get: function (target, name, receiver) {
|
85
|
-
switch (name) {
|
86
|
-
// These names are read by the Flight runtime if you end up using the exports object.
|
87
|
-
case '$$typeof':
|
88
|
-
// These names are a little too common. We should probably have a way to
|
89
|
-
// have the Flight runtime extract the inner target instead.
|
90
|
-
return target.$$typeof;
|
91
|
-
|
92
|
-
case 'filepath':
|
93
|
-
return target.filepath;
|
94
|
-
|
95
|
-
case 'name':
|
96
|
-
return target.name;
|
97
|
-
|
98
|
-
case 'async':
|
99
|
-
return target.async;
|
100
|
-
// We need to special case this because createElement reads it if we pass this
|
101
|
-
// reference.
|
102
|
-
|
103
|
-
case 'defaultProps':
|
104
|
-
return undefined;
|
105
|
-
// Avoid this attempting to be serialized.
|
106
|
-
|
107
|
-
case 'toJSON':
|
108
|
-
return undefined;
|
109
|
-
|
110
|
-
case Symbol.toPrimitive:
|
111
|
-
// $FlowFixMe[prop-missing]
|
112
|
-
return Object.prototype[Symbol.toPrimitive];
|
113
|
-
|
114
|
-
case '__esModule':
|
115
|
-
// Something is conditionally checking which export to use. We'll pretend to be
|
116
|
-
// an ESM compat module but then we'll check again on the client.
|
117
|
-
var moduleId = target.filepath;
|
118
|
-
target.default = Object.defineProperties(function () {
|
119
|
-
throw new Error("Attempted to call the default export of " + moduleId + " from the server " + "but it's on the client. It's not possible to invoke a client function from " + "the server, it can only be rendered as a Component or passed to props of a " + "Client Component.");
|
120
|
-
}, {
|
121
|
-
// This a placeholder value that tells the client to conditionally use the
|
122
|
-
// whole object or just the default export.
|
123
|
-
name: {
|
124
|
-
value: ''
|
125
|
-
},
|
126
|
-
$$typeof: {
|
127
|
-
value: CLIENT_REFERENCE
|
128
|
-
},
|
129
|
-
filepath: {
|
130
|
-
value: target.filepath
|
131
|
-
},
|
132
|
-
async: {
|
133
|
-
value: target.async
|
134
|
-
}
|
135
|
-
});
|
136
|
-
return true;
|
137
|
-
|
138
|
-
case 'then':
|
139
|
-
if (target.then) {
|
140
|
-
// Use a cached value
|
141
|
-
return target.then;
|
142
|
-
}
|
143
|
-
|
144
|
-
if (!target.async) {
|
145
|
-
// If this module is expected to return a Promise (such as an AsyncModule) then
|
146
|
-
// we should resolve that with a client reference that unwraps the Promise on
|
147
|
-
// the client.
|
148
|
-
var clientReference = Object.defineProperties({}, {
|
149
|
-
// Represents the whole Module object instead of a particular import.
|
150
|
-
name: {
|
151
|
-
value: '*'
|
152
|
-
},
|
153
|
-
$$typeof: {
|
154
|
-
value: CLIENT_REFERENCE
|
155
|
-
},
|
156
|
-
filepath: {
|
157
|
-
value: target.filepath
|
158
|
-
},
|
159
|
-
async: {
|
160
|
-
value: true
|
161
|
-
}
|
162
|
-
});
|
163
|
-
var proxy = new Proxy(clientReference, proxyHandlers); // Treat this as a resolved Promise for React's use()
|
164
|
-
|
165
|
-
target.status = 'fulfilled';
|
166
|
-
target.value = proxy;
|
167
|
-
var then = target.then = Object.defineProperties(function then(resolve, reject) {
|
168
|
-
// Expose to React.
|
169
|
-
return Promise.resolve(resolve(proxy));
|
170
|
-
}, // If this is not used as a Promise but is treated as a reference to a `.then`
|
171
|
-
// export then we should treat it as a reference to that name.
|
172
|
-
{
|
173
|
-
name: {
|
174
|
-
value: 'then'
|
175
|
-
},
|
176
|
-
$$typeof: {
|
177
|
-
value: CLIENT_REFERENCE
|
178
|
-
},
|
179
|
-
filepath: {
|
180
|
-
value: target.filepath
|
181
|
-
},
|
182
|
-
async: {
|
183
|
-
value: false
|
184
|
-
}
|
185
|
-
});
|
186
|
-
return then;
|
187
|
-
} else {
|
188
|
-
// Since typeof .then === 'function' is a feature test we'd continue recursing
|
189
|
-
// indefinitely if we return a function. Instead, we return an object reference
|
190
|
-
// if we check further.
|
191
|
-
return undefined;
|
192
|
-
}
|
193
|
-
|
194
|
-
}
|
195
|
-
|
196
|
-
var cachedReference = target[name];
|
197
|
-
|
198
|
-
if (!cachedReference) {
|
199
|
-
var reference = Object.defineProperties(function () {
|
200
|
-
throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
|
201
|
-
"Attempted to call " + String(name) + "() from the server but " + String(name) + " is on the client. " + "It's not possible to invoke a client function from the server, it can " + "only be rendered as a Component or passed to props of a Client Component.");
|
202
|
-
}, {
|
203
|
-
name: {
|
204
|
-
value: name
|
205
|
-
},
|
206
|
-
$$typeof: {
|
207
|
-
value: CLIENT_REFERENCE
|
208
|
-
},
|
209
|
-
filepath: {
|
210
|
-
value: target.filepath
|
211
|
-
},
|
212
|
-
async: {
|
213
|
-
value: target.async
|
214
|
-
}
|
215
|
-
});
|
216
|
-
cachedReference = target[name] = new Proxy(reference, deepProxyHandlers);
|
217
|
-
}
|
218
|
-
|
219
|
-
return cachedReference;
|
220
|
-
},
|
221
|
-
getPrototypeOf: function (target) {
|
222
|
-
// Pretend to be a Promise in case anyone asks.
|
223
|
-
return PROMISE_PROTOTYPE;
|
224
|
-
},
|
225
|
-
set: function () {
|
226
|
-
throw new Error('Cannot assign to a client module from a server module.');
|
227
|
-
}
|
228
|
-
}; // $FlowFixMe[prop-missing] found when upgrading Flow
|
229
|
-
|
230
|
-
var originalCompile = Module.prototype._compile; // $FlowFixMe[prop-missing] found when upgrading Flow
|
231
|
-
|
232
|
-
Module.prototype._compile = function (content, filename) {
|
233
|
-
// Do a quick check for the exact string. If it doesn't exist, don't
|
234
|
-
// bother parsing.
|
235
|
-
if (content.indexOf('use client') === -1) {
|
236
|
-
return originalCompile.apply(this, arguments);
|
237
|
-
}
|
238
|
-
|
239
|
-
var _acorn$parse = acorn.parse(content, {
|
240
|
-
ecmaVersion: '2019',
|
241
|
-
sourceType: 'source'
|
242
|
-
}),
|
243
|
-
body = _acorn$parse.body;
|
244
|
-
|
245
|
-
var useClient = false;
|
246
|
-
|
247
|
-
for (var i = 0; i < body.length; i++) {
|
248
|
-
var node = body[i];
|
249
|
-
|
250
|
-
if (node.type !== 'ExpressionStatement' || !node.directive) {
|
251
|
-
break;
|
252
|
-
}
|
253
|
-
|
254
|
-
if (node.directive === 'use client') {
|
255
|
-
useClient = true;
|
256
|
-
break;
|
257
|
-
}
|
258
|
-
}
|
259
|
-
|
260
|
-
if (!useClient) {
|
261
|
-
return originalCompile.apply(this, arguments);
|
262
|
-
}
|
263
|
-
|
264
|
-
var moduleId = url.pathToFileURL(filename).href;
|
265
|
-
var clientReference = Object.defineProperties({}, {
|
266
|
-
// Represents the whole Module object instead of a particular import.
|
267
|
-
name: {
|
268
|
-
value: '*'
|
269
|
-
},
|
270
|
-
$$typeof: {
|
271
|
-
value: CLIENT_REFERENCE
|
272
|
-
},
|
273
|
-
filepath: {
|
274
|
-
value: moduleId
|
275
|
-
},
|
276
|
-
async: {
|
277
|
-
value: false
|
278
|
-
}
|
279
|
-
}); // $FlowFixMe[incompatible-call] found when upgrading Flow
|
280
|
-
|
281
|
-
this.exports = new Proxy(clientReference, proxyHandlers);
|
282
|
-
};
|
283
|
-
};
|
13
|
+
'use strict';const m=require("acorn"),n=require("url"),q=require("module");
|
14
|
+
module.exports=function(){const h=Symbol.for("react.client.reference"),k=Symbol.for("react.server.reference"),r=Promise.prototype,t=Function.prototype.bind;Function.prototype.bind=function(a){const b=t.apply(this,arguments);if(this.$$typeof===k){const a=Array.prototype.slice.call(arguments,1);b.$$typeof=k;b.$$filepath=this.$$filepath;b.$$name=this.$$name;b.$$bound=this.$$bound.concat(a)}return b};const u={get:function(a,b){switch(b){case "$$typeof":return a.$$typeof;case "filepath":return a.filepath;
|
15
|
+
case "name":return a.name;case "displayName":return;case "async":return a.async;case "defaultProps":return;case "toJSON":return;case Symbol.toPrimitive:return Object.prototype[Symbol.toPrimitive];case "Provider":throw Error("Cannot render a Client Context Provider on the Server. Instead, you can export a Client Component wrapper that itself renders a Client Context Provider.");}switch(a.name){case "":a=String(b);break;case "*":a=String(b);break;default:a=String(a.name)+"."+String(b)}throw Error("Cannot access "+
|
16
|
+
a+" on the server. You cannot dot into a client module from a server component. You can only pass the imported name through.");},set:function(){throw Error("Cannot assign to a client module from a server module.");}},p={get:function(a,b){switch(b){case "$$typeof":return a.$$typeof;case "filepath":return a.filepath;case "name":return a.name;case "async":return a.async;case "defaultProps":return;case "toJSON":return;case Symbol.toPrimitive:return Object.prototype[Symbol.toPrimitive];case "__esModule":const d=
|
17
|
+
a.filepath;a.default=Object.defineProperties(function(){throw Error("Attempted to call the default export of "+d+" from the server but it's on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.");},{name:{value:""},$$typeof:{value:h},filepath:{value:a.filepath},async:{value:a.async}});return!0;case "then":if(a.then)return a.then;if(a.async)return;{var c=Object.defineProperties({},{name:{value:"*"},
|
18
|
+
$$typeof:{value:h},filepath:{value:a.filepath},async:{value:!0}});const b=new Proxy(c,p);a.status="fulfilled";a.value=b;return a.then=Object.defineProperties(function(a){return Promise.resolve(a(b))},{name:{value:"then"},$$typeof:{value:h},filepath:{value:a.filepath},async:{value:!1}})}}c=a[b];c||(c=Object.defineProperties(function(){throw Error("Attempted to call "+String(b)+"() from the server but "+String(b)+" is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.");
|
19
|
+
},{name:{value:b},$$typeof:{value:h},filepath:{value:a.filepath},async:{value:a.async}}),c=a[b]=new Proxy(c,u));return c},getPrototypeOf(){return r},set:function(){throw Error("Cannot assign to a client module from a server module.");}},l=q.prototype._compile;q.prototype._compile=function(a,b){if(-1===a.indexOf("use client")&&-1===a.indexOf("use server"))return l.apply(this,arguments);var c=m.parse(a,{ecmaVersion:"2019",sourceType:"source"}).body,d=!1,f=!1;for(var e=0;e<c.length;e++){var g=c[e];if("ExpressionStatement"!==
|
20
|
+
g.type||!g.directive)break;"use client"===g.directive&&(d=!0);"use server"===g.directive&&(f=!0)}if(!d&&!f)return l.apply(this,arguments);if(d&&f)throw Error('Cannot have both "use client" and "use server" directives in the same file.');d&&(c=n.pathToFileURL(b).href,c=Object.defineProperties({},{name:{value:"*"},$$typeof:{value:h},filepath:{value:c},async:{value:!1}}),this.exports=new Proxy(c,p));if(f)if(l.apply(this,arguments),f=n.pathToFileURL(b).href,c=this.exports,"function"===typeof c)Object.defineProperties(c,
|
21
|
+
{$$typeof:{value:k},$$filepath:{value:f},$$name:{value:"*"},$$bound:{value:[]}});else for(d=Object.keys(c),e=0;e<d.length;e++){g=d[e];const a=c[d[e]];"function"===typeof a&&Object.defineProperties(a,{$$typeof:{value:k},$$filepath:{value:f},$$name:{value:g},$$bound:{value:[]}})}}};
|