@@ -4,8 +4,6 @@ import getReactServerComponent from './getReactServerComponent.client.ts';
44import { createRSCPayloadKey } from './utils.ts' ;
55
66type RSCContextType = {
7- getCachedComponent : ( componentName : string , componentProps : unknown ) => React . ReactNode ;
8-
97 getComponent : ( componentName : string , componentProps : unknown ) => Promise < React . ReactNode > ;
108
119 refetchComponent : ( componentName : string , componentProps : unknown ) => Promise < React . ReactNode > ;
@@ -39,31 +37,21 @@ export const createRSCProvider = ({
3937 railsContext : RailsContextWithComponentSpecificMetadata ;
4038 getServerComponent : typeof getReactServerComponent ;
4139} ) => {
42- const cachedComponents : Record < string , React . ReactNode > = { } ;
4340 const fetchRSCPromises : Record < string , Promise < React . ReactNode > > = { } ;
4441
45- const getCachedComponent = ( componentName : string , componentProps : unknown ) => {
46- const key = createRSCPayloadKey ( componentName , componentProps , railsContext ) ;
47- return cachedComponents [ key ] ;
48- } ;
49-
5042 const getComponent = ( componentName : string , componentProps : unknown ) => {
5143 const key = createRSCPayloadKey ( componentName , componentProps , railsContext ) ;
5244 if ( key in fetchRSCPromises ) {
5345 return fetchRSCPromises [ key ] ;
5446 }
5547
56- const promise = getServerComponent ( { componentName, componentProps, railsContext } ) . then ( ( rsc ) => {
57- cachedComponents [ key ] = rsc ;
58- return rsc ;
59- } ) ;
48+ const promise = getServerComponent ( { componentName, componentProps, railsContext } ) ;
6049 fetchRSCPromises [ key ] = promise ;
6150 return promise ;
6251 } ;
6352
6453 const refetchComponent = ( componentName : string , componentProps : unknown ) => {
6554 const key = createRSCPayloadKey ( componentName , componentProps , railsContext ) ;
66- cachedComponents [ key ] = undefined ;
6755 const promise = getServerComponent ( {
6856 componentName,
6957 componentProps,
@@ -74,7 +62,7 @@ export const createRSCProvider = ({
7462 return promise ;
7563 } ;
7664
77- const contextValue = { getCachedComponent , getComponent, refetchComponent } ;
65+ const contextValue = { getComponent, refetchComponent } ;
7866
7967 return ( { children } : { children : React . ReactNode } ) => {
8068 return < RSCContext . Provider value = { contextValue } > { children } </ RSCContext . Provider > ;
@@ -85,8 +73,8 @@ export const createRSCProvider = ({
8573 * Hook to access the RSC context within client components.
8674 *
8775 * This hook provides access to:
88- * - getCachedComponent: For retrieving already rendered server components
8976 * - getComponent: For fetching and rendering server components
77+ * - refetchComponent: For refetching server components
9078 *
9179 * It must be used within a component wrapped by RSCProvider (typically done
9280 * automatically by wrapServerComponentRenderer).
0 commit comments