1212
1313"use strict" ;
1414var ReactDOM = require ( "react-dom" ) ,
15- React = require ( "react" ) ;
15+ React = require ( "react" ) ,
16+ requestedClientReferencesKeys = new Set ( ) ,
17+ checkIsClientReference ;
18+ function isClientReference ( reference ) {
19+ if ( null == checkIsClientReference )
20+ throw Error ( "Expected implementation for checkIsClientReference." ) ;
21+ return checkIsClientReference ( reference ) ;
22+ }
1623require ( "ReactFeatureFlags" ) ;
1724var byteLengthImpl = null ;
1825function writeChunkAndReturn ( destination , chunk ) {
1926 destination . write ( chunk ) ;
2027 return ! 0 ;
2128}
22- var registeredClientReferences = new Map ( ) ,
23- requestedClientReferencesKeys = new Set ( ) ,
24- ReactDOMFlightServerDispatcher = {
25- prefetchDNS : prefetchDNS ,
26- preconnect : preconnect ,
27- preload : preload ,
28- preloadModule : preloadModule ,
29- preinitStyle : preinitStyle ,
30- preinitScript : preinitScript ,
31- preinitModuleScript : preinitModuleScript
32- } ;
29+ var ReactDOMFlightServerDispatcher = {
30+ prefetchDNS : prefetchDNS ,
31+ preconnect : preconnect ,
32+ preload : preload ,
33+ preloadModule : preloadModule ,
34+ preinitStyle : preinitStyle ,
35+ preinitScript : preinitScript ,
36+ preinitModuleScript : preinitModuleScript
37+ } ;
3338function prefetchDNS ( href ) {
3439 if ( "string" === typeof href && href ) {
3540 var request = currentRequest ? currentRequest : null ;
@@ -647,8 +652,7 @@ function attemptResolveElement(
647652 "Refs cannot be used in Server Components, nor passed to Client Components."
648653 ) ;
649654 if ( "function" === typeof type ) {
650- if ( registeredClientReferences . has ( type ) )
651- return [ REACT_ELEMENT_TYPE , type , key , props ] ;
655+ if ( isClientReference ( type ) ) return [ REACT_ELEMENT_TYPE , type , key , props ] ;
652656 thenableIndexCounter = 0 ;
653657 thenableState = prevThenableState ;
654658 props = type ( props ) ;
@@ -666,8 +670,7 @@ function attemptResolveElement(
666670 ? props . children
667671 : [ REACT_ELEMENT_TYPE , type , key , props ] ;
668672 if ( null != type && "object" === typeof type ) {
669- if ( registeredClientReferences . has ( type ) )
670- return [ REACT_ELEMENT_TYPE , type , key , props ] ;
673+ if ( isClientReference ( type ) ) return [ REACT_ELEMENT_TYPE , type , key , props ] ;
671674 switch ( type . $$typeof ) {
672675 case REACT_LAZY_TYPE :
673676 var init = type . _init ;
@@ -727,32 +730,23 @@ function serializeByValueID(id) {
727730 return "$" + id . toString ( 16 ) ;
728731}
729732function serializeClientReference ( request , parent , key , clientReference ) {
730- var JSCompiler_inline_result =
731- registeredClientReferences . get ( clientReference ) ;
732- if ( null != JSCompiler_inline_result )
733- requestedClientReferencesKeys . add ( JSCompiler_inline_result . moduleId ) ,
734- ( JSCompiler_inline_result = JSCompiler_inline_result . moduleId ) ;
735- else
736- throw Error (
737- "Expected client reference " + clientReference + " to be registered."
738- ) ;
733+ var JSCompiler_inline_result = clientReference . getModuleId ( ) ;
734+ requestedClientReferencesKeys . add ( JSCompiler_inline_result ) ;
735+ JSCompiler_inline_result = clientReference . getModuleId ( ) ;
739736 var writtenClientReferences = request . writtenClientReferences ,
740737 existingId = writtenClientReferences . get ( JSCompiler_inline_result ) ;
741738 if ( void 0 !== existingId )
742739 return parent [ 0 ] === REACT_ELEMENT_TYPE && "1" === key
743740 ? "$L" + existingId . toString ( 16 )
744741 : serializeByValueID ( existingId ) ;
745742 try {
746- var metadata = registeredClientReferences . get ( clientReference ) ;
747- if ( null != metadata ) var JSCompiler_inline_result$jscomp$0 = metadata ;
748- else
749- throw Error (
750- "Expected client reference " + clientReference + " to be registered."
751- ) ;
752- clientReference = JSCompiler_inline_result$jscomp$0 ;
743+ var clientReferenceMetadata = {
744+ moduleId : clientReference . getModuleId ( ) ,
745+ exportName : "default"
746+ } ;
753747 request . pendingChunks ++ ;
754748 var importId = request . nextChunkId ++ ,
755- json = stringify ( clientReference ) ,
749+ json = stringify ( clientReferenceMetadata ) ,
756750 processedChunk = importId . toString ( 16 ) + ":I" + json + "\n" ;
757751 request . completedImportChunks . push ( processedChunk ) ;
758752 writtenClientReferences . set ( JSCompiler_inline_result , importId ) ;
@@ -852,7 +846,7 @@ function resolveModelToJSON(request, parent, key, value) {
852846 }
853847 if ( null === value ) return null ;
854848 if ( "object" === typeof value ) {
855- if ( registeredClientReferences . has ( value ) )
849+ if ( isClientReference ( value ) )
856850 return serializeClientReference ( request , parent , key , value ) ;
857851 parent = request . writtenObjects ;
858852 key = parent . get ( value ) ;
@@ -944,7 +938,7 @@ function resolveModelToJSON(request, parent, key, value) {
944938 ) ;
945939 if ( "undefined" === typeof value ) return "$undefined" ;
946940 if ( "function" === typeof value ) {
947- if ( registeredClientReferences . has ( value ) )
941+ if ( isClientReference ( value ) )
948942 return serializeClientReference ( request , parent , key , value ) ;
949943 throw Error ( "isServerReference: Not Implemented." ) ;
950944 }
@@ -1135,31 +1129,16 @@ exports.clearRequestedClientReferencesKeysSet = function () {
11351129exports . getRequestedClientReferencesKeys = function ( ) {
11361130 return Array . from ( requestedClientReferencesKeys ) ;
11371131} ;
1138- exports . registerClientReference = function ( clientReference , moduleId ) {
1139- registeredClientReferences . set ( clientReference , {
1140- moduleId : moduleId ,
1141- exportName : "default"
1142- } ) ;
1143- return clientReference ;
1144- } ;
1132+ exports . registerClientReference = function ( ) { } ;
11451133exports . registerServerReference = function ( ) {
11461134 throw Error ( "registerServerReference: Not Implemented." ) ;
11471135} ;
1148- exports . renderToDestination = function (
1149- destination ,
1150- model ,
1151- bundlerConfig ,
1152- options
1153- ) {
1136+ exports . renderToDestination = function ( destination , model , options ) {
11541137 if ( ! configured )
11551138 throw Error (
11561139 "Please make sure to call `setConfig(...)` before calling `renderToDestination`."
11571140 ) ;
1158- model = createRequest (
1159- model ,
1160- bundlerConfig ,
1161- options ? options . onError : void 0
1162- ) ;
1141+ model = createRequest ( model , null , options ? options . onError : void 0 ) ;
11631142 model . flushScheduled = null !== model . destination ;
11641143 performWork ( model ) ;
11651144 if ( 1 === model . status )
@@ -1175,7 +1154,11 @@ exports.renderToDestination = function (
11751154 }
11761155 }
11771156} ;
1157+ exports . setCheckIsClientReference = function ( impl ) {
1158+ checkIsClientReference = impl ;
1159+ } ;
11781160exports . setConfig = function ( config ) {
11791161 byteLengthImpl = config . byteLength ;
1162+ checkIsClientReference = config . isClientReference ;
11801163 configured = ! 0 ;
11811164} ;
0 commit comments