diff --git a/docs/README.md b/docs/README.md index 94cfad7b30..7729fd7500 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,14 +1,8 @@ # React on Rails Documentation -> **Integrate React components seamlessly into your Rails application with server-side rendering, hot reloading, and more.** +> For the best experience, visit our **[documentation website](https://www.shakacode.com/react-on-rails/docs/)**. -## πŸš€ Quick Start - -New to React on Rails? Start here for the fastest path to success: - -**β†’ [15-Minute Quick Start Guide](./getting-started/quick-start.md)** - -Already have Rails + Shakapacker? **β†’ [Add to existing app guide](./getting-started/installation-into-an-existing-rails-app.md)** +Browsing on GitHub? This guide will help you navigate the documentation. ## πŸ“š Learning Paths @@ -18,17 +12,17 @@ Choose your journey based on your experience level: Perfect if you're new to React on Rails -1. **[Quick Start](./getting-started/quick-start.md)** - Get your first component running -2. **[Core Concepts](./getting-started.md)** - Understand the basics -3. **[Tutorial](./getting-started/tutorial.md)** - Build something useful +1. **[Introduction](./introduction.md)** - What is React on Rails and why use it? +2. **[Quick Start](./getting-started/quick-start.md)** - Get your first component running in 15 minutes +3. **[Tutorial](./getting-started/tutorial.md)** - Build a complete app with Redux and routing ### ⚑ **Experienced Developer Path** -Jump to what you need +Jump straight to what you need -- **[Installation Guide](./getting-started/installation-into-an-existing-rails-app.md)** - Detailed setup -- **[API Reference](./api-reference/README.md)** - Quick lookup -- **[Advanced Features](./guides/advanced/README.md)** - SSR, Redux, Router +- **[Installation Guide](./getting-started/installation-into-an-existing-rails-app.md)** - Add to existing Rails app +- **[API Reference](./api-reference/view-helpers-api.md)** - View helpers, configuration, JavaScript API +- **[Core Concepts](./core-concepts/how-react-on-rails-works.md)** - Architecture and SSR ### πŸ—οΈ **Migrating from Other Solutions** @@ -48,125 +42,23 @@ Find guidance for your specific scenario: | **Deploy to production** | [Deployment Guide](./deployment/deployment.md) | | **Troubleshoot issues** | [Troubleshooting](./deployment/troubleshooting.md) | -## πŸ“– Complete Documentation - -### Core Guides - -- **[Getting Started](./getting-started.md)** - Installation and basic setup -- **[Tutorial](./getting-started/tutorial.md)** - Complete walkthrough with examples -- **[Configuration](./api-reference/configuration.md)** - All configuration options -- **[View Helpers](./api-reference/view-helpers-api.md)** - Using `react_component` method - -### Features - -- **[Server-Side Rendering](./core-concepts/react-server-rendering.md)** - SSR setup and optimization -- **[Auto-Bundling](./core-concepts/auto-bundling-file-system-based-automated-bundle-generation.md)** - Automatic bundle generation -- **[Redux Integration](./building-features/react-and-redux.md)** - State management with Redux -- **[React Router](./building-features/react-router.md)** - Client-side routing -- **[Internationalization](./building-features/i18n.md)** - I18n support - -### Development - -- **[Hot Module Replacement](./building-features/hmr-and-hot-reloading-with-the-webpack-dev-server.md)** - Fast development workflow -- **[Testing](./building-features/rspec-configuration.md)** - Testing React components -- **[Debugging](./deployment/troubleshooting-build-errors.md)** - Common debugging techniques - -### Deployment & Performance +## πŸ“– Documentation Categories -- **[Deployment](./deployment/deployment.md)** - Production deployment guide -- **[Performance](./core-concepts/webpack-configuration.md)** - Optimization techniques -- **[Bundle Optimization](./core-concepts/webpack-configuration.md)** - Reduce bundle size +- **[Getting Started](./getting-started/)** - Installation, quick start, tutorial +- **[Core Concepts](./core-concepts/)** - How React on Rails works, SSR, auto-bundling +- **[Building Features](./building-features/)** - Redux, routing, i18n, testing +- **[API Reference](./api-reference/)** - View helpers, configuration, JavaScript API +- **[Deployment](./deployment/)** - Production deployment and troubleshooting +- **[Upgrading](./upgrading/)** - Version upgrade guides +- **[Migrating](./migrating/)** - From other frameworks +- **[Pro](./pro/)** - React on Rails Pro features ## πŸ†˜ Need Help? -### Quick Solutions - - **[Troubleshooting Guide](./deployment/troubleshooting.md)** - Common issues and solutions -- **[FAQ](./deployment/troubleshooting.md)** - Frequently asked questions -- **[Error Messages](./deployment/troubleshooting-build-errors.md)** - Decode error messages - -### Community Support - -- **[React + Rails Slack](https://reactrails.slack.com)** - Real-time community help - **[GitHub Discussions](https://github.com/shakacode/react_on_rails/discussions)** - Ask questions -- **[GitHub Issues](https://github.com/shakacode/react_on_rails/issues)** - Report bugs - -### Professional Support - -- **[ShakaCode Support](mailto:react_on_rails@shakacode.com)** - Professional React on Rails help -- **[React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/)** - Advanced features and support - -## πŸ”— External Resources - -- **[Shakapacker Documentation](https://github.com/shakacode/shakapacker)** - Webpack integration for Rails -- **[React Documentation](https://react.dev)** - Official React docs -- **[Rails Guides](https://guides.rubyonrails.org)** - Ruby on Rails documentation +- **[React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/)** - Advanced features and professional support --- -## πŸ“š Table of Contents - -### API Reference - -- [View Helpers API](./api-reference/view-helpers-api.md) -- [Redux Store API](./api-reference/redux-store-api.md) -- [JavaScript API](./api-reference/javascript-api.md) - -### Guides - -#### Getting Started - -- [Installation](./getting-started.md) -- [Tutorial](./getting-started/tutorial.md) -- [Basic Configuration](./api-reference/configuration.md) - -#### Core Features - -- [Server-Side Rendering](./core-concepts/react-server-rendering.md) -- [Component Registration](./core-concepts/render-functions-and-railscontext.md) -- [Props and RailsContext](./core-concepts/render-functions-and-railscontext.md) - -#### State Management - -- [Redux Integration](./building-features/react-and-redux.md) -- [Context API](./core-concepts/render-functions-and-railscontext.md) - -#### Routing - -- [React Router Setup](./building-features/react-router.md) -- [Server-Side Routing](./core-concepts/react-server-rendering.md) - -#### Advanced Topics - -- [Webpack Configuration](./core-concepts/webpack-configuration.md) -- [Code Splitting](./building-features/code-splitting.md) -- [Performance Optimization](./core-concepts/webpack-configuration.md) - -#### Development - -- [Hot Module Replacement](./building-features/hmr-and-hot-reloading-with-the-webpack-dev-server.md) -- [Testing Components](./building-features/rspec-configuration.md) -- [Debugging](./deployment/troubleshooting-build-errors.md) - -#### Deployment - -- [Production Setup](./deployment/deployment.md) -- [Heroku Deployment](./deployment/deployment.md) -- [Docker Setup](./deployment/deployment.md) - -### Migration Guides - -- [Upgrading React on Rails](./upgrading/upgrading-react-on-rails.md) -- [From react-rails gem](./migrating/migrating-from-react-rails.md) - -### Troubleshooting - -- [Common Issues](./deployment/troubleshooting.md) -- [Error Messages](./deployment/troubleshooting-build-errors.md) -- [Performance Issues](./deployment/troubleshooting-build-errors.md) - -### Contributing - -- [Contributing Guide](../CONTRIBUTING.md) -- [Development Setup](../CONTRIBUTING.md) -- [Pull Request Guidelines](../CONTRIBUTING.md) +**πŸ’‘ Tip:** For the best reading experience with full navigation and search, visit the [documentation website](https://www.shakacode.com/react-on-rails/docs/). diff --git a/docs/advanced-topics/manual-installation-overview.md b/docs/advanced-topics/manual-installation-overview.md deleted file mode 100644 index 6535ce4b91..0000000000 --- a/docs/advanced-topics/manual-installation-overview.md +++ /dev/null @@ -1,28 +0,0 @@ -# Manual Installation Overview - -TODO: Review this file - -This file summarizes what the React on Rails generator does. - -## Configure the `/client` Directory - -This directory has no references to Rails outside of the destination directory for the files created by the various Webpack config files. - -The only requirements within this directory for basic React on Rails integration are: - -1. Your Webpack configuration files: - 1. Create outputs in a directory like `/public/webpack`, which is customizable in your `config/initializers/react_on_rails.rb`. - 1. Provide server rendering if you wish to use that feature. -1. Your JavaScript code "registers" any components and stores per the ReactOnRails APIs of ReactOnRails.register(components) and ReactOnRails.registerStore(stores). See [our JavaScript API docs](../api-reference/javascript-api.md) and the [React on Rails source](https://github.com/shakacode/react_on_rails/tree/master/packages/react-on-rails/src/ReactOnRails.client.ts). -1. Set your registration file as an "entry" point in your Webpack configs. -1. Configure scripts in `client/package.json` as shown in the example apps. These are used for building your Webpack assets. Also do this for your top-level `package.json`. - -## Rails Steps (outside `/client`) - -1. Add `gem "shakapacker"` to the Gemfile, run `bundle`. The gem provides the `stylesheet_pack_tag` and `javascript_pack_tag` helpers, which are used to load the bundled assets in your layouts. [Dummy Example](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/views/layouts/application.html.erb). -1. Configure the `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/initializers/react_on_rails.rb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/initializers/react_on_rails.rb) for a detailed example of configuration, including comments on the different values to configure. -1. Configure your Procfiles per the example apps. These are at the root of your Rails installation. -1. Configure your top-level JavaScript files for inclusion in your layout. Use one file for static assets, and a separate file for any files in your setup that are not part of your Webpack build. This separation is needed for hot reloading. If hot reloading is not needed, simply configure your `application.js` file to include the Webpack-generated files. -1. If you are deploying to Heroku, see [our Heroku deployment documentation](../deployment/heroku-deployment.md). - -If I missed anything, please submit a PR or file an issue. diff --git a/docs/advanced-topics/rails-engine-integration.md b/docs/advanced-topics/rails-engine-integration.md index 50814109c4..433dade798 100644 --- a/docs/advanced-topics/rails-engine-integration.md +++ b/docs/advanced-topics/rails-engine-integration.md @@ -1,3 +1,5 @@ +# Integrating React on Rails with Rails Engines + ## In your engine - At the top of `config/initializers/react_on_rails.rb` @@ -30,7 +32,7 @@ As far as solving the assets issue, `lib/tasks/assets.rake` in `react_on_rails` Another solution would be to detach this rake task from the `rails assets:precompile` task. This can be done by adding `REACT_ON_RAILS_PRECOMPILE=false` to your environment. If you do so, then React assets will have to be bundled separately from `rails assets:precompile`. -# Github Issues +## Github Issues - [Integration with an engine #342](https://github.com/shakacode/react_on_rails/issues/342) - [Feature: target destination option for the install generator #459](https://github.com/shakacode/react_on_rails/issues/459) diff --git a/docs/api-reference/README.md b/docs/api-reference/README.md deleted file mode 100644 index aa5aa7cc4b..0000000000 --- a/docs/api-reference/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# API Reference - -Complete API documentation for React on Rails. - -- [View Helpers API](../api-reference/view-helpers-api.md) -- [Redux Store API](../api-reference/redux-store-api.md) -- [JavaScript API](../api-reference/javascript-api.md) diff --git a/docs/api-reference/configuration.md b/docs/api-reference/configuration.md index 34ddbfffbe..96391204da 100644 --- a/docs/api-reference/configuration.md +++ b/docs/api-reference/configuration.md @@ -1,3 +1,5 @@ +# React on Rails Configuration Options + Here is the full set of config options. This file is `/config/initializers/react_on_rails.rb` First, you should have a `/config/shakapacker.yml` setup. diff --git a/docs/api-reference/generator-details.md b/docs/api-reference/generator-details.md index 0478cba2d0..fd862f49e8 100644 --- a/docs/api-reference/generator-details.md +++ b/docs/api-reference/generator-details.md @@ -39,20 +39,80 @@ Then you may run Another good option is to create a simple test app per the [Tutorial](../getting-started/tutorial.md). -# Understanding the Organization of the Generated Client Code +## Understanding the Organization of the Generated Client Code -The generated client code follows our organization scheme. Each unique set of functionality is given its own folder inside of `app/javascript/app/bundles`. This encourages modularity of _domains_. +The React on Rails generator creates different directory structures depending on whether you use the `--redux` option. -Inside the generated "HelloWorld" domain you will find the following folders: +### Default Structure (Without Redux) -- `startup`: contains the entry point files for webpack. It defaults to a single file that is used for both server and client compilation. But if these need to be different, then you can create two Webpack configurations with separate endpoints. Since RoR v14.2 this is strongly recommended because the client can import `react-on-rails/client` instead of `react-on-rails` for decreased bundle size. -- `containers`: contains "smart components" (components that have functionality and logic that is passed to child "dumb components"). -- `components`: contains "dumb components", or components that simply render their properties and call functions given to them as properties by a parent component. Ultimately, at least one of these dumb components will have a parent container component. +The basic generator creates a simple, flat structure optimized for auto-bundling: -You may also notice the `app/lib` folder. This is for any code that is common between bundles and therefore needs to be shared (for example, middleware). +``` +app/javascript/ +└── src/ + └── HelloWorld/ + └── ror_components/ # Components auto-registered by React on Rails + β”œβ”€β”€ HelloWorld.jsx # Your React component + β”œβ”€β”€ HelloWorld.module.css + └── HelloWorld.server.js # Optional: separate server rendering logic +``` + +- **`src/`**: Source directory for all React components +- **`ror_components/`**: Directory name is configurable via `config.components_subdirectory` in `config/initializers/react_on_rails.rb` +- **Auto-registration**: Components in `ror_components/` directories are automatically discovered and registered when using `auto_load_bundle: true` + +For components that need different client vs. server implementations, use `.client.jsx` and `.server.jsx` suffixes (e.g., `HelloWorld.client.jsx` and `HelloWorld.server.jsx`). + +### Redux Structure (With `--redux` Option) + +The Redux generator creates a more structured organization with familiar Redux patterns: + +``` +app/javascript/ +└── src/ + └── HelloWorldApp/ + β”œβ”€β”€ actions/ # Redux action creators + β”‚ └── helloWorldActionCreators.js + β”œβ”€β”€ components/ # Presentational components + β”‚ β”œβ”€β”€ HelloWorld.jsx + β”‚ └── HelloWorld.module.css + β”œβ”€β”€ constants/ # Action type constants + β”‚ └── helloWorldConstants.js + β”œβ”€β”€ containers/ # Connected components (smart components) + β”‚ └── HelloWorldContainer.js + β”œβ”€β”€ reducers/ # Redux reducers + β”‚ └── helloWorldReducer.js + β”œβ”€β”€ ror_components/ # Auto-registered entry points + β”‚ β”œβ”€β”€ HelloWorldApp.client.jsx + β”‚ └── HelloWorldApp.server.jsx + └── store/ # Redux store configuration + └── helloWorldStore.js +``` + +This structure follows Redux best practices: + +- **`components/`**: Presentational "dumb" components that receive data via props +- **`containers/`**: Container "smart" components connected to Redux store +- **`actions/`** and **`reducers/`**: Standard Redux patterns +- **`ror_components/`**: Entry point files that initialize Redux and render the app + +### TypeScript Support + +The generator also supports a `--typescript` option for generating TypeScript files: + +```bash +rails generate react_on_rails:install --typescript +``` + +This creates `.tsx` files instead of `.jsx` and adds TypeScript configuration. + +### Auto-Bundling and Component Registration -## Redux +Modern React on Rails uses auto-bundling to eliminate manual webpack configuration. Components placed in the configured `components_subdirectory` (default: `ror_components`) are automatically: -If you have used the `--redux` generator option, you will notice the familiar additional redux folders in addition to the aforementioned folders. The Hello World example has also been modified to use Redux. +1. Discovered by the generator +2. Bundled into separate webpack entry points +3. Registered for use with `react_component` helper +4. Loaded on-demand when used in views -Note the organizational paradigm of "bundles". These are like application domains and are used for grouping your code into webpack bundles, in case you decide to create different bundles for deployment. This is also useful for separating out logical parts of your application. The concept is that each bundle will have it's own Redux store. If you have code that you want to reuse across bundles, including components and reducers, place them under `/client/app/lib`. +For detailed information on auto-bundling, see the [Auto-Bundling Guide](../core-concepts/auto-bundling-file-system-based-automated-bundle-generation.md). diff --git a/docs/api-reference/redux-store-api.md b/docs/api-reference/redux-store-api.md index ba86fa3b0b..a09dd09b69 100644 --- a/docs/api-reference/redux-store-api.md +++ b/docs/api-reference/redux-store-api.md @@ -98,7 +98,7 @@ This method has the same API as the controller extension. **HOWEVER**, we recomm Place this view helper (no parameters) at the end of your shared layout so ReactOnRails will render the redux store hydration data. Since we're going to be setting up the stores in the controllers, we need to know where on the view to put the client-side rendering of this hydration data, which is a hidden div with a matching class that contains a data props. For an example, see [spec/dummy/app/views/layouts/application.html.erb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/views/layouts/application.html.erb). -# More Details +## More Details - [lib/react_on_rails/controller.rb](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/controller.rb) source - [lib/react_on_rails/helper.rb](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/helper.rb) source diff --git a/docs/api-reference/view-helpers-api.md b/docs/api-reference/view-helpers-api.md index c3100fedf6..536b2efbcd 100644 --- a/docs/api-reference/view-helpers-api.md +++ b/docs/api-reference/view-helpers-api.md @@ -90,7 +90,9 @@ You can call `rails_context` or `rails_context(server_side: true|false)` from yo A "renderer function" is a Render-Function that accepts three arguments (rather than 2): `(props, railsContext, domNodeId) => { ... }`. Instead of returning a React component, a renderer is responsible for installing a callback that will call `ReactDOM.render` (in React 16+, `ReactDOM.hydrate`) to render a React component into the DOM. The "renderer function" is called at the same time the document ready event would instantiate the React components into the DOM. -Why would you want to call `ReactDOM.hydrate` yourself? One possible use case is [code splitting](../building-features/code-splitting.md). In a nutshell, you don't want to load the React component on the DOM node yet. So you want to install some handler that will call `ReactDOM.hydrate` at a later time. In the case of code splitting with server rendering, the server rendered code has any async code loaded and used to server render. Thus, the client code must also fully load any asynch code before server rendering. Otherwise, the client code would first render partially, not matching the server rendering, and then a second later, the full code would render, resulting in an unpleasant flashing on the screen. +Why would you want to call `ReactDOM.hydrate` yourself? One possible use case is code splitting. In a nutshell, you don't want to load the React component on the DOM node yet. So you want to install some handler that will call `ReactDOM.hydrate` at a later time. In the case of code splitting with server rendering, the server-rendered code has any async code loaded and used to server render. Thus, the client code must also fully load any async code before server rendering. Otherwise, the client code would first render partially, not matching the server rendering, and then a second later, the full code would render, resulting in an unpleasant flashing on the screen. + +For modern code splitting with server-side rendering, see the [React on Rails Pro loadable-components guide](https://www.shakacode.com/react-on-rails-pro/docs/code-splitting-loadable-components). Renderer functions are not meant to be used on the server since there's no DOM on the server. Instead, use a Render-Function. Attempting to server render with a renderer function will throw an error. @@ -102,7 +104,7 @@ Renderer functions are not meant to be used on the server since there's no DOM o 1. [React on Rails docs for React Router](../building-features/react-router.md) 2. Examples in [spec/dummy/app/views/react_router](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/views/react_router) and follow to the JavaScript code in the [spec/dummy/client/app/startup/RouterApp.server.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/RouterApp.server.jsx). -3. [Code Splitting docs](../building-features/code-splitting.md) for information about how to set up code splitting for server rendered routes. +3. [React on Rails Pro loadable-components guide](https://www.shakacode.com/react-on-rails-pro/docs/code-splitting-loadable-components) for modern code splitting with server-side rendering. --- @@ -158,6 +160,6 @@ See the [React on Rails Pro Configuration](https://github.com/shakacode/react_on --- -# More details +## More details See the [lib/react_on_rails/helper.rb](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/helper.rb) source. diff --git a/docs/building-features/code-splitting.md b/docs/building-features/code-splitting.md deleted file mode 100644 index 78b6dc0633..0000000000 --- a/docs/building-features/code-splitting.md +++ /dev/null @@ -1,167 +0,0 @@ -# Code Splitting (Outdated) - -_Note: This document is outdated._ Please email [justin@shakacode.com](mailto:justin@shakacode.com) -if you would be interested in help with code splitting using -[loadable-components.com](https://loadable-components.com/docs) with React on Rails. - ---- - -What is code splitting? From the Webpack documentation: - -> For big web apps it’s not efficient to put all code into a single file, especially if some blocks of code are only required under some circumstances. Webpack has a feature to split your codebase into β€œchunks” which are loaded on demand. Some other bundlers call them β€œlayers”, β€œrollups”, or β€œfragments”. This feature is called β€œcode splitting”. - -## Server Rendering and Code Splitting - -Let's say you're requesting a page that needs to fetch a code chunk from the server before it's able to render. If you do all your rendering on the client side, you don't have to do anything special. However, if the page is rendered on the server, you'll find that React will spit out the following error: - -> Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server: - -> (client) `