Skip to content

Commit d6628ac

Browse files
convert createElement calls to jsx
1 parent 307ab96 commit d6628ac

File tree

3 files changed

+35
-30
lines changed

3 files changed

+35
-30
lines changed

eslint.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const config = tsEslint.config([
7575
alias: [['Assets', './spec/dummy/client/app/assets']],
7676

7777
node: {
78-
extensions: ['.js', '.jsx', '.ts', '.d.ts'],
78+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts'],
7979
},
8080
},
8181
},
@@ -100,6 +100,7 @@ const config = tsEslint.config([
100100
js: 'never',
101101
jsx: 'never',
102102
ts: 'never',
103+
tsx: 'never',
103104
},
104105
],
105106

@@ -132,6 +133,12 @@ const config = tsEslint.config([
132133
'react/jsx-props-no-spreading': 'off',
133134
'react/static-property-placement': 'off',
134135
'jsx-a11y/anchor-is-valid': 'off',
136+
'react/jsx-filename-extension': [
137+
'error',
138+
{
139+
extensions: ['.jsx', '.tsx'],
140+
},
141+
],
135142
},
136143
},
137144
{

node_package/src/RSCPayloadContainer.ts renamed to node_package/src/RSCPayloadContainer.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,28 @@ const RSCPayloadContainer = ({
4444
const chunkPromise = getChunkPromise(chunkIndex);
4545
const chunk = React.use(chunkPromise);
4646

47-
const scriptElement = React.createElement('script', {
48-
dangerouslySetInnerHTML: {
49-
// Ensure the array is never reassigned.
50-
// Even at the RSCClientRoot component, the array is assigned
51-
// only if it's not already assigned by this script.
52-
__html: escapeScript(`(self.REACT_ON_RAILS_RSC_PAYLOAD||=[]).push(${chunk.chunk})`),
53-
},
54-
key: `script-${chunkIndex}`,
55-
});
47+
const scriptElement = (
48+
<script
49+
// eslint-disable-next-line react/no-danger
50+
dangerouslySetInnerHTML={{
51+
__html: escapeScript(`(self.REACT_ON_RAILS_RSC_PAYLOAD||=[]).push(${chunk.chunk})`),
52+
}}
53+
key={`script-${chunkIndex}`}
54+
/>
55+
);
5656

5757
if (chunk.isLastChunk) {
5858
return scriptElement;
5959
}
6060

61-
return React.createElement(React.Fragment, null, [
62-
scriptElement,
63-
React.createElement(
64-
React.Suspense,
65-
{ fallback: null, key: `suspense-${chunkIndex}` },
66-
React.createElement(RSCPayloadContainer, { chunkIndex: chunkIndex + 1, getChunkPromise }),
67-
),
68-
]);
61+
return (
62+
<>
63+
{scriptElement}
64+
<React.Suspense fallback={null} key={`suspense-${chunkIndex}`}>
65+
<RSCPayloadContainer chunkIndex={chunkIndex + 1} getChunkPromise={getChunkPromise} />
66+
</React.Suspense>
67+
</>
68+
);
6969
};
7070

7171
export default function RSCPayloadContainerWrapper({ RSCPayloadStream }: RSCPayloadContainerProps) {
@@ -113,9 +113,9 @@ export default function RSCPayloadContainerWrapper({ RSCPayloadStream }: RSCPayl
113113
[chunkPromises],
114114
);
115115

116-
return React.createElement(
117-
React.Suspense,
118-
{ fallback: null },
119-
React.createElement(RSCPayloadContainer, { chunkIndex: 0, getChunkPromise }),
116+
return (
117+
<React.Suspense fallback={null}>
118+
<RSCPayloadContainer chunkIndex={0} getChunkPromise={getChunkPromise} />
119+
</React.Suspense>
120120
);
121121
}

node_package/src/RSCServerRoot.ts renamed to node_package/src/RSCServerRoot.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,12 @@ const RSCServerRoot: RenderFunction = async (
104104
rscPayloadStream.pipe(rscPayloadStream2);
105105
const serverComponentElement = createFromReactOnRailsNodeStream(rscPayloadStream1, ssrManifest);
106106

107-
return () =>
108-
React.createElement(React.Fragment, null, [
109-
React.createElement(React.Fragment, { key: 'serverComponentElement' }, use(serverComponentElement)),
110-
React.createElement(RSCPayloadContainer, {
111-
RSCPayloadStream: rscPayloadStream2,
112-
key: 'rscPayloadContainer',
113-
}),
114-
]);
107+
return () => (
108+
<>
109+
<React.Fragment key="serverComponentElement">{use(serverComponentElement)}</React.Fragment>
110+
<RSCPayloadContainer RSCPayloadStream={rscPayloadStream2} key="rscPayloadContainer" />
111+
</>
112+
);
115113
};
116114

117115
export default RSCServerRoot;

0 commit comments

Comments
 (0)