Skip to content

Commit a4752c3

Browse files
Refactor ReactOnRails imports and enhance server component functionality
- Updated import paths to directly reference ReactOnRails.client.ts, improving clarity and consistency across the codebase. - Enhanced the createReactOnRailsPro function to conditionally assign server-rendering methods, ensuring better integration of Pro-specific features. - Removed the obsolete index.ts file, streamlining the package structure and reducing unnecessary complexity. These changes improve the organization and functionality of the React on Rails Pro package.
1 parent b224987 commit a4752c3

File tree

7 files changed

+15
-23
lines changed

7 files changed

+15
-23
lines changed

packages/react-on-rails-pro/src/createReactOnRailsPro.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ export default function createReactOnRailsPro(
143143
// the functions object above
144144
const reactOnRailsPro = baseObject as unknown as ReactOnRailsInternal;
145145

146+
if (reactOnRailsPro.streamServerRenderedReactComponent) {
147+
// eslint-disable-next-line @typescript-eslint/unbound-method
148+
reactOnRailsProSpecificFunctions.streamServerRenderedReactComponent = reactOnRailsPro.streamServerRenderedReactComponent;
149+
}
150+
151+
if (reactOnRailsPro.serverRenderRSCReactComponent) {
152+
// eslint-disable-next-line @typescript-eslint/unbound-method
153+
reactOnRailsProSpecificFunctions.serverRenderRSCReactComponent = reactOnRailsPro.serverRenderRSCReactComponent;
154+
}
155+
146156
// Assign Pro-specific functions to the ReactOnRailsPro object using Object.assign
147157
// This pattern ensures we add exactly what's defined in the type, nothing more, nothing less
148158
Object.assign(reactOnRailsPro, reactOnRailsProSpecificFunctions);

packages/react-on-rails-pro/src/index.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/react-on-rails-pro/src/registerServerComponent/client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import * as React from 'react';
1616
import { ReactComponentOrRenderFunction } from 'react-on-rails/types';
17-
import ReactOnRails from '../index.ts';
17+
import ReactOnRails from '../ReactOnRails.client.ts';
1818
import RSCRoute from '../RSCRoute.tsx';
1919
import wrapServerComponentRenderer from '../wrapServerComponentRenderer/client.tsx';
2020

packages/react-on-rails-pro/src/registerServerComponent/server.rsc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
* https://github.com/shakacode/react_on_rails/blob/master/REACT-ON-RAILS-PRO-LICENSE.md
1313
*/
1414

15-
import ReactOnRails from 'react-on-rails/ReactOnRails.client';
1615
import { ReactComponent, RenderFunction } from 'react-on-rails/types';
16+
import ReactOnRails from '../ReactOnRails.client.ts';
1717

1818
/**
1919
* Registers React Server Components in the RSC bundle.

packages/react-on-rails-pro/src/registerServerComponent/server.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
*/
1414

1515
import * as React from 'react';
16-
import ReactOnRails from 'react-on-rails/ReactOnRails.client';
1716
import { ReactComponent, RenderFunction } from 'react-on-rails/types';
17+
import ReactOnRails from '../ReactOnRails.client.ts';
1818
import RSCRoute from '../RSCRoute.tsx';
1919
import wrapServerComponentRenderer from '../wrapServerComponentRenderer/server.tsx';
2020

packages/react-on-rails-pro/tests/registerServerComponent.client.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import '@testing-library/jest-dom';
1010
import * as path from 'path';
1111
import * as fs from 'fs';
1212
import { createNodeReadableStream, getNodeVersion } from './testUtils.js';
13-
import ReactOnRails from '../src/index.ts';
13+
import ReactOnRails from '../src/ReactOnRails.client.ts';
1414
import registerServerComponent from '../src/registerServerComponent/client.tsx';
1515
import { clear as clearComponentRegistry } from '../src/ComponentRegistry.ts';
1616

packages/react-on-rails-pro/tests/streamServerRenderedReactComponent.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as React from 'react';
66
import * as PropTypes from 'prop-types';
77
import streamServerRenderedReactComponent from '../src/streamServerRenderedReactComponent.ts';
88
import * as ComponentRegistry from '../src/ComponentRegistry.ts';
9-
import ReactOnRails from '../src/index.ts';
9+
import ReactOnRails from '../src/ReactOnRails.node.ts';
1010

1111
const AsyncContent = async ({ throwAsyncError }) => {
1212
await new Promise((resolve) => {

0 commit comments

Comments
 (0)