Skip to content

Commit 5f48cc7

Browse files
removed the functionality of caching components, react already caches them
1 parent 7b2e1f1 commit 5f48cc7

File tree

3 files changed

+5
-17
lines changed

3 files changed

+5
-17
lines changed

node_package/src/RSCProvider.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import getReactServerComponent from './getReactServerComponent.client.ts';
44
import { createRSCPayloadKey } from './utils.ts';
55

66
type 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).

node_package/src/getReactServerComponent.client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const createFromPreloadedPayloads = (payloads: string[]) => {
121121
* @returns A Promise resolving to the rendered React element
122122
*
123123
* @important This is an internal function. End users should not use this directly.
124-
* Instead, use the useRSC hook which provides getComponent and getCachedComponent functions
124+
* Instead, use the useRSC hook which provides getComponent and refetchComponent functions
125125
* for fetching or retrieving cached server components. For rendering server components,
126126
* consider using RSCRoute component which handles the rendering logic automatically.
127127
*/

node_package/src/getReactServerComponent.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const createFromReactOnRailsNodeStream = async (
5050
* @returns A Promise resolving to the rendered React element
5151
*
5252
* @important This is an internal function. End users should not use this directly.
53-
* Instead, use the useRSC hook which provides getComponent and getCachedComponent functions
53+
* Instead, use the useRSC hook which provides getComponent and refetchComponent functions
5454
* for fetching or retrieving cached server components. For rendering server components,
5555
* consider using RSCRoute component which handles the rendering logic automatically.
5656
*/

0 commit comments

Comments
 (0)