Skip to content

Commit 93daa83

Browse files
justin808claude
andcommitted
Restore 'use client' directives to RSCProvider and RSCRoute
These files MUST be client components because they use client-only React APIs: - React.createContext and React.useContext (RSCProvider) - React.Component class (RSCRoute) The previous commit incorrectly removed 'use client' from these files. The ESLint rule preventing 'use client' only applies to .server.tsx files, not to regular .tsx files that need client-side APIs. Without 'use client', webpack includes these files in the server bundle, which fails because React's server exports don't include client-only APIs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent beff1b4 commit 93daa83

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

packages/react-on-rails-pro/src/RSCProvider.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
* https://github.com/shakacode/react_on_rails/blob/master/REACT-ON-RAILS-PRO-LICENSE.md
1313
*/
1414

15-
import type { ReactNode } from 'react';
15+
'use client';
16+
1617
import * as React from 'react';
1718
import type { ClientGetReactServerComponentProps } from './getReactServerComponent.client.ts';
1819
import { createRSCPayloadKey } from './utils.ts';
1920

2021
type RSCContextType = {
21-
getComponent: (componentName: string, componentProps: unknown) => Promise<ReactNode>;
22+
getComponent: (componentName: string, componentProps: unknown) => Promise<React.ReactNode>;
2223

23-
refetchComponent: (componentName: string, componentProps: unknown) => Promise<ReactNode>;
24+
refetchComponent: (componentName: string, componentProps: unknown) => Promise<React.ReactNode>;
2425
};
2526

2627
const RSCContext = React.createContext<RSCContextType | undefined>(undefined);
@@ -47,9 +48,9 @@ const RSCContext = React.createContext<RSCContextType | undefined>(undefined);
4748
export const createRSCProvider = ({
4849
getServerComponent,
4950
}: {
50-
getServerComponent: (props: ClientGetReactServerComponentProps) => Promise<ReactNode>;
51+
getServerComponent: (props: ClientGetReactServerComponentProps) => Promise<React.ReactNode>;
5152
}) => {
52-
const fetchRSCPromises: Record<string, Promise<ReactNode>> = {};
53+
const fetchRSCPromises: Record<string, Promise<React.ReactNode>> = {};
5354

5455
const getComponent = (componentName: string, componentProps: unknown) => {
5556
const key = createRSCPayloadKey(componentName, componentProps);
@@ -75,7 +76,7 @@ export const createRSCProvider = ({
7576

7677
const contextValue = { getComponent, refetchComponent };
7778

78-
return ({ children }: { children: ReactNode }) => {
79+
return ({ children }: { children: React.ReactNode }) => {
7980
return <RSCContext.Provider value={contextValue}>{children}</RSCContext.Provider>;
8081
};
8182
};

packages/react-on-rails-pro/src/RSCRoute.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
/// <reference types="react/experimental" />
1616

17-
import type { ReactNode } from 'react';
17+
'use client';
18+
1819
import * as React from 'react';
1920
import { useRSC } from './RSCProvider.tsx';
2021
import { ServerComponentFetchError } from './ServerComponentFetchError.ts';
@@ -24,10 +25,10 @@ import { ServerComponentFetchError } from './ServerComponentFetchError.ts';
2425
* So, the parent ErrorBoundary can refetch the server component
2526
*/
2627
class RSCRouteErrorBoundary extends React.Component<
27-
{ children: ReactNode; componentName: string; componentProps: unknown },
28+
{ children: React.ReactNode; componentName: string; componentProps: unknown },
2829
{ error: Error | null }
2930
> {
30-
constructor(props: { children: ReactNode; componentName: string; componentProps: unknown }) {
31+
constructor(props: { children: React.ReactNode; componentName: string; componentProps: unknown }) {
3132
super(props);
3233
this.state = { error: null };
3334
}
@@ -74,7 +75,7 @@ export type RSCRouteProps = {
7475
componentProps: unknown;
7576
};
7677

77-
const PromiseWrapper = ({ promise }: { promise: Promise<ReactNode> }) => {
78+
const PromiseWrapper = ({ promise }: { promise: Promise<React.ReactNode> }) => {
7879
// React.use is available in React 18.3+
7980
const promiseResult = React.use(promise);
8081

@@ -87,7 +88,7 @@ const PromiseWrapper = ({ promise }: { promise: Promise<ReactNode> }) => {
8788
return promiseResult;
8889
};
8990

90-
const RSCRoute = ({ componentName, componentProps }: RSCRouteProps): ReactNode => {
91+
const RSCRoute = ({ componentName, componentProps }: RSCRouteProps): React.ReactNode => {
9192
const { getComponent } = useRSC();
9293
const componentPromise = getComponent(componentName, componentProps);
9394
return (

0 commit comments

Comments
 (0)