Skip to content

Commit 7a9f539

Browse files
justin808claude
andcommitted
Fix React 18.0.0 compatibility by using React namespace imports
Changed from named imports to React namespace for better compatibility with React 18.0.0: - `Component` → `React.Component` - `createContext` → `React.createContext` - `useContext` → `React.useContext` - `use` → `React.use` This fixes the build (20) CI failure where React is downgraded to 18.0.0 for minimum version testing. Named exports may not be available in older React versions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent c1a8229 commit 7a9f539

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

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

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

1515
'use client';
1616

17-
import { createContext, useContext, type ReactNode } from 'react';
17+
import * as React from 'react';
18+
import { type ReactNode } from 'react';
1819
import type { ClientGetReactServerComponentProps } from './getReactServerComponent.client.ts';
1920
import { createRSCPayloadKey } from './utils.ts';
2021

@@ -24,7 +25,7 @@ type RSCContextType = {
2425
refetchComponent: (componentName: string, componentProps: unknown) => Promise<ReactNode>;
2526
};
2627

27-
const RSCContext = createContext<RSCContextType | undefined>(undefined);
28+
const RSCContext = React.createContext<RSCContextType | undefined>(undefined);
2829

2930
/**
3031
* Creates a provider context for React Server Components.
@@ -101,7 +102,7 @@ export const createRSCProvider = ({
101102
* ```
102103
*/
103104
export const useRSC = () => {
104-
const context = useContext(RSCContext);
105+
const context = React.useContext(RSCContext);
105106
if (!context) {
106107
throw new Error('useRSC must be used within a RSCProvider');
107108
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616

1717
'use client';
1818

19-
import { Component, use, type ReactNode } from 'react';
19+
import * as React from 'react';
20+
import { type ReactNode } from 'react';
2021
import { useRSC } from './RSCProvider.tsx';
2122
import { ServerComponentFetchError } from './ServerComponentFetchError.ts';
2223

2324
/**
2425
* Error boundary component for RSCRoute that adds server component name and props to the error
2526
* So, the parent ErrorBoundary can refetch the server component
2627
*/
27-
class RSCRouteErrorBoundary extends Component<
28+
class RSCRouteErrorBoundary extends React.Component<
2829
{ children: ReactNode; componentName: string; componentProps: unknown },
2930
{ error: Error | null }
3031
> {
@@ -76,8 +77,8 @@ export type RSCRouteProps = {
7677
};
7778

7879
const PromiseWrapper = ({ promise }: { promise: Promise<ReactNode> }) => {
79-
// use is available in React 18.3+
80-
const promiseResult = use(promise);
80+
// React.use is available in React 18.3+
81+
const promiseResult = React.use(promise);
8182

8283
// In case that an error happened during the rendering of the RSC payload before the rendering of the component itself starts
8384
// RSC bundle will return an error object serialized inside the RSC payload

0 commit comments

Comments
 (0)