Skip to content

Commit 676381e

Browse files
remove options parameter from registerServerComponent and update related tests
1 parent 97f440e commit 676381e

File tree

5 files changed

+10
-26
lines changed

5 files changed

+10
-26
lines changed

lib/react_on_rails/packs_generator.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,10 @@ def pack_file_contents(file_path)
9393
ReactOnRailsPro.configuration.enable_rsc_support
9494

9595
if load_server_components && !client_entrypoint?(file_path)
96-
rsc_payload_generation_url_path = ReactOnRailsPro.configuration.rsc_payload_generation_url_path
97-
9896
return <<~FILE_CONTENT.strip
9997
import registerServerComponent from 'react-on-rails/registerServerComponent/client';
10098
101-
registerServerComponent({
102-
rscPayloadGenerationUrlPath: "#{rsc_payload_generation_url_path}",
103-
}, "#{registered_component_name}")
99+
registerServerComponent("#{registered_component_name}");
104100
FILE_CONTENT
105101
end
106102

node_package/src/registerServerComponent/client.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import ReactOnRails from '../ReactOnRails.client.ts';
33
import RSCRoute from '../RSCRoute.ts';
4-
import { ReactComponentOrRenderFunction, RegisterServerComponentOptions } from '../types/index.ts';
4+
import { ReactComponentOrRenderFunction } from '../types/index.ts';
55
import WrapServerComponentRenderer from '../wrapServerComponentRenderer/client.tsx';
66

77
/**
@@ -29,14 +29,12 @@ import WrapServerComponentRenderer from '../wrapServerComponentRenderer/client.t
2929
*
3030
* @example
3131
* ```js
32-
* registerServerComponent({
33-
* rscPayloadGenerationUrlPath: '/rsc_payload'
34-
* }, 'ServerComponent1', 'ServerComponent2');
32+
* registerServerComponent('ServerComponent1', 'ServerComponent2');
3533
*
3634
* // When ServerComponent1 renders, it will fetch from: /rsc_payload/ServerComponent1
3735
* ```
3836
*/
39-
const registerServerComponent = (options: RegisterServerComponentOptions, ...componentNames: string[]) => {
37+
const registerServerComponent = (...componentNames: string[]) => {
4038
const componentsWrappedInRSCRoute: Record<string, ReactComponentOrRenderFunction> = {};
4139
for (const name of componentNames) {
4240
componentsWrappedInRSCRoute[name] = WrapServerComponentRenderer((props: unknown) => (

node_package/src/types/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ export interface RegisteredComponent {
162162
isRenderer: boolean;
163163
}
164164

165-
export interface RegisterServerComponentOptions {
166-
rscPayloadGenerationUrlPath: string;
167-
}
168-
169165
export type ItemRegistrationCallback<T> = (component: T) => void;
170166

171167
interface Params {

node_package/tests/registerServerComponent.client.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ enableFetchMocks();
6262
const { stream, push } = createNodeReadableStream();
6363
window.fetchMock.mockResolvedValue(new Response(stream));
6464

65-
registerServerComponent({}, 'TestComponent');
65+
registerServerComponent('TestComponent');
6666
const railsContext = {
6767
rscPayloadGenerationUrl: rscPayloadGenerationUrlPath,
6868
componentSpecificMetadata: {
@@ -172,7 +172,7 @@ enableFetchMocks();
172172
chunk1 = JSON.stringify(JSON.parse(fs.readFileSync(path.join(chunksDirectory, 'chunk1.json'), 'utf8')));
173173
chunk2 = JSON.stringify(JSON.parse(fs.readFileSync(path.join(chunksDirectory, 'chunk2.json'), 'utf8')));
174174

175-
registerServerComponent({}, 'TestComponent');
175+
registerServerComponent('TestComponent');
176176
railsContext = {
177177
rscPayloadGenerationUrl: 'rsc-render',
178178
componentSpecificMetadata: {

spec/dummy/spec/packs_generator_spec.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module ReactOnRails
2424
before do
2525
stub_const("ReactOnRailsPro", Class.new do
2626
def self.configuration
27-
@configuration ||= Struct.new(:enable_rsc_support, :rsc_payload_generation_url_path).new(false, nil)
27+
@configuration ||= Struct.new(:enable_rsc_support).new(false)
2828
end
2929
end)
3030
ReactOnRails.configuration.server_bundle_js_file = server_bundle_js_file
@@ -216,15 +216,13 @@ def self.configuration
216216

217217
context "when RSC support is enabled" do
218218
let(:components_directory) { "ReactServerComponents" }
219-
let(:rsc_payload_generation_url_path) { "/rsc" }
220219

221220
before do
222221
stub_packer_source_path(component_name: components_directory,
223222
packer_source_path: packer_source_path)
224223
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(true)
225224
allow(ReactOnRailsPro.configuration).to receive_messages(
226-
enable_rsc_support: true,
227-
rsc_payload_generation_url_path: rsc_payload_generation_url_path
225+
enable_rsc_support: true
228226
)
229227
end
230228

@@ -240,9 +238,7 @@ def self.configuration
240238
expected_content = <<~CONTENT.strip
241239
import registerServerComponent from 'react-on-rails/registerServerComponent/client';
242240
243-
registerServerComponent({
244-
rscPayloadGenerationUrlPath: "#{rsc_payload_generation_url_path}",
245-
}, "#{component_name}")
241+
registerServerComponent("#{component_name}");
246242
CONTENT
247243

248244
expect(pack_content).to eq(expected_content)
@@ -276,9 +272,7 @@ def self.configuration
276272
expected_content = <<~CONTENT.strip
277273
import registerServerComponent from 'react-on-rails/registerServerComponent/client';
278274
279-
registerServerComponent({
280-
rscPayloadGenerationUrlPath: "#{rsc_payload_generation_url_path}",
281-
}, "#{component_name}")
275+
registerServerComponent("#{component_name}");
282276
CONTENT
283277

284278
expect(pack_content).to eq(expected_content)

0 commit comments

Comments
 (0)