Skip to content

Commit 9bebfc4

Browse files
Refactor RSC payload key generation to include domNodeId
1 parent 1179f40 commit 9bebfc4

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

node_package/src/getReactServerComponent.client.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ const createFromPreloadedPayloads = (payloads: string[]) => {
165165
const getReactServerComponent =
166166
(domNodeId: string, railsContext: RailsContext) =>
167167
({ componentName, componentProps, enforceRefetch = false }: ClientGetReactServerComponentProps) => {
168-
const componentCacheKey = createRSCPayloadKey(componentName, componentProps);
169-
170-
const rscPayloadKey = `${componentCacheKey}-${domNodeId}`;
168+
const rscPayloadKey = createRSCPayloadKey(componentName, componentProps, domNodeId);
171169
const payloads = window.REACT_ON_RAILS_RSC_PAYLOADS?.[rscPayloadKey];
172170
if (!enforceRefetch && payloads) {
173171
return createFromPreloadedPayloads(payloads);

node_package/src/injectRSCPayload.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ export default function injectRSCPayload(
210210

211211
rscRequestTracker.onRSCPayloadGenerated((streamInfo) => {
212212
const { stream, props, componentName } = streamInfo;
213-
const cacheKey = createRSCPayloadKey(componentName, props);
214-
const rscPayloadKey = `${cacheKey}-${domNodeId}`;
213+
const rscPayloadKey = createRSCPayloadKey(componentName, props, domNodeId);
215214

216215
// CRITICAL TIMING: Initialize global array IMMEDIATELY when component requests RSC
217216
// This ensures the array exists before the component's HTML is rendered and sent.

node_package/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export { customFetch as fetch };
2121
* @param componentProps - Props passed to the component (serialized to JSON)
2222
* @returns A unique cache key string
2323
*/
24-
export const createRSCPayloadKey = (componentName: string, componentProps: unknown) => {
25-
return `${componentName}-${JSON.stringify(componentProps)}`;
24+
export const createRSCPayloadKey = (componentName: string, componentProps: unknown, domNodeId?: string) => {
25+
return `${componentName}-${JSON.stringify(componentProps)}${domNodeId ? `-${domNodeId}` : ''}`;
2626
};
2727

2828
/**

0 commit comments

Comments
 (0)