@@ -29,8 +29,7 @@ module.exports = function register() {
2929 // $FlowFixMe[method-unbinding]
3030 const args = Array . prototype . slice . call ( arguments , 1 ) ;
3131 newFn . $$typeof = SERVER_REFERENCE ;
32- newFn . $$filepath = this . $$filepath ;
33- newFn . $$name = this . $$name ;
32+ newFn . $$id = this . $$id ;
3433 newFn . $$bound = this . $$bound . concat ( args ) ;
3534 }
3635 return newFn ;
@@ -44,14 +43,14 @@ module.exports = function register() {
4443 // These names are a little too common. We should probably have a way to
4544 // have the Flight runtime extract the inner target instead.
4645 return target . $$typeof ;
47- case 'filepath' :
48- return target . filepath ;
46+ case '$$id' :
47+ return target . $$id ;
48+ case '$$async' :
49+ return target . $$async ;
4950 case 'name' :
5051 return target . name ;
5152 case 'displayName' :
5253 return undefined ;
53- case 'async' :
54- return target . async ;
5554 // We need to special case this because createElement reads it if we pass this
5655 // reference.
5756 case 'defaultProps' :
@@ -69,20 +68,8 @@ module.exports = function register() {
6968 `that itself renders a Client Context Provider.` ,
7069 ) ;
7170 }
72- let expression ;
73- switch ( target . name ) {
74- case '':
75- // eslint-disable-next-line react-internal/safe-string-coercion
76- expression = String ( name ) ;
77- break ;
78- case '* ':
79- // eslint-disable-next-line react-internal/safe-string-coercion
80- expression = String ( name ) ;
81- break ;
82- default :
83- // eslint-disable-next-line react-internal/safe-string-coercion
84- expression = String ( target . name ) + '. ' + String ( name ) ;
85- }
71+ // eslint-disable-next-line react-internal/safe-string-coercion
72+ const expression = String ( target . name ) + '. ' + String ( name ) ;
8673 throw new Error (
8774 `Cannot access ${expression } on the server . ` +
8875 'You cannot dot into a client module from a server component. ' +
@@ -103,15 +90,13 @@ module.exports = function register() {
10390 switch (name) {
10491 // These names are read by the Flight runtime if you end up using the exports object.
10592 case '$$typeof':
106- // These names are a little too common. We should probably have a way to
107- // have the Flight runtime extract the inner target instead.
10893 return target.$$typeof;
109- case 'filepath' :
110- return target . filepath ;
94+ case '$$id':
95+ return target.$$id;
96+ case '$$async':
97+ return target.$$async;
11198 case 'name':
11299 return target.name;
113- case 'async' :
114- return target . async ;
115100 // We need to special case this because createElement reads it if we pass this
116101 // reference.
117102 case 'defaultProps':
@@ -125,7 +110,7 @@ module.exports = function register() {
125110 case '__esModule':
126111 // Something is conditionally checking which export to use. We'll pretend to be
127112 // an ESM compat module but then we'll check again on the client.
128- const moduleId = target . filepath ;
113+ const moduleId = target.$$id ;
129114 target.default = Object.defineProperties(
130115 (function () {
131116 throw new Error(
@@ -136,12 +121,11 @@ module.exports = function register() {
136121 ) ;
137122 } : any ) ,
138123 {
124+ $$typeof : { value : CLIENT_REFERENCE } ,
139125 // This a placeholder value that tells the client to conditionally use the
140126 // whole object or just the default export.
141- name : { value : '' } ,
142- $$typeof : { value : CLIENT_REFERENCE } ,
143- filepath : { value : target . filepath } ,
144- async : { value : target . async } ,
127+ $$id : { value : target . $$id + '#' } ,
128+ $$async : { value : target . $$async } ,
145129 } ,
146130 ) ;
147131 return true ;
@@ -150,17 +134,15 @@ module.exports = function register() {
150134 // Use a cached value
151135 return target . then ;
152136 }
153- if ( ! target . async ) {
137+ if ( ! target . $$ async) {
154138 // If this module is expected to return a Promise (such as an AsyncModule) then
155139 // we should resolve that with a client reference that unwraps the Promise on
156140 // the client.
157141
158142 const clientReference = Object . defineProperties ( ( { } : any ) , {
159- // Represents the whole Module object instead of a particular import.
160- name : { value : '*' } ,
161143 $$typeof : { value : CLIENT_REFERENCE } ,
162- filepath : { value : target . filepath } ,
163- async : { value : true } ,
144+ $$id : { value : target . $$id } ,
145+ $$ async : { value : true } ,
164146 } ) ;
165147 const proxy = new Proxy ( clientReference , proxyHandlers ) ;
166148
@@ -176,10 +158,9 @@ module.exports = function register() {
176158 // If this is not used as a Promise but is treated as a reference to a `.then`
177159 // export then we should treat it as a reference to that name.
178160 {
179- name : { value : 'then' } ,
180161 $$typeof : { value : CLIENT_REFERENCE } ,
181- filepath : { value : target . filepath } ,
182- async : { value : false } ,
162+ $$id : { value : target . $$id + '#then' } ,
163+ $$ async : { value : false } ,
183164 } ,
184165 ) ) ;
185166 return then ;
@@ -206,8 +187,8 @@ module.exports = function register() {
206187 {
207188 name : { value : name } ,
208189 $$typeof : { value : CLIENT_REFERENCE } ,
209- filepath : { value : target . filepath } ,
210- async : { value : target . async } ,
190+ $$id : { value : target . $$id + '#' + name } ,
191+ $$ async : { value : target . $$ async} ,
211192 } ,
212193 ) ;
213194 cachedReference = target [ name ] = new Proxy (
@@ -284,11 +265,10 @@ module.exports = function register() {
284265 if ( useClient ) {
285266 const moduleId : string = ( url . pathToFileURL ( filename ) . href : any ) ;
286267 const clientReference = Object . defineProperties ( ( { } : any ) , {
287- // Represents the whole Module object instead of a particular import.
288- name : { value : '*' } ,
289268 $$typeof : { value : CLIENT_REFERENCE } ,
290- filepath : { value : moduleId } ,
291- async : { value : false } ,
269+ // Represents the whole Module object instead of a particular import.
270+ $$id : { value : moduleId } ,
271+ $$async : { value : false } ,
292272 } ) ;
293273 // $FlowFixMe[incompatible-call] found when upgrading Flow
294274 this . exports = new Proxy ( clientReference , proxyHandlers ) ;
@@ -306,10 +286,9 @@ module.exports = function register() {
306286 if ( typeof exports === 'function' ) {
307287 // The module exports a function directly,
308288 Object . defineProperties ( ( exports : any ) , {
309- // Represents the whole Module object instead of a particular import.
310289 $$typeof : { value : SERVER_REFERENCE } ,
311- $$filepath : { value : moduleId } ,
312- $$name : { value : '*' } ,
290+ // Represents the whole Module object instead of a particular import.
291+ $$id : { value : moduleId } ,
313292 $$bound : { value : [ ] } ,
314293 } ) ;
315294 } else {
@@ -320,8 +299,7 @@ module.exports = function register() {
320299 if ( typeof value === 'function' ) {
321300 Object . defineProperties ( ( value : any ) , {
322301 $$typeof : { value : SERVER_REFERENCE } ,
323- $$filepath : { value : moduleId } ,
324- $$name : { value : key } ,
302+ $$id : { value : moduleId + '#' + key } ,
325303 $$bound : { value : [ ] } ,
326304 } ) ;
327305 }
0 commit comments