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
@@ -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
|
@@ -510,8 +510,7 @@ function createModelResolver(chunk, parentObject, key) {
|
|
510
510
|
deps: 1,
|
511
511
|
value: null
|
512
512
|
};
|
513
|
-
}
|
514
|
-
|
513
|
+
}
|
515
514
|
|
516
515
|
return function (value) {
|
517
516
|
parentObject[key] = value;
|
@@ -540,6 +539,29 @@ function createModelReject(chunk) {
|
|
540
539
|
};
|
541
540
|
}
|
542
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
|
+
|
543
565
|
function parseModelString(response, parentObject, key, value) {
|
544
566
|
if (value[0] === '$') {
|
545
567
|
if (value === '$') {
|
@@ -576,18 +598,20 @@ function parseModelString(response, parentObject, key, value) {
|
|
576
598
|
|
577
599
|
case 'S':
|
578
600
|
{
|
601
|
+
// Symbol
|
579
602
|
return Symbol.for(value.substring(2));
|
580
603
|
}
|
581
604
|
|
582
605
|
case 'P':
|
583
606
|
{
|
607
|
+
// Server Context Provider
|
584
608
|
return getOrCreateServerContext(value.substring(2)).Provider;
|
585
609
|
}
|
586
610
|
|
587
|
-
|
611
|
+
case 'F':
|
588
612
|
{
|
589
|
-
//
|
590
|
-
var _id2 = parseInt(value.substring(
|
613
|
+
// Server Reference
|
614
|
+
var _id2 = parseInt(value.substring(2), 16);
|
591
615
|
|
592
616
|
var _chunk2 = getChunk(response, _id2);
|
593
617
|
|
@@ -595,27 +619,54 @@ function parseModelString(response, parentObject, key, value) {
|
|
595
619
|
case RESOLVED_MODEL:
|
596
620
|
initializeModelChunk(_chunk2);
|
597
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;
|
598
649
|
|
599
650
|
case RESOLVED_MODULE:
|
600
|
-
initializeModuleChunk(
|
651
|
+
initializeModuleChunk(_chunk3);
|
601
652
|
break;
|
602
653
|
} // The status might have changed after initialization.
|
603
654
|
|
604
655
|
|
605
|
-
switch (
|
656
|
+
switch (_chunk3.status) {
|
606
657
|
case INITIALIZED:
|
607
|
-
return
|
658
|
+
return _chunk3.value;
|
608
659
|
|
609
660
|
case PENDING:
|
610
661
|
case BLOCKED:
|
611
662
|
var parentChunk = initializingChunk;
|
612
663
|
|
613
|
-
|
664
|
+
_chunk3.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
|
614
665
|
|
615
666
|
return null;
|
616
667
|
|
617
668
|
default:
|
618
|
-
throw
|
669
|
+
throw _chunk3.reason;
|
619
670
|
}
|
620
671
|
}
|
621
672
|
}
|
@@ -634,10 +685,16 @@ function parseModelTuple(response, value) {
|
|
634
685
|
|
635
686
|
return value;
|
636
687
|
}
|
637
|
-
|
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) {
|
638
694
|
var chunks = new Map();
|
639
695
|
var response = {
|
640
696
|
_bundlerConfig: bundlerConfig,
|
697
|
+
_callServer: callServer !== undefined ? callServer : missingCall,
|
641
698
|
_chunks: chunks
|
642
699
|
};
|
643
700
|
return response;
|
@@ -655,12 +712,12 @@ function resolveModel(response, id, model) {
|
|
655
712
|
function resolveModule(response, id, model) {
|
656
713
|
var chunks = response._chunks;
|
657
714
|
var chunk = chunks.get(id);
|
658
|
-
var
|
659
|
-
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.
|
660
717
|
// For now we preload all modules as early as possible since it's likely
|
661
718
|
// that we'll need them.
|
662
719
|
|
663
|
-
var promise = preloadModule(
|
720
|
+
var promise = preloadModule(clientReference);
|
664
721
|
|
665
722
|
if (promise) {
|
666
723
|
var blockedChunk;
|
@@ -678,17 +735,17 @@ function resolveModule(response, id, model) {
|
|
678
735
|
}
|
679
736
|
|
680
737
|
promise.then(function () {
|
681
|
-
return resolveModuleChunk(blockedChunk,
|
738
|
+
return resolveModuleChunk(blockedChunk, clientReference);
|
682
739
|
}, function (error) {
|
683
740
|
return triggerErrorOnChunk(blockedChunk, error);
|
684
741
|
});
|
685
742
|
} else {
|
686
743
|
if (!chunk) {
|
687
|
-
chunks.set(id, createResolvedModuleChunk(response,
|
744
|
+
chunks.set(id, createResolvedModuleChunk(response, clientReference));
|
688
745
|
} else {
|
689
746
|
// This can't actually happen because we don't have any forward
|
690
747
|
// references to modules.
|
691
|
-
resolveModuleChunk(chunk,
|
748
|
+
resolveModuleChunk(chunk, clientReference);
|
692
749
|
}
|
693
750
|
}
|
694
751
|
}
|
@@ -800,11 +857,11 @@ function createFromJSONCallback(response) {
|
|
800
857
|
};
|
801
858
|
}
|
802
859
|
|
803
|
-
function createResponse$1(bundlerConfig) {
|
860
|
+
function createResponse$1(bundlerConfig, callServer) {
|
804
861
|
// NOTE: CHECK THE COMPILER OUTPUT EACH TIME YOU CHANGE THIS.
|
805
862
|
// It should be inlined to one object literal but minor changes can break it.
|
806
863
|
var stringDecoder = createStringDecoder() ;
|
807
|
-
var response = createResponse(bundlerConfig);
|
864
|
+
var response = createResponse(bundlerConfig, callServer);
|
808
865
|
response._partialRow = '';
|
809
866
|
|
810
867
|
{
|
@@ -841,13 +898,13 @@ function startReadingFromStream(response, stream) {
|
|
841
898
|
}
|
842
899
|
|
843
900
|
function createFromReadableStream(stream, options) {
|
844
|
-
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);
|
845
902
|
startReadingFromStream(response, stream);
|
846
903
|
return getRoot(response);
|
847
904
|
}
|
848
905
|
|
849
906
|
function createFromFetch(promiseForResponse, options) {
|
850
|
-
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);
|
851
908
|
promiseForResponse.then(function (r) {
|
852
909
|
startReadingFromStream(response, r.body);
|
853
910
|
}, function (e) {
|
@@ -857,7 +914,7 @@ function createFromFetch(promiseForResponse, options) {
|
|
857
914
|
}
|
858
915
|
|
859
916
|
function createFromXHR(request, options) {
|
860
|
-
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);
|
861
918
|
var processedLength = 0;
|
862
919
|
|
863
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,276 +10,12 @@
|
|
10
10
|
|
11
11
|
'use strict';
|
12
12
|
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
var
|
18
|
-
|
19
|
-
var
|
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; // $FlowFixMe[missing-local-annot]
|
167
|
-
|
168
|
-
var then = target.then = Object.defineProperties(function then(resolve, reject) {
|
169
|
-
// Expose to React.
|
170
|
-
return Promise.resolve( // $FlowFixMe[incompatible-call] found when upgrading Flow
|
171
|
-
resolve(proxy));
|
172
|
-
}, // If this is not used as a Promise but is treated as a reference to a `.then`
|
173
|
-
// export then we should treat it as a reference to that name.
|
174
|
-
{
|
175
|
-
name: {
|
176
|
-
value: 'then'
|
177
|
-
},
|
178
|
-
$$typeof: {
|
179
|
-
value: CLIENT_REFERENCE
|
180
|
-
},
|
181
|
-
filepath: {
|
182
|
-
value: target.filepath
|
183
|
-
},
|
184
|
-
async: {
|
185
|
-
value: false
|
186
|
-
}
|
187
|
-
});
|
188
|
-
return then;
|
189
|
-
} else {
|
190
|
-
// Since typeof .then === 'function' is a feature test we'd continue recursing
|
191
|
-
// indefinitely if we return a function. Instead, we return an object reference
|
192
|
-
// if we check further.
|
193
|
-
return undefined;
|
194
|
-
}
|
195
|
-
|
196
|
-
}
|
197
|
-
|
198
|
-
var cachedReference = target[name];
|
199
|
-
|
200
|
-
if (!cachedReference) {
|
201
|
-
var reference = Object.defineProperties(function () {
|
202
|
-
throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
|
203
|
-
"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.");
|
204
|
-
}, {
|
205
|
-
name: {
|
206
|
-
value: name
|
207
|
-
},
|
208
|
-
$$typeof: {
|
209
|
-
value: CLIENT_REFERENCE
|
210
|
-
},
|
211
|
-
filepath: {
|
212
|
-
value: target.filepath
|
213
|
-
},
|
214
|
-
async: {
|
215
|
-
value: target.async
|
216
|
-
}
|
217
|
-
});
|
218
|
-
cachedReference = target[name] = new Proxy(reference, deepProxyHandlers);
|
219
|
-
}
|
220
|
-
|
221
|
-
return cachedReference;
|
222
|
-
},
|
223
|
-
getPrototypeOf: function (target) {
|
224
|
-
// Pretend to be a Promise in case anyone asks.
|
225
|
-
return PROMISE_PROTOTYPE;
|
226
|
-
},
|
227
|
-
set: function () {
|
228
|
-
throw new Error('Cannot assign to a client module from a server module.');
|
229
|
-
}
|
230
|
-
}; // $FlowFixMe[prop-missing] found when upgrading Flow
|
231
|
-
|
232
|
-
var originalCompile = Module.prototype._compile; // $FlowFixMe[prop-missing] found when upgrading Flow
|
233
|
-
|
234
|
-
Module.prototype._compile = function (content, filename) {
|
235
|
-
// Do a quick check for the exact string. If it doesn't exist, don't
|
236
|
-
// bother parsing.
|
237
|
-
if (content.indexOf('use client') === -1) {
|
238
|
-
return originalCompile.apply(this, arguments);
|
239
|
-
}
|
240
|
-
|
241
|
-
var _acorn$parse = acorn.parse(content, {
|
242
|
-
ecmaVersion: '2019',
|
243
|
-
sourceType: 'source'
|
244
|
-
}),
|
245
|
-
body = _acorn$parse.body;
|
246
|
-
|
247
|
-
var useClient = false;
|
248
|
-
|
249
|
-
for (var i = 0; i < body.length; i++) {
|
250
|
-
var node = body[i];
|
251
|
-
|
252
|
-
if (node.type !== 'ExpressionStatement' || !node.directive) {
|
253
|
-
break;
|
254
|
-
}
|
255
|
-
|
256
|
-
if (node.directive === 'use client') {
|
257
|
-
useClient = true;
|
258
|
-
break;
|
259
|
-
}
|
260
|
-
}
|
261
|
-
|
262
|
-
if (!useClient) {
|
263
|
-
return originalCompile.apply(this, arguments);
|
264
|
-
}
|
265
|
-
|
266
|
-
var moduleId = url.pathToFileURL(filename).href;
|
267
|
-
var clientReference = Object.defineProperties({}, {
|
268
|
-
// Represents the whole Module object instead of a particular import.
|
269
|
-
name: {
|
270
|
-
value: '*'
|
271
|
-
},
|
272
|
-
$$typeof: {
|
273
|
-
value: CLIENT_REFERENCE
|
274
|
-
},
|
275
|
-
filepath: {
|
276
|
-
value: moduleId
|
277
|
-
},
|
278
|
-
async: {
|
279
|
-
value: false
|
280
|
-
}
|
281
|
-
}); // $FlowFixMe[incompatible-call] found when upgrading Flow
|
282
|
-
|
283
|
-
this.exports = new Proxy(clientReference, proxyHandlers);
|
284
|
-
};
|
285
|
-
};
|
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 "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 "+a+" on the server. You cannot dot into a client module from a server component. You can only pass the imported name through.");
|
16
|
+
},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=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.");
|
17
|
+
},{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:"*"},$$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||
|
18
|
+
(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.");},{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.");
|
19
|
+
}},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"!==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.');
|
20
|
+
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,{$$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},
|
21
|
+
$$filepath:{value:f},$$name:{value:g},$$bound:{value:[]}})}}};
|