Skip to content

Commit 9b34703

Browse files
Refactor client startup and component loading behavior
- Changed the `reactOnRailsPageLoaded` function to return a resolved promise after invoking the startup logic, improving consistency in handling asynchronous operations. - Updated the `reactOnRailsStoreLoaded` function to suppress unused variable warnings, enhancing code clarity. - Added an ESLint directive to the `unmountAllComponents` function to address the use of deprecated APIs, ensuring better compliance with TypeScript standards. These changes streamline the client-side rendering process and improve code quality.
1 parent 272c731 commit 9b34703

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

eslint.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ const config = tsEslint.config([
151151
},
152152
},
153153
{
154-
files: ['packages/react-on-rails/src/**/*'],
154+
files: ['packages/**/src/**/*'],
155155
rules: {
156156
'import/extensions': ['error', 'ignorePackages'],
157157
},

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export * from 'react-on-rails';
1717

1818
// Import core ReactOnRails to enhance it
1919
import ReactOnRailsCore from 'react-on-rails/ReactOnRails.client';
20+
import { onPageLoaded, onPageUnloaded } from 'react-on-rails/pageLifecycle';
21+
import { debugTurbolinks } from 'react-on-rails/turbolinksUtils';
2022

2123
// Import pro registries and features
2224
import type {
@@ -120,9 +122,6 @@ const ReactOnRailsPro = {
120122
globalThis.ReactOnRails = ReactOnRailsPro;
121123

122124
// Pro client startup with immediate hydration support
123-
import { onPageLoaded, onPageUnloaded } from 'react-on-rails/pageLifecycle';
124-
import { debugTurbolinks } from 'react-on-rails/turbolinksUtils';
125-
126125
export async function reactOnRailsPageLoaded() {
127126
debugTurbolinks('reactOnRailsPageLoaded [PRO]');
128127
// Pro: Render all components that don't have immediate_hydration

packages/react-on-rails/src/ClientRenderer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ function unmountAllComponents(): void {
182182
root.unmount();
183183
} else {
184184
// React 16-17 legacy API
185+
// eslint-disable-next-line @typescript-eslint/no-deprecated
185186
unmountComponentAtNode(domNode);
186187
}
187188
} catch (error) {

packages/react-on-rails/src/ReactOnRails.client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,16 @@ globalThis.ReactOnRails = {
8989
},
9090

9191
reactOnRailsPageLoaded() {
92-
return ClientStartup.reactOnRailsPageLoaded();
92+
ClientStartup.reactOnRailsPageLoaded();
93+
return Promise.resolve();
9394
},
9495

9596
reactOnRailsComponentLoaded(domId: string): Promise<void> {
9697
return reactOnRailsComponentLoaded(domId);
9798
},
9899

99-
reactOnRailsStoreLoaded(storeName: string): Promise<void> {
100+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
101+
reactOnRailsStoreLoaded(_storeName: string): Promise<void> {
100102
throw new Error('reactOnRailsStoreLoaded requires react-on-rails-pro package');
101103
},
102104

packages/react-on-rails/src/clientStartup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { renderAllComponents } from './ClientRenderer.ts';
44
import { onPageLoaded } from './pageLifecycle.ts';
55
import { debugTurbolinks } from './turbolinksUtils.ts';
66

7-
export async function reactOnRailsPageLoaded() {
7+
export function reactOnRailsPageLoaded() {
88
debugTurbolinks('reactOnRailsPageLoaded');
99
// Core package: Render all components after page is fully loaded
1010
renderAllComponents();

0 commit comments

Comments
 (0)