@@ -36,29 +36,26 @@ function onStreamFinished(
36
36
)
37
37
}
38
38
39
- function rscFetch ( rscId : string , serializedProps : string ) {
39
+ function rscFetchRoutes ( serializedProps : string ) {
40
40
console . log (
41
- 'rscFetch :: args:\n rscId: ' +
42
- rscId +
43
- '\n serializedProps: ' +
44
- serializedProps ,
41
+ 'rscFetchRoutes :: args:\n serializedProps: ' + serializedProps ,
45
42
)
46
- const rscCacheKey = ` ${ rscId } :: ${ serializedProps } `
43
+ const rscCacheKey = serializedProps
47
44
48
45
const cached = rscCache . get ( rscCacheKey )
49
46
if ( cached ) {
50
- console . log ( 'rscFetch :: cache hit for' , rscCacheKey )
47
+ console . log ( 'rscFetchRoutes :: cache hit for' , rscCacheKey )
51
48
return cached
52
49
} else {
53
- console . log ( 'rscFetch :: cache miss for' , rscCacheKey )
50
+ console . log ( 'rscFetchRoutes :: cache miss for' , rscCacheKey )
54
51
}
55
52
56
53
const searchParams = new URLSearchParams ( )
57
54
searchParams . set ( 'props' , serializedProps )
58
55
59
56
// TODO (RSC): During SSR we should not fetch (Is this function really
60
57
// called during SSR?)
61
- const responsePromise = fetch ( BASE_PATH + rscId + ' ?' + searchParams , {
58
+ const responsePromise = fetch ( BASE_PATH + '__rwjs__Routes ?' + searchParams , {
62
59
headers : {
63
60
'rw-rsc' : '1' ,
64
61
} ,
@@ -82,7 +79,7 @@ function rscFetch(rscId: string, serializedProps: string) {
82
79
// a new cache key that will trigger a rerender.
83
80
// TODO (RSC): What happens if you call the same RSA twice in a row?
84
81
// Like `increment()`
85
- const rscCacheKey = `${ rscId } :: ${ serializedProps } ::${ rsaId } ::${ new Date ( ) } `
82
+ const rscCacheKey = `${ serializedProps } ::${ rsaId } ::${ new Date ( ) } `
86
83
87
84
const searchParams = new URLSearchParams ( )
88
85
searchParams . set ( 'action_id' , rsaId )
@@ -150,17 +147,16 @@ function rscFetch(rscId: string, serializedProps: string) {
150
147
}
151
148
152
149
interface Props {
153
- rscId : string
154
150
rscProps : RscProps
155
151
}
156
152
157
- export const RscFetcher = ( { rscId , rscProps } : Props ) => {
153
+ export const RscFetcher = ( { rscProps } : Props ) => {
158
154
const serializedProps = JSON . stringify ( rscProps )
159
155
const [ currentRscCacheKey , setCurrentRscCacheKey ] = useState ( ( ) => {
160
156
console . log ( 'RscFetcher :: useState initial value' )
161
- // Calling rscFetch here to prime the cache
162
- rscFetch ( rscId , serializedProps )
163
- return ` ${ rscId } :: ${ serializedProps } `
157
+ // Calling rscFetchRoutes here to prime the cache
158
+ rscFetchRoutes ( serializedProps )
159
+ return serializedProps
164
160
} )
165
161
166
162
useEffect ( ( ) => {
@@ -173,19 +169,13 @@ export const RscFetcher = ({ rscId, rscProps }: Props) => {
173
169
} , [ ] )
174
170
175
171
useEffect ( ( ) => {
176
- console . log ( 'RscFetcher :: useEffect about to call rscFetch ' )
177
- // rscFetch will update rscCache with the fetched component
178
- rscFetch ( rscId , serializedProps )
179
- setCurrentRscCacheKey ( ` ${ rscId } :: ${ serializedProps } ` )
180
- } , [ rscId , serializedProps ] )
172
+ console . log ( 'RscFetcher :: useEffect about to call rscFetchRoutes ' )
173
+ // rscFetchRoutes will update rscCache with the fetched component
174
+ rscFetchRoutes ( serializedProps )
175
+ setCurrentRscCacheKey ( serializedProps )
176
+ } , [ serializedProps ] )
181
177
182
- console . log (
183
- 'RscFetcher :: current props\n' +
184
- ' rscId: ' +
185
- rscId +
186
- '\n rscProps: ' +
187
- serializedProps ,
188
- )
178
+ console . log ( 'RscFetcher :: current props\n rscProps: ' + serializedProps )
189
179
console . log ( 'RscFetcher :: rendering cache entry for\n' + currentRscCacheKey )
190
180
191
181
const component = rscCache . get ( currentRscCacheKey )
0 commit comments