Skip to content

Commit 8e8ebdd

Browse files
linting
1 parent 6b3d694 commit 8e8ebdd

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

docs/api/javascript-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The best source of docs is the main [ReactOnRails.ts](https://github.com/shakaco
5959
getStore(name, throwIfMissing = true )
6060

6161
/**
62-
* Renders or hydrates the react element passed. In case react version is >=18 will use the new api.
62+
* Renders or hydrates the React element passed. In case React version is >=18 will use the root API.
6363
* @param domNode
6464
* @param reactElement
6565
* @param hydrate if true will perform hydration, if false will render

node_package/src/RSCClientRoot.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import RSDWClient from 'react-server-dom-webpack/client';
55
import { fetch } from './utils';
66
import transformRSCStreamAndReplayConsoleLogs from './transformRSCStreamAndReplayConsoleLogs';
77

8-
if (!('use' in React && typeof React.use === 'function')) {
8+
const { use } = React;
9+
10+
if (typeof use !== 'function') {
911
throw new Error('React.use is not defined. Please ensure you are using React 18 with experimental features enabled or React 19+ to use server components.');
1012
}
1113

12-
const { use } = React;
13-
1414
let renderCache: Record<string, Promise<React.ReactNode>> = {};
1515
export const resetRenderCache = () => {
1616
renderCache = {};

node_package/src/ReactOnRails.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ ctx.ReactOnRails = {
105105
},
106106

107107
/**
108-
* Renders or hydrates the react element passed. In case react version is >=18 will use the new api.
108+
* Renders or hydrates the React element passed. In case React version is >=18 will use the root API.
109109
* @param domNode
110110
* @param reactElement
111111
* @param hydrate if true will perform hydration, if false will render
@@ -287,7 +287,7 @@ ctx.ReactOnRails = {
287287
},
288288

289289
/**
290-
* Used by rsc payload generation by Rails
290+
* Generates RSC payload, used by Rails
291291
*/
292292
serverRenderRSCReactComponent() {
293293
throw new Error('serverRenderRSCReactComponent is supported in RSC bundle only.');

node_package/src/loadReactClientManifest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
22
import fs from 'fs';
33

4-
const loadedReactClientManifests = new Map<string, { [key: string]: unknown; }>();
4+
const loadedReactClientManifests = new Map<string, Record<string, unknown>>();
55

66
export default function loadReactClientManifest(reactClientManifestFileName: string) {
77
// React client manifest is uploaded to node renderer as an asset.

node_package/src/pageLifecycle.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,20 @@ import {
77
} from './turbolinksUtils';
88

99
type PageLifecycleCallback = () => void;
10-
enum PageState {
11-
Load = 'load',
12-
Unload = 'unload',
13-
Initial = 0
14-
}
10+
type PageState = 'load' | 'unload' | 'initial';
1511

1612
const pageLoadedCallbacks = new Set<PageLifecycleCallback>();
1713
const pageUnloadedCallbacks = new Set<PageLifecycleCallback>();
1814

19-
let currentPageState: PageState = PageState.Initial;
15+
let currentPageState: PageState = 'initial';
2016

2117
function runPageLoadedCallbacks(): void {
22-
currentPageState = PageState.Load;
18+
currentPageState = 'load';
2319
pageLoadedCallbacks.forEach((callback) => callback());
2420
}
2521

2622
function runPageUnloadedCallbacks(): void {
27-
currentPageState = PageState.Unload;
23+
currentPageState = 'unload';
2824
pageUnloadedCallbacks.forEach((callback) => callback());
2925
}
3026

@@ -78,15 +74,15 @@ function initializePageEventListeners(): void {
7874
}
7975

8076
export function onPageLoaded(callback: PageLifecycleCallback): void {
81-
if (currentPageState === PageState.Load) {
77+
if (currentPageState === 'load') {
8278
callback();
8379
}
8480
pageLoadedCallbacks.add(callback);
8581
initializePageEventListeners();
8682
}
8783

8884
export function onPageUnloaded(callback: PageLifecycleCallback): void {
89-
if (currentPageState === PageState.Unload) {
85+
if (currentPageState === 'unload') {
9086
callback();
9187
}
9288
pageUnloadedCallbacks.add(callback);

0 commit comments

Comments
 (0)