Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update react-on-rails import to /client as needed #1703

Merged
merged 4 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Changes since the last non-beta release.
### Changed

- The global context is now accessed using `globalThis`. [PR 1727](https://github.com/shakacode/react_on_rails/pull/1727) by [alexeyr-ci2](https://github.com/alexeyr-ci2).
- Generated client packs now import from `react-on-rails/client` instead of `react-on-rails`. [PR 1706](https://github.com/shakacode/react_on_rails/pull/1706) by [alexeyr-ci](https://github.com/alexeyr-ci).
- The "optimization opportunity" message when importing the server-side `react-on-rails` instead of `react-on-rails/client` in browsers is now a warning for two reasons:
- Make it more prominent
- Include a stack trace when clicked

### [15.0.0-alpha.2] - 2025-03-07

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Many projects will have different entry points for client and server rendering.
Your Client Entry can look like this:

```js
import ReactOnRails from 'react-on-rails';
import ReactOnRails from 'react-on-rails/client';
import App from './ClientApp';
ReactOnRails.register({ App });
```
Expand All @@ -22,7 +22,7 @@ import App from './ServerApp';
ReactOnRails.register({ App });
```

Note that the only difference is on the second line of each of these examples.
Note that the only difference is in the imports.

## B. Two Options for Using Webpack Resolve Alias in the Webpack Config

Expand Down
4 changes: 2 additions & 2 deletions docs/javascript/code-splitting.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Here's an example of how you might use this in practice:
#### clientRegistration.js

```js
import ReactOnRails from 'node_package/lib/ReactOnRails';
import ReactOnRails from 'react-on-rails/client';
import NavigationApp from './NavigationApp';

// Note that we're importing a different RouterApp than in serverRegistration.js
Expand Down Expand Up @@ -76,7 +76,7 @@ Note that you should not register a renderer on the server, since there won't be
#### RouterAppRenderer.jsx

```jsx
import ReactOnRails from 'react-on-rails';
import ReactOnRails from 'react-on-rails/client';
import React from 'react';
import ReactDOM from 'react-dom';
import Router from 'react-router/lib/Router';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReactOnRails from 'react-on-rails';
import ReactOnRails from 'react-on-rails/client';

import <%= config[:component_name] %> from '<%= config[:app_relative_path] %>';

Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails/packs_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def pack_file_contents(file_path)
relative_component_path = relative_component_path_from_generated_pack(file_path)

<<~FILE_CONTENT.strip
import ReactOnRails from 'react-on-rails';
import ReactOnRails from 'react-on-rails/client';
import #{registered_component_name} from '#{relative_component_path}';

ReactOnRails.register({#{registered_component_name}});
Expand Down
5 changes: 3 additions & 2 deletions node_package/src/ReactOnRails.full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import type { RenderParams, RenderResult, ErrorOptions } from './types';
import Client from './ReactOnRails.client';

if (typeof window !== 'undefined') {
console.log(
'Optimization opportunity: "react-on-rails" includes ~14KB of server-rendering code. Browsers may not need it. See https://forum.shakacode.com/t/how-to-use-different-versions-of-a-file-for-client-and-server-rendering/1352 (Requires creating a free account)',
// warn to include a collapsed stack trace
console.warn(
'Optimization opportunity: "react-on-rails" includes ~14KB of server-rendering code. Browsers may not need it. See https://forum.shakacode.com/t/how-to-use-different-versions-of-a-file-for-client-and-server-rendering/1352 (Requires creating a free account). Click this for the stack trace.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justin808 Please update the article.

);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<br/>
<pre>
import HelloWorld from '../components/HelloWorld';
import ReactOnRails from 'react-on-rails';
import ReactOnRails from 'react-on-rails/client';
ReactOnRails.register({ HelloWorld });
</pre>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<br/>
<pre>
import HelloWorld from '../components/HelloWorld';
import ReactOnRails from 'react-on-rails';
import ReactOnRails from 'react-on-rails/client';
ReactOnRails.register({ HelloWorld });
</pre>
</li>
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/views/pages/server_side_redux_app.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<br/>
<pre>
import ReduxApp from './ClientReduxApp';
import ReactOnRails from 'react-on-rails';
import ReactOnRails from 'react-on-rails/client';
ReactOnRails.register({ ReduxApp });
</pre>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<br/>
<pre>
import ReduxApp from './ClientReduxApp';
import ReactOnRails from 'react-on-rails';
import ReactOnRails from 'react-on-rails/client';
ReactOnRails.register({ ReduxApp });
</pre>
</li>
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/views/pages/xhr_refresh.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<br/>
<pre style='white-space: pre-wrap; word-break: keep-all;'>
import HellowWorldRehydratable from '../components/HellowWorldRehydratable';
import ReactOnRails from 'react-on-rails';
import ReactOnRails from 'react-on-rails/client';
ReactOnRails.register({ HellowWorldRehydratable });
</pre>
</li>
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/client/app/startup/HelloWorldRehydratable.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import ReactOnRails from 'react-on-rails';
import ReactOnRails from 'react-on-rails/client';
import RailsContext from '../components/RailsContext';

class HelloWorldRehydratable extends React.Component {
Expand Down
6 changes: 3 additions & 3 deletions spec/dummy/client/app/startup/ReduxSharedStoreApp.client.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Top level component for client side.
// Compare this to the ./ServerApp.jsx file which is used for server side rendering.
// Top level component for the client side.
// Compare this to the ./ReduxSharedStoreApp.server.jsx file which is used for server side rendering.

import React from 'react';
import { Provider } from 'react-redux';
import ReactOnRails from 'react-on-rails';
import ReactOnRails from 'react-on-rails/client';
import ReactDOMClient from 'react-dom/client';

import HelloWorldContainer from '../components/HelloWorldContainer';
Expand Down
4 changes: 2 additions & 2 deletions spec/dummy/client/app/startup/ReduxSharedStoreApp.server.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Top level component for serer side.
// Compare this to the ./ClientReduxSharedStoreApp.jsx file which is used for client side rendering.
// Top level component for the server side.
// Compare this to the ./ReduxSharedStoreApp.client.jsx file which is used for client side rendering.

import React from 'react';
import ReactOnRails from 'react-on-rails';
Expand Down
8 changes: 4 additions & 4 deletions spec/dummy/spec/packs_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def self.configuration
component_name = "ReactClientComponentWithClientAndServer"
component_pack = "#{generated_directory}/#{component_name}.js"
pack_content = File.read(component_pack)
expect(pack_content).to include("import ReactOnRails from 'react-on-rails';")
expect(pack_content).to include("import ReactOnRails from 'react-on-rails/client';")
expect(pack_content).to include("ReactOnRails.register({#{component_name}});")
expect(pack_content).not_to include("registerServerComponent")
end
Expand Down Expand Up @@ -294,7 +294,7 @@ def self.configuration
component_name = "ReactClientComponent"
component_pack = "#{generated_directory}/#{component_name}.js"
pack_content = File.read(component_pack)
expect(pack_content).to include("import ReactOnRails from 'react-on-rails';")
expect(pack_content).to include("import ReactOnRails from 'react-on-rails/client';")
expect(pack_content).to include("ReactOnRails.register({#{component_name}});")
expect(pack_content).not_to include("registerServerComponent")
end
Expand All @@ -310,7 +310,7 @@ def self.configuration
component_name = "ReactServerComponent"
component_pack = "#{generated_directory}/#{component_name}.js"
pack_content = File.read(component_pack)
expect(pack_content).to include("import ReactOnRails from 'react-on-rails';")
expect(pack_content).to include("import ReactOnRails from 'react-on-rails/client';")
expect(pack_content).to include("ReactOnRails.register({#{component_name}});")
expect(pack_content).not_to include("registerServerComponent")
end
Expand All @@ -326,7 +326,7 @@ def self.configuration
component_name = "ReactServerComponent"
component_pack = "#{generated_directory}/#{component_name}.js"
pack_content = File.read(component_pack)
expect(pack_content).to include("import ReactOnRails from 'react-on-rails';")
expect(pack_content).to include("import ReactOnRails from 'react-on-rails/client';")
expect(pack_content).to include("ReactOnRails.register({#{component_name}});")
expect(pack_content).not_to include("registerServerComponent")
end
Expand Down
Loading