@@ -29,8 +29,7 @@ module.exports = function register() {
29
29
// $FlowFixMe[method-unbinding]
30
30
const args = Array . prototype . slice . call ( arguments , 1 ) ;
31
31
newFn . $$typeof = SERVER_REFERENCE ;
32
- newFn . $$filepath = this . $$filepath ;
33
- newFn . $$name = this . $$name ;
32
+ newFn . $$id = this . $$id ;
34
33
newFn . $$bound = this . $$bound . concat ( args ) ;
35
34
}
36
35
return newFn ;
@@ -44,14 +43,14 @@ module.exports = function register() {
44
43
// These names are a little too common. We should probably have a way to
45
44
// have the Flight runtime extract the inner target instead.
46
45
return target . $$typeof ;
47
- case 'filepath' :
48
- return target . filepath ;
46
+ case '$$id' :
47
+ return target . $$id ;
48
+ case '$$async' :
49
+ return target . $$async ;
49
50
case 'name' :
50
51
return target . name ;
51
52
case 'displayName' :
52
53
return undefined ;
53
- case 'async' :
54
- return target . async ;
55
54
// We need to special case this because createElement reads it if we pass this
56
55
// reference.
57
56
case 'defaultProps' :
@@ -69,20 +68,8 @@ module.exports = function register() {
69
68
`that itself renders a Client Context Provider.` ,
70
69
) ;
71
70
}
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 ) ;
86
73
throw new Error (
87
74
`Cannot access ${expression } on the server . ` +
88
75
'You cannot dot into a client module from a server component. ' +
@@ -103,15 +90,13 @@ module.exports = function register() {
103
90
switch (name) {
104
91
// These names are read by the Flight runtime if you end up using the exports object.
105
92
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.
108
93
return target.$$typeof;
109
- case 'filepath' :
110
- return target . filepath ;
94
+ case '$$id':
95
+ return target.$$id;
96
+ case '$$async':
97
+ return target.$$async;
111
98
case 'name':
112
99
return target.name;
113
- case 'async' :
114
- return target . async ;
115
100
// We need to special case this because createElement reads it if we pass this
116
101
// reference.
117
102
case 'defaultProps':
@@ -125,7 +110,7 @@ module.exports = function register() {
125
110
case '__esModule':
126
111
// Something is conditionally checking which export to use. We'll pretend to be
127
112
// an ESM compat module but then we'll check again on the client.
128
- const moduleId = target . filepath ;
113
+ const moduleId = target.$$id ;
129
114
target.default = Object.defineProperties(
130
115
(function () {
131
116
throw new Error(
@@ -136,12 +121,11 @@ module.exports = function register() {
136
121
) ;
137
122
} : any ) ,
138
123
{
124
+ $$typeof : { value : CLIENT_REFERENCE } ,
139
125
// This a placeholder value that tells the client to conditionally use the
140
126
// 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 } ,
145
129
} ,
146
130
) ;
147
131
return true ;
@@ -150,17 +134,15 @@ module.exports = function register() {
150
134
// Use a cached value
151
135
return target . then ;
152
136
}
153
- if ( ! target . async ) {
137
+ if ( ! target . $$ async) {
154
138
// If this module is expected to return a Promise (such as an AsyncModule) then
155
139
// we should resolve that with a client reference that unwraps the Promise on
156
140
// the client.
157
141
158
142
const clientReference = Object . defineProperties ( ( { } : any ) , {
159
- // Represents the whole Module object instead of a particular import.
160
- name : { value : '*' } ,
161
143
$$typeof : { value : CLIENT_REFERENCE } ,
162
- filepath : { value : target . filepath } ,
163
- async : { value : true } ,
144
+ $$id : { value : target . $$id } ,
145
+ $$ async : { value : true } ,
164
146
} ) ;
165
147
const proxy = new Proxy ( clientReference , proxyHandlers ) ;
166
148
@@ -176,10 +158,9 @@ module.exports = function register() {
176
158
// If this is not used as a Promise but is treated as a reference to a `.then`
177
159
// export then we should treat it as a reference to that name.
178
160
{
179
- name : { value : 'then' } ,
180
161
$$typeof : { value : CLIENT_REFERENCE } ,
181
- filepath : { value : target . filepath } ,
182
- async : { value : false } ,
162
+ $$id : { value : target . $$id + '#then' } ,
163
+ $$ async : { value : false } ,
183
164
} ,
184
165
) ) ;
185
166
return then ;
@@ -206,8 +187,8 @@ module.exports = function register() {
206
187
{
207
188
name : { value : name } ,
208
189
$$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} ,
211
192
} ,
212
193
) ;
213
194
cachedReference = target [ name ] = new Proxy (
@@ -284,11 +265,10 @@ module.exports = function register() {
284
265
if ( useClient ) {
285
266
const moduleId : string = ( url . pathToFileURL ( filename ) . href : any ) ;
286
267
const clientReference = Object . defineProperties ( ( { } : any ) , {
287
- // Represents the whole Module object instead of a particular import.
288
- name : { value : '*' } ,
289
268
$$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 } ,
292
272
} ) ;
293
273
// $FlowFixMe[incompatible-call] found when upgrading Flow
294
274
this . exports = new Proxy ( clientReference , proxyHandlers ) ;
@@ -306,10 +286,9 @@ module.exports = function register() {
306
286
if ( typeof exports === 'function' ) {
307
287
// The module exports a function directly,
308
288
Object . defineProperties ( ( exports : any ) , {
309
- // Represents the whole Module object instead of a particular import.
310
289
$$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 } ,
313
292
$$bound : { value : [ ] } ,
314
293
} ) ;
315
294
} else {
@@ -320,8 +299,7 @@ module.exports = function register() {
320
299
if ( typeof value === 'function' ) {
321
300
Object . defineProperties ( ( value : any ) , {
322
301
$$typeof : { value : SERVER_REFERENCE } ,
323
- $$filepath : { value : moduleId } ,
324
- $$name : { value : key } ,
302
+ $$id : { value : moduleId + '#' + key } ,
325
303
$$bound : { value : [ ] } ,
326
304
} ) ;
327
305
}
0 commit comments