diff --git a/.circleci/config.yml b/.circleci/config.yml index 7d9a37f75..eab28626e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,8 +1,9 @@ +# CircleCI is not longer in use by this repository & this file is now for reference only. version: 2 aliases: - &docker-image - - image: circleci/ruby:2.7-node-browsers + - image: circleci/ruby:3.0-node-browsers # Print critical data and executables versions. - &print-system-info @@ -53,16 +54,17 @@ aliases: - &install-dummy-app-ruby-gems name: Install Ruby Gems for dummy app command: | - gem install bundler + gem install bundler:2.5.9 echo "Bundler version: "; bundle --version - cd spec/dummy && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 + cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 # Install ruby gems unless existing set of gems is satisfying bundler. - &install-package-ruby-gems name: Install Ruby Gems for package command: | - gem install bundler + gem install bundler:2.5.9 echo "Bundler version: "; bundle --version + bundle lock --add-platform 'x86_64-linux' bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 # Restore node_modules dir from cache using yarn.lock checksum as a key. @@ -129,7 +131,7 @@ jobs: name: prettier command: yarn start format.listDifferent - # Install Node modules for Renderer package with Yarn and save them to chache. + # Install Node modules for Renderer package with Yarn and save them to cache. install-package-node-packages: docker: *docker-image steps: @@ -204,6 +206,9 @@ jobs: - run: *install-yalc-add-react-on-rails - run: *install-dummy-app-node-modules - run: *install-dummy-app-ruby-gems + - run: + name: generate file system-based packs + command: cd spec/dummy && bundle exec rake react_on_rails:generate_packs - run: name: Build test bundles for dummy app command: cd spec/dummy && yarn run build:test @@ -316,6 +321,7 @@ workflows: - build-dummy-app-webpack-test-bundles: requires: - install-dummy-app-node-packages + - install-dummy-app-ruby-gems - package-js-tests: requires: - install-package-node-packages diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..30d130baa --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,23 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +A bug is a crash or incorrect behavior. If you have a debugging or troubleshooting question, please open [a discussion](https://github.com/shakacode/react_on_rails/discussions). + +## Environment + +1. Ruby version: +2. Rails version: +3. Shakapacker/Webpacker version: +4. React on Rails version: + +## Expected behavior + +## Actual behavior + +## Small, reproducible repo diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 000000000..bbcbbe7d6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..9d46cce19 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,19 @@ +### Summary + +_Remove this paragraph and provide a general description of the code changes in your pull +request... were there any bugs you had fixed? If so, mention them. If +these bugs have open GitHub issues, be sure to tag them here as well, +to keep the conversation linked together._ + +### Pull Request checklist +_Remove this line after checking all the items here. If the item is not applicable to the PR, both check it out and wrap it by `~`._ + +- [ ] Add/update test to cover these changes +- [ ] Update documentation +- [ ] Update CHANGELOG file + _Add the CHANGELOG entry at the top of the file._ + +### Other Information + +_Remove this paragraph and mention any other important and relevant information such as benchmarks._ + diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml new file mode 100644 index 000000000..d66cee35c --- /dev/null +++ b/.github/workflows/examples.yml @@ -0,0 +1,94 @@ +name: Generator tests + +on: + push: + branches: + - 'master' + pull_request: + +jobs: + examples: + env: + SKIP_YARN_COREPACK_CHECK: 0 + strategy: + fail-fast: false + matrix: + versions: ['oldest', 'newest'] + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v44 + with: + files: | + lib/generators/** + rakelib/example_type.rb + rakelib/example_config.yml + rakelib/examples.rake + rakelib/run_rspec.rake + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.versions == 'oldest' && '3.0' || '3.3' }} + bundler: 2.5.9 + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Print system information + run: | + echo "Linux release: "; cat /etc/issue + echo "Current user: "; whoami + echo "Current directory: "; pwd + echo "Ruby version: "; ruby -v + echo "Node version: "; node -v + echo "Yarn version: "; yarn --version + echo "Bundler version: "; bundle --version + - name: run conversion script to support shakapacker v6 + if: matrix.versions == 'oldest' + run: script/convert + - name: Save root node_modules to cache + uses: actions/cache@v4 + with: + path: node_modules + key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }} + - name: Save root ruby gems to cache + uses: actions/cache@v4 + with: + path: vendor/bundle + key: package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}-${{ hashFiles('Gemfile.development_dependencies') }}-${{ matrix.versions }} + - id: get-sha + run: echo "::set-output name=sha::$(git rev-parse HEAD)" + - name: Install Node modules with Yarn for renderer package + run: | + yarn install --no-progress --no-emoji + sudo yarn global add yalc + - name: yalc publish for react-on-rails + run: yalc publish + - name: Install Ruby Gems for package + run: bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle _2.5.9_ install --path=vendor/bundle --jobs=4 --retry=3 + - name: Ensure minimum required Chrome version + run: | + echo -e "Already installed $(google-chrome --version)\n" + MINIMUM_REQUIRED_CHROME_VERSION=75 + INSTALLED_CHROME_MAJOR_VERSION="$(google-chrome --version | tr ' .' '\t' | cut -f3)" + if [[ $INSTALLED_CHROME_MAJOR_VERSION < $MINIMUM_REQUIRED_CHROME_VERSION ]]; then + wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add - + sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' + sudo apt-get update + sudo apt-get install google-chrome-stable + echo -e "\nInstalled $(google-chrome --version)" + fi + - name: Increase the amount of inotify watchers + run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p + - name: Main CI + if: steps.changed-files.outputs.any_changed == 'true' + run: bundle exec rake run_rspec:${{ matrix.versions == 'oldest' && 'web' || 'shaka' }}packer_examples + - name: Store test results + uses: actions/upload-artifact@v4 + with: + name: main-rspec-${{ github.run_id }}-${{ github.job }}-${{ matrix.versions }} + path: ~/rspec diff --git a/.github/workflows/lint-js-and-ruby.yml b/.github/workflows/lint-js-and-ruby.yml index 476c0db38..d6946a64a 100644 --- a/.github/workflows/lint-js-and-ruby.yml +++ b/.github/workflows/lint-js-and-ruby.yml @@ -1,24 +1,28 @@ name: Lint JS and Ruby -on: [push, pull_request] + +on: + push: + branches: + - 'master' + pull_request: jobs: build: - strategy: - matrix: - ruby: [2.7] - node: [14] - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + persist-credentials: false - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: ${{ matrix.ruby }} + ruby-version: 3 + bundler: 2.5.9 - name: Setup Node - uses: actions/setup-node@v2-beta + uses: actions/setup-node@v4 with: - node-version: ${{ matrix.node }} + node-version: 20 - name: Print system information run: | echo "Linux release: "; cat /etc/issue @@ -29,25 +33,25 @@ jobs: echo "Yarn version: "; yarn --version echo "Bundler version: "; bundle --version - name: Save root node_modules to cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: node_modules - key: v4-package-node-modules-cache-${{ hashFiles('yarn.lock') }} + key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }} - name: Save root ruby gems to cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: vendor/bundle - key: v4-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }} + key: package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}-${{ hashFiles('Gemfile.development_dependencies') }}-oldest - name: Install Node modules with Yarn for renderer package run: | yarn install --no-progress --no-emoji - yarn run eslint -v - sudo yarn global add yalc - name: Install Ruby Gems for package - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 + run: bundle check --path=vendor/bundle || bundle _2.5.9_ install --path=vendor/bundle --jobs=4 --retry=3 - name: Linting of Ruby run: bundle exec rubocop - name: Linting of JS run: yarn start lint - name: Check formatting run: yarn start format.listDifferent + - name: Type-check TypeScript + run: yarn run type-check diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d28ca3432..3cc5c2806 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,24 +1,34 @@ name: Main test -on: [push, pull_request] +on: + push: + branches: + - 'master' + pull_request: jobs: build-dummy-app-webpack-test-bundles: strategy: matrix: - ruby: [2.7] - node: [14] - runs-on: ubuntu-latest + versions: ['oldest', 'newest'] + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + persist-credentials: false - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: ${{ matrix.ruby }} + ruby-version: ${{ matrix.versions == 'oldest' && '3.0' || '3.3' }} + bundler: 2.5.9 + # libyaml-dev is needed for psych v5 + # this gem depends on sdoc which depends on rdoc which depends on psych + - name: Fix dependency for libyaml-dev + run: sudo apt install libyaml-dev - name: Setup Node - uses: actions/setup-node@v2-beta + uses: actions/setup-node@v4 with: - node-version: ${{ matrix.node }} + node-version: ${{ matrix.versions == 'oldest' && '16' || '20' }} - name: Print system information run: | echo "Linux release: "; cat /etc/issue @@ -28,62 +38,68 @@ jobs: echo "Node version: "; node -v echo "Yarn version: "; yarn --version echo "Bundler version: "; bundle --version + - name: run conversion script to support shakapacker v6 + if: matrix.versions == 'oldest' + run: script/convert - name: Save root node_modules to cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: node_modules - key: v4-package-node-modules-cache-${{ hashFiles('yarn.lock') }} + key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }} - name: Install Node modules with Yarn for renderer package run: | yarn install --no-progress --no-emoji - yarn run eslint -v sudo yarn global add yalc - name: yalc publish for react-on-rails run: yalc publish - name: Save spec/dummy/node_modules to cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: spec/dummy/node_modules - key: v4-dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/yarn.lock') }} + key: dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/package.json') }}-${{ matrix.versions }} - name: yalc add react-on-rails run: cd spec/dummy && yalc add react-on-rails - name: Install Node modules with Yarn for dummy app run: cd spec/dummy && yarn install --no-progress --no-emoji - name: Save dummy app ruby gems to cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: spec/dummy/vendor/bundle - key: v4-dummy-app-gem-cache-${{ hashFiles('spec/dummy/Gemfile.lock') }} + key: dummy-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}-${{ hashFiles('Gemfile.development_dependencies') }}-${{ matrix.versions }} - name: Install Ruby Gems for dummy app - run: cd spec/dummy && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 + run: cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle _2.5.9_ install --path=vendor/bundle --jobs=4 --retry=3 + - name: generate file system-based packs + run: cd spec/dummy && RAILS_ENV=test bundle exec rake react_on_rails:generate_packs - name: Build test bundles for dummy app - run: cd spec/dummy && yarn run build:test + run: cd spec/dummy && rm -rf public/webpack/test && yarn build:rescript && RAILS_ENV=test NODE_ENV=test bin/${{ matrix.versions == 'oldest' && 'web' || 'shaka' }}packer - id: get-sha run: echo "::set-output name=sha::$(git rev-parse HEAD)" - name: Save test webpack bundles to cache (for build number checksum used by rspec job) - uses: actions/cache@v2 + uses: actions/cache/save@v4 with: path: spec/dummy/public/webpack - key: v4-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }} + key: dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }}-${{ matrix.versions }} - main: + dummy-app-integration-tests: needs: build-dummy-app-webpack-test-bundles strategy: + fail-fast: false matrix: - ruby: [2.7] - node: [14] - rake_task: ['run_rspec:all_dummy', 'run_rspec:all_but_examples', 'run_rspec:examples'] - runs-on: ubuntu-latest + versions: ['oldest', 'newest'] + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + persist-credentials: false - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: ${{ matrix.ruby }} + ruby-version: ${{ matrix.versions == 'oldest' && '3.0' || '3.3' }} + bundler: 2.5.9 - name: Setup Node - uses: actions/setup-node@v2-beta + uses: actions/setup-node@v4 with: - node-version: ${{ matrix.node }} + node-version: ${{ matrix.versions == 'oldest' && '16' || '20' }} - name: Print system information run: | echo "Linux release: "; cat /etc/issue @@ -93,47 +109,50 @@ jobs: echo "Node version: "; node -v echo "Yarn version: "; yarn --version echo "Bundler version: "; bundle --version + - name: run conversion script to support shakapacker v6 + if: matrix.versions == 'oldest' + run: script/convert - name: Save root node_modules to cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: node_modules - key: v4-package-node-modules-cache-${{ hashFiles('yarn.lock') }} + key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }} - name: Save root ruby gems to cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: vendor/bundle - key: v4-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }} + key: package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}-${{ hashFiles('Gemfile.development_dependencies') }}-${{ matrix.versions }} - name: Save dummy app ruby gems to cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: spec/dummy/vendor/bundle - key: v4-dummy-app-gem-cache-${{ hashFiles('spec/dummy/Gemfile.lock') }} + key: dummy-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}-${{ hashFiles('Gemfile.development_dependencies') }}-${{ matrix.versions }} - name: Save spec/dummy/node_modules to cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: spec/dummy/node_modules - key: v4-dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/yarn.lock') }} + key: dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/package.json') }}-${{ matrix.versions }} - id: get-sha run: echo "::set-output name=sha::$(git rev-parse HEAD)" - name: Save test webpack bundles to cache (for build number checksum used by rspec job) - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: spec/dummy/public/webpack - key: v4-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }} - - - name: Install Node modules with Yarn for renderer package + key: dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }}-${{ matrix.versions }} + - name: Install Node modules with Yarn run: | yarn install --no-progress --no-emoji - yarn run eslint -v sudo yarn global add yalc - name: yalc publish for react-on-rails run: yalc publish - name: yalc add react-on-rails run: cd spec/dummy && yalc add react-on-rails + - name: Install Node modules with Yarn for dummy app + run: cd spec/dummy && yarn install --no-progress --no-emoji - name: Install Ruby Gems for package - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 + run: bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle _2.5.9_ install --path=vendor/bundle --jobs=4 --retry=3 - name: Install Ruby Gems for dummy app - run: cd spec/dummy && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 + run: cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle _2.5.9_ install --path=vendor/bundle --jobs=4 --retry=3 - name: Ensure minimum required Chrome version run: | echo -e "Already installed $(google-chrome --version)\n" @@ -146,33 +165,36 @@ jobs: sudo apt-get install google-chrome-stable echo -e "\nInstalled $(google-chrome --version)" fi - - name: Touch webpack bundles - run: touch spec/dummy/public/webpack/test/* - - name: Install yalc globally - run: sudo yarn global add yalc - name: Increase the amount of inotify watchers run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p - - name: Prep for CI - run: bundle exec rake prepare_for_ci + - name: generate file system-based packs + run: cd spec/dummy && RAILS_ENV=test bundle exec rake react_on_rails:generate_packs + - name: Git Stuff + if: matrix.versions == 'oldest' + run: | + git config user.email "you@example.com" + git config user.name "Your Name" + git commit -am "stop generators from complaining about uncommitted code" + - run: cd spec/dummy && bundle info shakapacker - name: Main CI - run: bundle exec rake ${{ matrix.rake_task }} + run: bundle exec rake run_rspec:all_dummy - name: Store test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: main-rspec + name: main-rspec-${{ github.run_id }}-${{ github.job }}-${{ matrix.versions }} path: ~/rspec - name: Store artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: dummy-app-capybara + name: dummy-app-capybara-${{ github.run_id }}-${{ github.job }}-${{ matrix.versions }} path: spec/dummy/tmp/capybara - name: Store artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: dummy-app-test-log + name: dummy-app-test-log-${{ github.run_id }}-${{ github.job }}-${{ matrix.versions }} path: spec/dummy/log/test.log - name: Store artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: dummy-app-yarn-log + name: dummy-app-yarn-log-${{ github.run_id }}-${{ github.job }}-${{ matrix.versions }} path: spec/dummy/yarn-error.log diff --git a/.github/workflows/package-js-tests.yml b/.github/workflows/package-js-tests.yml index 8d5160db4..7c56378a0 100644 --- a/.github/workflows/package-js-tests.yml +++ b/.github/workflows/package-js-tests.yml @@ -1,19 +1,26 @@ name: JS unit tests for Renderer package -on: [push, pull_request] + +on: + push: + branches: + - 'master' + pull_request: jobs: build: strategy: matrix: - node: [12, 14] - runs-on: ubuntu-latest + versions: ['oldest', 'newest'] + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + persist-credentials: false - name: Setup Node - uses: actions/setup-node@v2-beta + uses: actions/setup-node@v4 with: - node-version: ${{ matrix.node }} + node-version: ${{ matrix.versions == 'oldest' && '16' || '20' }} - name: Print system information run: | echo "Linux release: "; cat /etc/issue @@ -22,10 +29,10 @@ jobs: echo "Node version: "; node -v echo "Yarn version: "; yarn --version - name: Save root node_modules to cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: node_modules - key: v4-package-node-modules-cache-${{ hashFiles('yarn.lock') }} + key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }} - name: Install Node modules with Yarn for renderer package run: | yarn install --no-progress --no-emoji diff --git a/.github/workflows/rspec-package-specs.yml b/.github/workflows/rspec-package-specs.yml index 214e7923e..80181f5c3 100644 --- a/.github/workflows/rspec-package-specs.yml +++ b/.github/workflows/rspec-package-specs.yml @@ -1,20 +1,27 @@ name: Rspec test for gem -on: [push, pull_request] +on: + push: + branches: + - 'master' + pull_request: jobs: - build: + rspec-package-tests: strategy: + fail-fast: false matrix: - ruby: [2.7] - node: [14] - runs-on: ubuntu-latest + versions: ['oldest', 'newest'] + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + persist-credentials: false - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: ${{ matrix.ruby }} + ruby-version: ${{ matrix.versions == 'oldest' && '3.0' || '3.3' }} + bundler: 2.5.9 - name: Print system information run: | echo "Linux release: "; cat /etc/issue @@ -24,22 +31,31 @@ jobs: echo "Node version: "; node -v echo "Yarn version: "; yarn --version echo "Bundler version: "; bundle --version + - name: run conversion script to support shakapacker v6 + if: matrix.versions == 'oldest' + run: script/convert - name: Save root ruby gems to cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: vendor/bundle - key: v4-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }} + key: package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}-${{ matrix.versions }} - name: Install Ruby Gems for package - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 + run: bundle check --path=vendor/bundle || bundle _2.5.9_ install --path=vendor/bundle --jobs=4 --retry=3 + - name: Git Stuff + if: matrix.versions == 'oldest' + run: | + git config user.email "you@example.com" + git config user.name "Your Name" + git commit -am "stop generators from complaining about uncommitted code" - name: Run rspec tests run: bundle exec rspec spec/react_on_rails - name: Store test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: main-rspec + name: main-rspec-${{ github.run_id }}-${{ github.job }}-${{ matrix.versions }} path: ~/rspec - name: Store artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: main-test-log + name: main-test-log-${{ github.run_id }}-${{ github.job }}-${{ matrix.versions }} path: log/test.log diff --git a/.gitignore b/.gitignore index 971e77111..b9eb951cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ /.bundle/ /.yardoc -/Gemfile.lock /_yardoc/ /coverage/ /doc/ @@ -11,9 +10,6 @@ /vendor/ /spec/examples.txt -/spec/dummy/client/node_modules -/spec/dummy/public/webpack/ -/spec/dummy/coverage/ /spec/react_on_rails/dummy-for-generators/ # RVM @@ -34,3 +30,11 @@ npm-debug.* .yalc yalc.lock + +.byebug_history + +# IDE +.idea/ + +# TypeScript +*.tsbuildinfo diff --git a/.prettierignore b/.prettierignore index fb2ce15f2..b34ea2a43 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,8 +3,12 @@ package.json tmp/ coverage/ **/app/assets/webpack/ -spec/dummy/public gen-examples/examples/* node_package/lib/* spec/react_on_rails/dummy-for-generators/app/javascript/bundles/HelloWorld/* bundle/ +spec/dummy/lib/bs/** +spec/dummy/public +**/.yalc/** +**/generated/** +*.bs.js diff --git a/.rubocop.yml b/.rubocop.yml index 1006263c8..25ef515fe 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,7 +7,7 @@ require: AllCops: NewCops: enable DisplayCopNames: true - TargetRubyVersion: 2.5 + TargetRubyVersion: 3.0.0 Include: - '**/Rakefile' @@ -94,6 +94,8 @@ RSpec/AnyInstance: Exclude: - 'spec/react_on_rails/git_utils_spec.rb' - 'spec/react_on_rails/locales_to_js_spec.rb' + - 'spec/react_on_rails/binstubs/dev_spec.rb' + - 'spec/react_on_rails/binstubs/dev_static_spec.rb' RSpec/DescribeClass: Enabled: false @@ -111,6 +113,8 @@ RSpec/BeforeAfterAll: Exclude: - 'spec/react_on_rails/generators/dev_tests_generator_spec.rb' - 'spec/react_on_rails/generators/install_generator_spec.rb' + - 'spec/react_on_rails/binstubs/dev_spec.rb' + - 'spec/react_on_rails/binstubs/dev_static_spec.rb' RSpec/MessageChain: Enabled: false @@ -128,3 +132,8 @@ RSpec/MultipleMemoizedHelpers: Style/GlobalVars: Exclude: - 'spec/dummy/config/environments/development.rb' + +RSpec/NoExpectationExample: + AllowedPatterns: + - ^expect_ + - ^assert_ diff --git a/.travis.yml b/.travis.yml index 5e8c1c8e0..6790f821f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ sudo: required language: ruby rvm: - - 2.5.3 + - 2.5.9 - 2.6.5 - 2.7.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 8956ff432..aaa732e31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,21 +1,219 @@ # Change Log -All notable changes to this project's source code will be documented in this file. Items under `Unreleased` is upcoming features that will be out in next version. NOTE: major versions of the npm module and the gem must be kept in sync. +All notable changes to this project's source code will be documented in this file. Items under `Unreleased` is upcoming features that will be out in the next version. Migration instructions for the major updates can be found [here](https://www.shakacode.com/react-on-rails/docs/guides/upgrading-react-on-rails#upgrading-to-version-9.md). Some smaller migration information can be found here. -## Need Help Migrating? -If you would like help in migrating between React on Rails versions or help with implementing server rendering, please contact [justin@shakacode.com](mailto:justin@shakacode.com) for information about our [React on Rails Pro Support Options](https://www.shakacode.com/react-on-rails-pro). +## Want to Save Time Updating? -We specialize in helping companies to quickly and efficiently move from versions before 9 to current. The older versions use the Rails asset pipeline to package client assets. The current and recommended way is to use Webpack 4 for asset preparation. You may also need help migrating from the `rails/webpacker`'s Webpack configuration to a better setup ready for Server Side Rendering. +If you need help upgrading `react_on_rails`, `webpacker` to `shakapacker`, or JS packages, contact justin@shakacode.com. We can upgrade your project and improve your development and customer experiences, allowing you to focus on building new features or fixing bugs instead. + +For an overview of working with us, see our [Client Engagement Model](https://www.shakacode.com/blog/client-engagement-model/) article and [how we bill for time](https://www.shakacode.com/blog/shortcut-jira-trello-github-toggl-time-and-task-tracking/). + +If you think ShakaCode can help your project, [click here](https://meetings.hubspot.com/justingordon/30-minute-consultation) to book a call with [Justin Gordon](mailto:justin@shakacode.com), the creator of React on Rails and Shakapacker. ## Contributors Please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version. ## Versions ### [Unreleased] -Changes since last non-beta release. +Changes since the last non-beta release. + +#### Fixed + +- Incorrect type and confusing name for `ReactOnRails.registerStore`, use `registerStoreGenerators` instead. [PR 1651](https://github.com/shakacode/react_on_rails/pull/1651) by [alexeyr-ci](https://github.com/alexeyr-ci). +- Changed the ReactOnRails' version checker to use `ReactOnRails.configuration.node_modules_location` to determine the location of the package.json that the `react-on-rails` dependency is expected to be set by. +- Also, all errors that would be raised by the version checking have been converted to `Rails.Logger` warnings to avoid any breaking changes. [PR 1657](https://github.com/shakacode/react_on_rails/pull/1657) by [judahmeek](https://github.com/judahmeek). +- Enable use as a `git:` dependency. [PR 1664](https://github.com/shakacode/react_on_rails/pull/1664) by [alexeyr-ci](https://github.com/alexeyr-ci). + +#### Added +- Added streaming server rendering support: + - [PR #1633](https://github.com/shakacode/react_on_rails/pull/1633) by [AbanoubGhadban](https://github.com/AbanoubGhadban). + - New `stream_react_component` helper for adding streamed components to views + - New `streamServerRenderedReactComponent` function in the react-on-rails package that uses React 18's `renderToPipeableStream` API + - Enables progressive page loading and improved performance for server-rendered React components + - Added support for replaying console logs that occur during server rendering of streamed React components. This enables debugging of server-side rendering issues by capturing and displaying console output on the client and on the server output. [PR #1647](https://github.com/shakacode/react_on_rails/pull/1647) by [AbanoubGhadban](https://github.com/AbanoubGhadban). + - Added support for handling errors happening during server rendering of streamed React components. It handles errors that happen during the initial render and errors that happen inside suspense boundaries. [PR #1648](https://github.com/shakacode/react_on_rails/pull/1648) by [AbanoubGhadban](https://github.com/AbanoubGhadban). + - Added support for passing options to `YAML.safe_load` when loading locale files with `config.i18n_yml_safe_load_options`. [PR #1668](https://github.com/shakacode/react_on_rails/pull/1668) by [dzirtusss](https://github.com/dzirtusss). + +#### Changed +- Console replay script generation now awaits the render request promise before generating, allowing it to capture console logs from asynchronous operations. This requires using a version of the Node renderer that supports replaying async console logs. [PR #1649](https://github.com/shakacode/react_on_rails/pull/1649) by [AbanoubGhadban](https://github.com/AbanoubGhadban). + +### [14.0.5] - 2024-08-20 +#### Fixed +- Should force load react-components which send over turbo-stream [PR #1620](https://github.com/shakacode/react_on_rails/pull/1620) by [theforestvn88](https://github.com/theforestvn88). + +### [14.0.4] - 2024-07-02 + +#### Improved +- Improved dependency management by integrating package_json. [PR 1639](https://github.com/shakacode/react_on_rails/pull/1639) by [vaukalak](https://github.com/vaukalak). + +#### Changed +- Update outdated GitHub Actions to use Node.js 20.0 versions instead [PR 1623](https://github.com/shakacode/react_on_rails/pull/1623) by [adriangohjw](https://github.com/adriangohjw). + +### [14.0.3] - 2024-06-28 + +#### Fixed +- Fixed css-loader installation with [PR 1634](https://github.com/shakacode/react_on_rails/pull/1634) by [vaukalak](https://github.com/vaukalak). +- Address a number of typos and grammar mistakes [PR 1631](https://github.com/shakacode/react_on_rails/pull/1631) by [G-Rath](https://github.com/G-Rath). +- Adds an adapter module & improves test suite to support all versions of Shakapacker. [PR 1622](https://github.com/shakacode/react_on_rails/pull/1622) by [adriangohjw](https://github.com/adriangohjw) and [judahmeek](https://github.com/judahmeek). + +### [14.0.2] - 2024-06-11 + +#### Fixed +- Generator errors with Shakapacker v8+ fixed [PR 1629](https://github.com/shakacode/react_on_rails/pull/1629) by [vaukalak](https://github.com/vaukalak) + +### [14.0.1] - 2024-05-16 + +#### Fixed +- Pack Generation: Added functionality that will add an import statement, if missing, to the server bundle entry point even if the auto-bundle generated files still exist [PR 1610](https://github.com/shakacode/react_on_rails/pull/1610) by [judahmeek](https://github.com/judahmeek). + +### [14.0.0] - 2024-04-03 +_Major bump because dropping support for Ruby 2.7 and deprecated `webpackConfigLoader.js`._ + +#### Removed +- Dropped Ruby 2.7 support [PR 1595](https://github.com/shakacode/react_on_rails/pull/1595) by [ahangarha](https://github.com/ahangarha). +- Removed deprecated `webpackConfigLoader.js` [PR 1600](https://github.com/shakacode/react_on_rails/pull/1600) by [ahangarha](https://github.com/ahangarha). + +#### Fixed +- Trimmed the Gem to remove package.json which could cause superflous security warnings. [PR 1605](https://github.com/shakacode/react_on_rails/pull/1605) by [justin808](https://github.com/justin808). +- Prevent displaying the deprecation message for using `webpacker_precompile?` method and `webpacker:clean` rake task when using Shakapacker v7+ [PR 1592](https://github.com/shakacode/react_on_rails/pull/1592) by [ahangarha](https://github.com/ahangarha). +- Fixed Typescript types for ServerRenderResult, ReactComponent, RenderFunction, and RailsContext interfaces. [PR 1582](https://github.com/shakacode/react_on_rails/pull/1582) & [PR 1585](https://github.com/shakacode/react_on_rails/pull/1585) by [kotarella1110](https://github.com/kotarella1110) +- Removed a workaround in `JsonOutput#escape` for an no-longer supported Rails version. Additionally, removed `Utils.rails_version_less_than_4_1_1` +which was only used in the workaround. [PR 1580](https://github.com/shakacode/react_on_rails/pull/1580) by [wwahammy](https://github.com/wwahammy) + +#### Added +- Exposed TypeScript all types [PR 1586](https://github.com/shakacode/react_on_rails/pull/1586) by [kotarella1110](https://github.com/kotarella1110) + +### [13.4.0] - 2023-07-30 +#### Fixed +- Fixed Pack Generation logic during `assets:precompile` if `auto_load_bundle` is `false` & `components_subdirectory` is not set. [PR 1567](https://github.com/shakacode/react_on_rails/pull/1545) by [blackjack26](https://github.com/blackjack26) & [judahmeek](https://github.com/judahmeek). + +#### Improved +- Improved performance by removing an unnecessary JS eval from Ruby. [PR 1544](https://github.com/shakacode/react_on_rails/pull/1544) by [wyattades](https://github.com/wyattades). + +#### Added +- Added support for Shakapacker 7 in install generator [PR 1548](https://github.com/shakacode/react_on_rails/pull/1548) by [ahangarha](https://github.com/ahangarha). + +#### Changed +- Throw error when attempting to redefine ReactOnRails. [PR 1562](https://github.com/shakacode/react_on_rails/pull/1562) by [rubenochiavone](https://github.com/rubenochiavone). +- Prevent generating FS-based packs when `component_subdirectory` configuration is not present. [PR 1567](https://github.com/shakacode/react_on_rails/pull/1567) by [blackjack26](https://github.com/blackjack26). +- Removed a requirement for autoloaded pack files to be generated as part of CI or deployment separate from initial Shakapacker bundling. [PR 1545](https://github.com/shakacode/react_on_rails/pull/1545) by [judahmeek](https://github.com/judahmeek). + + +### [13.3.5] - 2023-05-31 +#### Fixed +- Fixed race condition where a react component could attempt to initialize before it had been registered. [PR 1540](https://github.com/shakacode/react_on_rails/pull/1540) by [judahmeek](https://github.com/judahmeek). + +### [13.3.4] - 2023-05-23 + +#### Added +- Improved functionality of Filesystem-based pack generation & auto-bundling. Added `make_generated_server_bundle_the_entrypoint` configuration key. [PR 1531](https://github.com/shakacode/react_on_rails/pull/1531) by [judahmeek](https://github.com/judahmeek). + +#### Removed +- Removed unneeded `HMR=true` from `Procfile.dev` in install template [PR 1537](https://github.com/shakacode/react_on_rails/pull/1537) by [ahangarha](https://github.com/ahangarha). + +### [13.3.3] - 2023-03-21 + +#### Fixed +- Fixed bug regarding loading FS-based packs. [PR 1527](https://github.com/shakacode/react_on_rails/pull/1527) by [judahmeek](https://github.com/judahmeek). + +### [13.3.2] - 2023-02-24 + +#### Fixed +- Fixed the bug in `bin/dev` and `bin/dev-static` scripts by using `system` instead of `exec` and remove option to pass arguments [PR 1519](https://github.com/shakacode/react_on_rails/pull/1519) by [ahangarha](https://github.com/ahangarha). + +### [13.3.1] - 2023-01-30 +#### Added +- Optimized `ReactOnRails::TestHelper`'s RSpec integration using `when_first_matching_example_defined`. [PR 1496](https://github.com/shakacode/react_on_rails/pull/1496) by [mcls](https://github.com/mcls). + +#### Fixed +- Fixed bug regarding FS-based packs generation. [PR 1515](https://github.com/shakacode/react_on_rails/pull/1515) by [pulkitkkr](https://github.com/pulkitkkr). + +### [13.3.0] - 2023-01-29 +#### Fixed +- Fixed pack not found warning while using `react_component` and `react_component_hash` helpers, even when corresponding chunks are present. [PR 1511](https://github.com/shakacode/react_on_rails/pull/1511) by [pulkitkkr](https://github.com/pulkitkkr). +- Fixed FS-based packs generation functionality to trigger pack generation on the creation of a new react component inside `components_subdirectory`. [PR 1506](https://github.com/shakacode/react_on_rails/pull/1506) by [pulkitkkr](https://github.com/pulkitkkr). +- Upgrade several JS dependencies to fix security issues. [PR 1514](https://github.com/shakacode/react_on_rails/pull/1514) by [ahangarha](https://github.com/ahangarha). + +#### Added +- Added `./bin/dev` and `./bin/dev-static` executables to ease and standardize running the dev server. [PR 1491](https://github.com/shakacode/react_on_rails/pull/1491) by [ahangarha](https://github.com/ahangarha). + +### [13.2.0] - 2022-12-23 + +#### Fixed +- Fix reactOnRailsPageUnloaded when there is no component on the page. Important for apps using both hotwire and react_on_rails. [PR 1498](https://github.com/shakacode/react_on_rails/pull/1498) by [NhanHo](https://github.com/NhanHo). +- Fixing wrong type. The throwIfMissing param of getStore should be optional as it defaults to true. [PR 1480](https://github.com/shakacode/react_on_rails/pull/1480) by [wouldntsavezion](https://github.com/wouldntsavezion). + +#### Added +- Exposed `reactHydrateOrRender` utility via [PR 1481](https://github.com/shakacode/react_on_rails/pull/1481) by [vaukalak](https://github.com/vaukalak). + +### [13.1.0] - 2022-08-20 + +#### Improved +- Removed addition of `mini_racer` gem by default. [PR 1453](https://github.com/shakacode/react_on_rails/pull/1453) by [vtamara](https://github.com/vtamara) and [tomdracz](https://github.com/tomdracz). + + Using `mini_racer` makes most sense when deploying or building in environments that do not have Javascript runtime present. Since `react_on_rails` requires Node.js, there's no reason to override `ExecJS` runtime with `mini_racer`. + + To migrate this change, remove `mini_racer` gem from your `Gemfile` and test your app for correct behaviour. You can continue using `mini_racer` and it will be still picked as the default `ExecJS` runtime, if present in your app `Gemfile`. + +- Upgraded the example test app in `spec/dummy` to React 18. [PR 1463](https://github.com/shakacode/react_on_rails/pull/1463) by [alexeyr](https://github.com/alexeyr). + +- Added file-system-based automatic bundle generation feature. [PR 1455](https://github.com/shakacode/react_on_rails/pull/1455) by [pulkitkkr](https://github.com/pulkitkkr). -*Please add entries here for your pull requests that are not yet released.* +#### Fixed +- Correctly unmount roots under React 18. [PR 1466](https://github.com/shakacode/react_on_rails/pull/1466) by [alexeyr](https://github.com/alexeyr). + +- Fixed the `You are importing hydrateRoot from "react-dom" [...] You should instead import it from "react-dom/client"` warning under React 18 ([#1441](https://github.com/shakacode/react_on_rails/issues/1441)). [PR 1460](https://github.com/shakacode/react_on_rails/pull/1460) by [alexeyr](https://github.com/alexeyr). + + In exchange, you may see a warning like this when building using any version of React below 18: + ``` + WARNING in ./node_modules/react-on-rails/node_package/lib/reactHydrateOrRender.js19:25-52 + Module not found: Error: Can't resolve 'react-dom/client' in '/home/runner/work/react_on_rails/react_on_rails/spec/dummy/node_modules/react-on-rails/node_package/lib' + @ ./node_modules/react-on-rails/node_package/lib/ReactOnRails.js 34:45-78 + @ ./client/app/packs/client-bundle.js 5:0-42 32:0-23 35:0-21 59:0-26 + ``` + It can be safely [suppressed](https://webpack.js.org/configuration/other-options/#ignorewarnings) in your Webpack configuration. + +### [13.0.2] - 2022-03-09 +#### Fixed +- React 16 doesn't support version property, causing problems loading React on Rails. [PR 1435](https://github.com/shakacode/react_on_rails/pull/1435) by [justin808](https://github.com/justin808). + +### [13.0.1] - 2022-02-09 +#### Improved +- Updated the default generator. [PR 1431](https://github.com/shakacode/react_on_rails/pull/1431) by [justin808](https://github.com/justin808). + +### [13.0.0] - 2022-02-08 +#### Breaking +- Removed webpacker as a dependency. Add gem Shakapacker to your project, and update your package.json to also use shakapacker. + +#### Fixed +- Proper throwing of exceptions. +- Default configuration better handles test env. + +### [12.6.0] - 2022-01-22 + +#### Added +- A `rendering_props_extension` configuration which takes a module with an `adjust_props_for_client_side_hydration` method, which is used to process props differently for server/client if `prerender` is set to `true`. [PR 1413](https://github.com/shakacode/react_on_rails/pull/1413) by [gscarv13](https://github.com/gscarv13) & [judahmeek](https://github.com/judahmeek). + +### [12.5.2] - 2021-12-29 +#### Fixed +- Usage of config.build_production_command for custom command for production builds fixed. [PR 1415](https://github.com/shakacode/react_on_rails/pull/1415) by [judahmeek](https://github.com/judahmeek). + +### [12.5.1] - 2021-12-27 + +#### Fixed +- A fatal server rendering error if running an ReactOnRails >=12.4.0 with ReactOnRails Pro <2.4.0. [PR 1412](https://github.com/shakacode/react_on_rails/pull/1412) by [judahmeek](https://github.com/judahmeek). + +### [12.5.0] - 2021-12-26 + +#### Added +- Support for React 18, including the changed SSR API. [PR 1409](https://github.com/shakacode/react_on_rails/pull/1409) by [kylemellander](https://github.com/kylemellander). +- Added webpack configuration files as part of the generator and updated webpacker to version 6. [PR 1404](https://github.com/shakacode/react_on_rails/pull/1404) by [gscarv13](https://github.com/gscarv13). +- Supports Rails 7. + +#### Changed +- Changed logic of determining the usage of the default rails/webpacker webpack config or a custom command to only check if the config.build_production_command is defined. [PR 1402](https://github.com/shakacode/react_on_rails/pull/1402) by [justin808](https://github.com/justin808) and [gscarv13](https://github.com/gscarv13). +- Minimum required Ruby is 2.7 to match latest rails/webpacker. ### [12.4.0] - 2021-09-22 #### Added @@ -23,7 +221,7 @@ Changes since last non-beta release. - Ability to stop React on Rails from modifying or creating the `assets:precompile` task. [PR 1371](https://github.com/shakacode/react_on_rails/pull/1371) by [justin808](https://github.com/justin808). Thanks to [elstgav](https://github.com/elstgav) for [the suggestion](https://github.com/shakacode/react_on_rails/issues/1368)! -- Ability to stop stubbing of setTimeout, setInterval, & clearTimeout conditional by setting `ReactOnRailsPro.config.include_execjs_polyfills = false` in the React on Rails Pro configuration file. Also, added the ability to have render functions return a promise to be awaited by React on Rails Pro Node Renderer. [PR 1380](https://github.com/shakacode/react_on_rails/pull/1380) by [judahmeek](https://github.com/judahmeek) +- Added the ability to have render functions return a promise to be awaited by React on Rails Pro Node Renderer. [PR 1380](https://github.com/shakacode/react_on_rails/pull/1380) by [judahmeek](https://github.com/judahmeek) ### [12.3.0] - 2021-07-26 #### Added @@ -42,7 +240,7 @@ Changes since last non-beta release. - Added the ability to assign a module with a `call` method to `config.build_production_command`. See [the configuration docs](https://www.shakacode.com/react-on-rails/docs/guides/configuration). [PR 1362: Accept custom module for config.build_production_command](https://github.com/shakacode/react_on_rails/pull/1362). #### Fixed -- Stop setting NODE_ENV value during precompile, as it interferred with rails/webpacker's setting of NODE_ENV to production by default. Fixes [#1334](https://github.com/shakacode/react_on_rails/issues/1334). [PR 1356: Don't set NODE_ENV in assets.rake](https://github.com/shakacode/react_on_rails/pull/1356) by [alexrozanski](https://github.com/alexrozanski). +- Stop setting NODE_ENV value during precompile, as it interfered with rails/webpacker's setting of NODE_ENV to production by default. Fixes [#1334](https://github.com/shakacode/react_on_rails/issues/1334). [PR 1356: Don't set NODE_ENV in assets.rake](https://github.com/shakacode/react_on_rails/pull/1356) by [alexrozanski](https://github.com/alexrozanski). ### [12.0.4] - 2020-11-14 #### Fixed @@ -62,7 +260,7 @@ Changes since last non-beta release. ### [12.0.1] - 2020-07-09 #### Fixed -- Changed invocation of webpacker:clean to use a very large number of versions so it does not acidentally delete the server-bundle.js. [PR 1306](https://github.com/shakacode/react_on_rails/pull/1306) by By [justin808](https://github.com/justin808). +- Changed invocation of webpacker:clean to use a very large number of versions so it does not accidentally delete the server-bundle.js. [PR 1306](https://github.com/shakacode/react_on_rails/pull/1306) by By [justin808](https://github.com/justin808). ### [12.0.0] - 2020-07-08 For upgrade instructions, see [docs/guides/upgrading-react-on-rails.md](https://www.shakacode.com/react-on-rails/docs/guides/upgrading-react-on-rails). @@ -82,7 +280,7 @@ invoked to return the React component. In that case, you won't need to pass any [PR 1268](https://github.com/shakacode/react_on_rails/pull/1268) by [justin808](https://github.com/justin808) See [docs/guides/upgrading-react-on-rails](https://www.shakacode.com/react-on-rails/docs/guides/upgrading-react-on-rails#upgrading-to-v12) -for details. +for details. #### Other Updates * `react_on_rails` fully supports `rails/webpacker`. The example test app in `spec/dummy` was recently converted over to use rails/webpacker v4+. It's a good example of how to leverage rails/webpacker's webpack configuration for server-side rendering. @@ -221,7 +419,7 @@ Do not use. Unpublished. Caused by an issue with the release script. ### [11.0.7] - 2018-05-16 #### Fixed -- Fix npm publshing. [PR 1090](https://github.com/shakacode/react_on_rails/pull/1090) by [justin808](https://github.com/justin808). +- Fix npm publishing. [PR 1090](https://github.com/shakacode/react_on_rails/pull/1090) by [justin808](https://github.com/justin808). ### [11.0.6] - 2018-05-15 #### Changed @@ -363,7 +561,7 @@ Moved to [our documentation](https://www.shakacode.com/react-on-rails/docs/guide - Fixes GitUtils.uncommitted_changes? throwing an error when called in an environment without Git, and allows install generator to be run successfully with `--ignore-warnings` [#878](https://github.com/shakacode/react_on_rails/pull/878) by [jasonblalock](https://github.com/jasonblalock). ## [8.0.5] - 2017-07-04 -### fixed +#### Fixed - Corrects `devBuild` value for webpack production build from webpackConfigLoader. [#877](https://github.com/shakacode/react_on_rails/pull/877) by [chenqingspring](https://github.com/chenqingspring). - Remove contentBase deprecation warning message. [#878](https://github.com/shakacode/react_on_rails/pull/878) by [ened ](https://github.com/ened). - Removes invalid reference to _railsContext in the generated files. [#886](https://github.com/shakacode/react_on_rails/pull/886) by [justin808](https://github.com/justin808). @@ -372,11 +570,11 @@ Moved to [our documentation](https://www.shakacode.com/react-on-rails/docs/guide *Note: 8.0.4 skipped.* ## [8.0.3] - 2017-06-19 -### Fixed +#### Fixed - Ruby 2.1 issue due to `<<~` as reported in [issue #870](https://github.com/shakacode/react_on_rails/issues/870). [#867](https://github.com/shakacode/react_on_rails/pull/867) by [justin808](https://github.com/justin808) ## [8.0.2] - 2017-06-04 -### Fixed +#### Fixed - Any failure in webpack to build test files quits tests. - Fixed a Ruby 2.4 potential crash which could cause a crash due to pathname change in Ruby 2.4. - CI Improvements: @@ -387,7 +585,7 @@ Moved to [our documentation](https://www.shakacode.com/react-on-rails/docs/guide - [#862](https://github.com/shakacode/react_on_rails/pull/862) by [justin808](https://github.com/justin808) ## [8.0.1] - 2017-05-30 -### Fixed +#### Fixed - Generator no longer modifies `assets.rb`. [#859](https://github.com/shakacode/react_on_rails/pull/859) by [justin808](https://github.com/justin808) ## [8.0.0] - 2017-05-29 @@ -400,21 +598,21 @@ Moved to [our documentation](https://www.shakacode.com/react-on-rails/docs/guide - For a simple example of the webpacker_lite setup, run the basic generator. ## [8.0.0-beta.3] - 2017-05-27 -### Changed +#### Changed - Major updates for WebpackerLite 2.0.2. [#844](https://github.com/shakacode/react_on_rails/pull/845) by [justin808](https://github.com/justin808) with help from ](https://github.com/robwise) - Logging no longer occurs when trace is turned to false. [#845](https://github.com/shakacode/react_on_rails/pull/845) by [conturbo](https://github.com/Conturbo) ## [8.0.0-beta.2] - 2017-05-08 -### Changed +#### Changed Removed unnecessary values in default paths.yml files for generators. [#834](https://github.com/shakacode/react_on_rails/pull/834) by [justin808](https://github.com/justin808). ## [8.0.0-beta.1] - 2017-05-03 -### Added +#### Added Support for WebpackerLite in the generators. [#822](https://github.com/shakacode/react_on_rails/pull/822) by [kaizencodes](https://github.com/kaizencodes) and [justin808](https://github.com/justin808). -### Changed +#### Changed Breaking change is that the default value of symlink_non_digested_assets_regex has changed from this old value to nil. This is a breaking change if you didn't have this value set in your config/initializers/react_on_rails.rb file and you need this because you're using webpack's CSS @@ -434,65 +632,65 @@ Same as 7.0.1. *Accidental release of beta gem here* ## [7.0.1] - 2017-04-27 -### Fixed +#### Fixed - Fix to handle nil values in json_safe_and_pretty [#823](https://github.com/shakacode/react_on_rails/pull/823) by [dzirtusss](https://github.com/dzirtusss) ## [7.0.0] - 2017-04-25 -### Changed +#### Changed - Any version differences in gem and node package for React on Rails throw an error [#821](https://github.com/shakacode/react_on_rails/pull/821) by [justin808](https://github.com/justin808) -### Fixed +#### Fixed - Fixes serious performance regression when using String props for rendering. [#821](https://github.com/shakacode/react_on_rails/pull/821) by [justin808](https://github.com/justin808) ## [6.10.1] - 2017-04-23 -### Fixed +#### Fixed - Improve json conversion with tests and support for older Rails 3.x. [#787](https://github.com/shakacode/react_on_rails/pull/787) by [cheremukhin23](https://github.com/cheremukhin23) and [Ynote](https://github.com/Ynote). ## [6.10.0] - 2017-04-13 -### Added +#### Added - Add an ability to return multiple HTML strings in a `Hash` as a result of `react_component` method call. Allows to build `
` contents with [React Helmet](https://github.com/nfl/react-helmet). [#800](https://github.com/shakacode/react_on_rails/pull/800) by [udovenko](https://github.com/udovenko). -### Fixed +#### Fixed - Fix PropTypes, createClass deprecation warnings for React 15.5.x. [#804](https://github.com/shakacode/react_on_rails/pull/804) by [udovenko ](https://github.com/udovenko). ## [6.9.3] - 2017-04-03 -### Fixed +#### Fixed - Removed call of to_json on strings when formatting props. [#791](https://github.com/shakacode/react_on_rails/pull/791) by [justin808](https://github.com/justin808). ## [6.9.2] - 2017-04-02 -### Changed +#### Changed - Update version_checker.rb to `logger.error` rather than `logger.warn` for gem/npm version mismatch. [#788](https://github.com/shakacode/react_on_rails/issues/788) by [justin808](https://github.com/justin808). -### Fixed +#### Fixed - Remove pretty formatting of JSON in development. [#789](https://github.com/shakacode/react_on_rails/pull/789) by [justin808](https://github.com/justin808) - Clear hydrated stores with each server rendered block. [#785](https://github.com/shakacode/react_on_rails/pull/785) by [udovenko](https://github.com/udovenko) ## [6.9.1] - 2017-03-30 -### Fixed +#### Fixed - Fixes Crash in Development for String Props. [#784](https://github.com/shakacode/react_on_rails/issues/784) by [justin808](https://github.com/justin808). ## [6.9.0] - 2017-03-29 -### Fixed +#### Fixed - Fixed error in the release script. [#767](https://github.com/shakacode/react_on_rails/issues/767) by [isolo](https://github.com/isolo). -### Changed +#### Changed - Use +``` + +## When to Use Streaming + +Streaming SSR is particularly valuable in specific scenarios. Here's when to consider it: + +### Ideal Use Cases + +1. **Data-Heavy Pages** + - Pages that fetch data from multiple sources + - Dashboard-style layouts where different sections can load independently + - Content that requires heavy processing or computation + +2. **Progressive Enhancement** + - When you want users to see and interact with parts of the page while others load + - For improving perceived performance on slower connections + - When different parts of your page have different priority levels + +3. **Large, Complex Applications** + - Applications with multiple independent widgets or components + - Pages where some content is critical and other content is supplementary + - When you need to optimize Time to First Byte (TTFB) + +### Best Practices for Streaming + +1. **Component Structure** + ```jsx + // Good: Independent sections that can stream separately +Exception in rendering[.\s\S]*Sync Error[.\s\S]*<\/pre>/); + expect(chunks[0].consoleReplayScript).toBe(''); + expect(chunks[0].hasErrors).toBe(true); + expect(chunks[0].isShellReady).toBe(false); + }); + + it("doesn't emit an error if there is an error in the shell and throwJsErrors is false", async () => { + const { renderResult, chunks } = setupStreamTest({ throwSyncError: true, throwJsErrors: false }); + const onError = jest.fn(); + renderResult.on('error', onError); + await new Promise((resolve) => renderResult.on('end', resolve)); + + expect(onError).not.toHaveBeenCalled(); + expect(chunks).toHaveLength(1); + expect(chunks[0].html).toMatch(/Exception in rendering[.\s\S]*Sync Error[.\s\S]*<\/pre>/); + expect(chunks[0].consoleReplayScript).toBe(''); + expect(chunks[0].hasErrors).toBe(true); + expect(chunks[0].isShellReady).toBe(false); + }); + + it('emits an error if there is an error in the async content and throwJsErrors is true', async () => { + const { renderResult, chunks } = setupStreamTest({ throwAsyncError: true, throwJsErrors: true }); + const onError = jest.fn(); + renderResult.on('error', onError); + await new Promise((resolve) => renderResult.on('end', resolve)); + + expect(onError).toHaveBeenCalled(); + expect(chunks).toHaveLength(2); + expect(chunks[0].html).toContain('Header In The Shell'); + expect(chunks[0].consoleReplayScript).toBe(''); + expect(chunks[0].hasErrors).toBe(false); + expect(chunks[0].isShellReady).toBe(true); + // Script that fallbacks the render to client side + expect(chunks[1].html).toMatch(/\"}" end + describe "#load_pack_for_generated_component" do + let(:render_options) do + ReactOnRails::ReactComponent::RenderOptions.new(react_component_name: "component_name", + options: {}) + end + + it "appends js/css pack tag" do + allow(helper).to receive(:append_javascript_pack_tag) + allow(helper).to receive(:append_stylesheet_pack_tag) + expect { helper.load_pack_for_generated_component("component_name", render_options) }.not_to raise_error + expect(helper).to have_received(:append_javascript_pack_tag).with("generated/component_name", { defer: true }) + expect(helper).to have_received(:append_stylesheet_pack_tag).with("generated/component_name") + end + + it "throws an error in development if generated component isn't found" do + allow(Rails.env).to receive(:development?).and_return(true) + expect { helper.load_pack_for_generated_component("nonexisting_component", render_options) } + .to raise_error(ReactOnRails::Error, /the generated component entrypoint/) + end + end + describe "#json_safe_and_pretty(hash_or_string)" do it "raises an error if not hash nor string nor nil passed" do expect { helper.json_safe_and_pretty(false) }.to raise_error(ReactOnRails::Error) @@ -143,7 +169,7 @@ class PlainReactOnRailsHelper end let(:json_props_sanitized) do - '{"hello":"world","free":"of charge","x":"\\u003c/script\\u003e\\u003cscrip'\ + '{"hello":"world","free":"of charge","x":"\\u003c/script\\u003e\\u003cscrip' \ "t\\u003ealert('foo')\\u003c/script\\u003e\"}" end @@ -265,6 +291,26 @@ class PlainReactOnRailsHelper it { is_expected.not_to include '' } it { is_expected.to include '' } end + + describe "'force_load' tag option" do + let(:force_load_script) do + %( +ReactOnRails.reactOnRailsComponentLoaded('App-react-component-0'); + ).html_safe + end + + context "with 'force_load' == true" do + subject { react_component("App", force_load: true) } + + it { is_expected.to include force_load_script } + end + + context "without 'force_load' tag option" do + subject { react_component("App") } + + it { is_expected.not_to include force_load_script } + end + end end describe "#redux_store" do @@ -275,9 +321,9 @@ class PlainReactOnRailsHelper end let(:react_store_script) do - '" + '" end it { expect(self).to respond_to :redux_store } @@ -320,5 +366,30 @@ class PlainReactOnRailsHelper expect { ob.send(:rails_context, server_side: false) }.not_to raise_error end end + + describe "#rails_context_if_not_already_rendered" do + let(:helper) { PlainReactOnRailsHelper.new } + + before do + allow(helper).to receive(:rails_context).and_return({ some: "context" }) + end + + it "returns a script tag with rails context when not already rendered" do + result = helper.send(:rails_context_if_not_already_rendered) + expect(result).to include('