-
-
Notifications
You must be signed in to change notification settings - Fork 638
Add Shakapacker precompile hook support for auto pack generation #1905
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
Add Shakapacker precompile hook support for auto pack generation #1905
Conversation
This commit updates all references to shakapacker from version 8.2.0 to 9.3.0 across the codebase: Key changes: - Updated Gemfile.development_dependencies to require shakapacker 9.3.0 - Updated spec/dummy/package.json devDependencies to shakapacker 9.3.0 - Updated lib/react_on_rails/packer_utils.rb async loading version check to 9.3.0 - Updated rakelib/shakapacker_examples.rake to use >= 9.3.0 for generated examples - Updated script/convert to reference shakapacker 9.3.0 - Updated spec/react_on_rails/packer_utils_spec.rb test expectations to match new version - Updated Gemfile.lock and yarn.lock files after bundle/yarn install All linting checks pass with bundle exec rubocop showing no offenses. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Keep the async loading version requirement at 8.2.0 (when the feature was introduced) rather than requiring the latest 9.3.0 version. This allows users with any version >= 8.2.0 to use the async loading feature. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Shakapacker 9.3.0 defaults to using SWC as the JavaScript transpiler (20x faster than Babel). This change ensures compatibility by: - Added @swc/core and swc-loader to spec/dummy/package.json devDependencies - Updated generator template shakapacker.yml to use javascript_transpiler: "swc" (new setting name) - Replaced deprecated webpack_loader setting with javascript_transpiler in templates - Updated yarn.lock after installing new dependencies This fixes the webpack build error: "Your Shakapacker config specified using swc, but swc-loader package is not installed" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Shakapacker 9.0.0 introduced a breaking change where CSS Modules now use named exports by default (namedExport: true). This breaks existing code using default imports like `import styles from './styles.module.css'`. This commit restores backward compatibility by configuring css-loader to: - Set namedExport: false to allow default imports - Use exportLocalsConvention: 'camelCase' for consistent naming This allows existing code to continue working without changing all import statements to use named exports. Related to Shakapacker 9.0.0 breaking change: https://github.com/shakacode/shakapacker/blob/main/CHANGELOG.md#v900 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The generators were missing swc-loader and @swc/core in the dev dependencies, causing CI failures when generating example apps with Shakapacker 9.3.0. This commit adds both packages to the dev_deps list in: - lib/generators/react_on_rails/base_generator.rb - lib/generators/react_on_rails/install_generator.rb Also fixes ESLint warnings in webpack config for CSS modules configuration. This ensures that all generated apps have the required SWC dependencies for Shakapacker 9.3.0's default JavaScript transpiler. Fixes CI failures in: - examples (3.2, minimum) - examples (3.4, latest) - build-dummy-app-webpack-test-bundles tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The version checker was failing during `rake shakapacker:install` because it runs before package.json is created. This broke the generator examples in CI with error: "package.json file not found". This commit updates the engine initializer to skip validation when package.json doesn't exist yet, allowing installation tasks to complete successfully. The validation will still run normally once package.json exists, ensuring version compatibility in production apps. Fixes generator test failures: - examples (3.2, minimum) - examples (3.4, latest) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The webpack config was failing with "Cannot read properties of undefined (reading 'push')" because the SCSS rule might not exist or might not have a 'use' property in Shakapacker 9.3.0's generated config. Added proper guard check before attempting to push to the scss config's use array. Error was: TypeError: Cannot read properties of undefined (reading 'push') at commonWebpackConfig.js:27:59 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…rsions This commit fixes two issues that were causing generator tests to fail: 1. Version validation running during generator execution - The engine initializer was validating npm package installation - But generators hadn't installed packages yet (chicken-and-egg problem) - Solution: Skip validation when Rails generators are running 2. Package installed with semver range instead of exact version - package_json gem was adding packages with carets (^16.1.1) - React on Rails requires exact version matching between gem and npm package - Solution: Use npm install --save-exact directly for react-on-rails package Changes: - lib/react_on_rails/engine.rb: Skip validation during generator runs - lib/generators/react_on_rails/install_generator.rb: Use --save-exact flag Note: Filed issue with package_json gem to add exact version support: shakacode/package_json#25 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This comment explains React on Rails' use case for exact version support and provides context for why we had to implement a workaround. To be posted at: shakacode/package_json#25 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The HelloWorld.module.scss files were using $bright-color variable without importing the app-variables.scss file where it's defined. This was causing webpack build failures. Changes: - spec/dummy/client/app/components/HelloWorld.module.scss: Add @import - react_on_rails_pro/spec/dummy/client/app/components/HelloWorld.module.scss: Add @import - knip.ts: Auto-cleaned unused dependency ignores 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…n skip, and webpack safety This commit addresses three code review issues: 1. Fix package manager hard-coding (High Priority) - Add detect_package_manager_and_exact_flag helper to GeneratorHelper - Detect package manager from lock files (yarn, pnpm, bun, npm) - Update all package installation methods to use detected PM - Warn users when multiple lock files are detected - Fixes issue where npm was hard-coded, causing conflicts for yarn/pnpm/bun users 2. Fix fragile ARGV-based generator detection (Medium Priority) - Replace ARGV.any? check with explicit ENV variable - Install generator sets REACT_ON_RAILS_SKIP_VALIDATION=true - More robust than string matching on ARGV - Works correctly in all contexts (rake, console, tests) - Prevents false positives from paths containing "generate" or "g" 3. Add defensive checks to webpack CSS Modules config (Low Priority) - Add comprehensive type and existence checks before accessing loader properties - Prevents potential runtime errors with malformed webpack configs - Consistent with defensive pattern used for SCSS configuration All changes verified with: - bundle exec rubocop: 0 offenses - Install generator specs: 53 examples, 0 failures Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The version checker was failing during `rails generate react_on_rails:install` because it ran after package.json was created by shakapacker:install but before the generator had a chance to install the react-on-rails package. Error was: **ERROR** ReactOnRails: No React on Rails npm package is installed. This commit adds an additional check to skip validation if neither react-on-rails nor react-on-rails-pro package is found in package.json, allowing the generator to complete its installation process. The validation will still run normally once the packages are installed, ensuring version compatibility in production apps. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add .js extension to shakapacker/package/babel/preset import path. This is required for Shakapacker 9.3.0's package.json exports field to correctly resolve the module path. Fixes Jest test failures: - tests/react-on-rails.import.test.js - tests/react-on-rails.require.test.js 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The sass-resources-loader webpack plugin automatically injects app-variables.scss into all SCSS files, making manual @import statements redundant and potentially problematic. The previous fix attempted to import app-variables.scss to resolve undefined $bright-color variables, but this caused issues with React Server Components builds. The variables are already available through the webpack sass-resources-loader configuration. Changes: - spec/dummy/client/app/components/HelloWorld.module.scss: Remove @import - react_on_rails_pro/spec/dummy/client/app/components/HelloWorld.module.scss: Remove @import Fixes React Router Sixth Page RSC test failure. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Removed explicit .js extension from shakapacker preset import to comply
with ESLint's import/extensions rule.
Error was:
1:35 error Unexpected use of file extension "js" for
"shakapacker/package/babel/preset.js" import/extensions
Changed:
require('shakapacker/package/babel/preset.js')
To:
require('shakapacker/package/babel/preset')
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
…ssing require Addresses 3 critical issues identified in PR #1896 review: 1. Remove invalid javascript_transpiler configuration - Shakapacker 9.3.0 does not support a top-level javascript_transpiler key - Removed lines 39-42 from shakapacker.yml template - Transpiler selection is configured via webpack config and installed loaders 2. Update Pro package.json files to Shakapacker 9.3.0 - Updated react_on_rails_pro/spec/dummy/package.json (8.0.0 → 9.3.0) - Updated react_on_rails_pro/spec/execjs-compatible-dummy/package.json (8.0.0 → 9.3.0) - Added swc-loader and @swc/core dependencies to both files - Ensures version consistency across the codebase 3. Fix missing GeneratorMessages require in generator_helper.rb - Added require_relative "generator_messages" to prevent NameError - Issue occurred when detect_package_manager_and_exact_flag found multiple lock files - Now consistent with other generator files (base_generator.rb, install_generator.rb) All RuboCop checks pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add @import statement to HelloWorld.module.scss files to import app-variables.scss which defines $bright-color variable. This fixes the "Undefined variable" SCSS compilation error during webpack builds. Fixed in both: - spec/dummy/client/app/components/HelloWorld.module.scss - react_on_rails_pro/spec/dummy/client/app/components/HelloWorld.module.scss 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…files These are build-time tools and should be in devDependencies, not dependencies. Changes: - react_on_rails_pro/spec/dummy/package.json: Moved @swc/core and swc-loader to devDependencies - react_on_rails_pro/spec/execjs-compatible-dummy/package.json: Moved @swc/core and swc-loader to devDependencies Both entries maintain the same version strings (^1.7.0 and ^0.2.6). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Shakapacker is a build-time tool and should be in devDependencies, not dependencies. Changed in react_on_rails_pro/spec/dummy/package.json: - Removed "shakapacker": "9.3.0" from dependencies - Added "shakapacker": "9.3.0" to devDependencies This completes the correct categorization of all build-time tools (@swc/core, swc-loader, and shakapacker) as devDependencies. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
… extension The shakapacker babel preset requires the explicit .js extension in the require statement for Jest/Babel to resolve it correctly. Without the extension, Jest fails with "Cannot find module" error. Changes: - Restored .js extension in spec/dummy/babel.config.js - Added eslint-disable-next-line comment to suppress import/extensions rule Error fixed: Cannot find module '/path/to/shakapacker/package/babel/preset' at babel.config.js:1:27 This is a special case where the .js extension is required for module resolution in the Babel/Jest context, even though ESLint normally discourages it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Change the build.prepack script to use 'yarn run build' instead of 'npm run build'. In a yarn workspace, using npm to run scripts that depend on workspace features (like 'yarn workspace react-on-rails run build') causes build failures. This fixes the yalc package publishing failures in CI where the prepack script would fail silently, resulting in packages being published without the built files, leading to downstream errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1. Revert package-scripts.yml change (npm->yarn) - This file doesn't exist on master, so the change shouldn't be included 2. Add javascript_compiler setting to shakapacker.yml template - Adds configuration option to choose between 'babel' or 'swc' - Defaults to 'babel' for wider ecosystem support - Documents the tradeoffs between the two compilers 3. Fix swc/babel dependency management - Move swc packages (@swc/core, swc-loader) from devDependencies to dependencies - Make swc and babel mutually exclusive based on shakapacker.yml setting - Add using_swc? helper method to check javascript_compiler configuration - When using swc, install swc packages instead of babel packages This ensures proper dependency installation based on the chosen JavaScript compiler. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
When bin/dev loads bundler/setup and then PackGenerator tries to run "bundle exec rake", it fails due to Bundler path conflicts. The system command tries to spawn a new bundle process from within an already-setup Bundler environment, causing Ruby/Bundler version mismatches. Solution: Detect if we're already in a Bundler context and directly invoke the Rake task instead of shelling out to "bundle exec rake". This avoids the nested Bundler issue while maintaining compatibility with non-Bundler environments. Changes: - lib/react_on_rails/dev/pack_generator.rb: - Add run_pack_generation method to detect Bundler context - Add run_rake_task_directly to invoke Rake task in-process - Add run_via_bundle_exec for non-Bundler environments - Load Rails environment when needed for in-process execution Fixes: bin/dev static (and other bin/dev commands) now successfully generate packs before starting the development server. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
When bin/dev starts, webpack immediately tries to build bundles that import ReScript components (HelloWorldReScript.res.js). However, these .res.js files are generated by the ReScript compiler from .res source files, and webpack fails if they don't exist yet. Solution: Build ReScript files before starting the Procfile processes. This ensures all .res.js files are generated before webpack starts. Changes: - lib/react_on_rails/dev/server_manager.rb: - Add build_rescript_if_needed method to compile ReScript before dev server - Check for both bsconfig.json (old) and rescript.json (new) config files - Run yarn build:rescript if ReScript is configured - Exit with error if ReScript build fails Fixes webpack Module not found errors for HelloWorldReScript.res.js 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Implement explicit yalc publishing before yarn install to avoid frozen-lockfile conflicts. This resolves the issue where preinstall scripts triggered yalc operations that modified yarn.lock, causing CI to fail with "--frozen-lockfile" checks. Changes: 1. Add explicit "Build and publish packages with yalc" step that runs yarn run yalc:publish for both root and Pro packages before install 2. Add --ignore-scripts flag to Pro dummy app yarn install to skip preinstall hook (since yalc already published in previous step) 3. Apply to all 3 jobs: build, rspec, and playwright tests This approach: - Separates build/publish from install for better CI reproducibility - Prevents yarn.lock modifications during install - Maintains frozen-lockfile enforcement for dependency stability - Faster CI (no redundant builds during preinstall) The preinstall script remains useful for local development to auto-update yalc packages, but in CI we use explicit steps for better control. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
When navigating between pages with Turbo, JavaScript wasn't being re-initialized because the layout was using old Turbolinks data attributes instead of Turbo attributes. Changes: - spec/dummy/app/views/layouts/application.html.erb: - Change data-turbolinks-track to data-turbo-track="reload" - Add defer: true to ensure proper script loading order with Turbo This ensures React components properly hydrate on Turbo navigation, not just on hard refresh. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
… regression Documents a regression that existed for over 1 year where JavaScript failed to work after Turbo navigation (only worked on hard refresh). This issue provides a comprehensive plan for adding Playwright E2E tests to prevent this type of regression in the future. The issue includes: - Background on what happened and when the bug was introduced (PR #1620) - Impact on users (broken JS after navigation) - Proposed Playwright test implementation - Verification steps to prove the test catches the regression - Additional test cases to consider - Success criteria and implementation checklist To verify Playwright is working correctly, developers can: 1. Run the test with the current fix (should pass) 2. Revert the fix in application.html.erb (should fail) 3. Restore the fix (should pass again) This proves the test effectively catches Turbo navigation issues. Related commits: - Bug introduced: 56ee2bd (PR #1620, ~1 year ago) - Bug fixed: f03b935 (this PR) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Change 'yarn run yalc:publish' to 'yarn && yalc publish' for the react_on_rails_pro package, since it doesn't have a yalc:publish script defined (only the workspace packages do). The workflow now: 1. Runs yarn run yalc:publish at root (publishes workspace packages) 2. Runs yarn && yalc publish in react_on_rails_pro (installs + publishes Pro) This matches the command structure used in the preinstall script. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The build.prepack script in package-scripts.yml was using `npm run build` which causes failures in CI. This is inconsistent with the rest of the codebase which uses yarn. Changed line 29 from: (npm run build >/dev/null 2>&1 || true) To: (yarn run build >/dev/null 2>&1 || true) This matches the fix previously made in packages/react-on-rails/package.json (commit 9f254fb) but was missed in the root package-scripts.yml file. Fixes CI error: Building react-on-rails seems to have failed! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Added 'tree' as the language identifier for the fenced code block showing the file structure, changing from generic ``` to ```tree for better syntax highlighting and clarity. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The yalc workflow modifies yarn.lock when adding packages, so we cannot use --frozen-lockfile after yalc has run. Keep --ignore-scripts to skip the preinstall hook (since yalc already ran in the previous step). This allows the install to succeed after yalc has modified the lockfile. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Updated shakapacker gem version from 8.0.0 to 9.3.0 in Pro Gemfiles to match
the package.json changes, fixing the version mismatch error:
"Shakapacker gem and node package versions do not match
Detected: 9.3.0
gem: 8.0.0"
Changed in:
- react_on_rails_pro/Gemfile.development_dependencies (8.0.0 → 9.3.0)
- react_on_rails_pro/spec/execjs-compatible-dummy/Gemfile (8.0 → 9.3.0)
This ensures gem and npm package versions match across all Pro dummy apps.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Updated yarn.lock to match package.json changes for @swc/core and swc-loader dependencies moved to devDependencies. Fixes CI lint-js-and-ruby failure: "Your lockfile needs to be updated, but yarn was run with --frozen-lockfile" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Updated yarn.lock to match package.json changes for @swc/core and swc-loader dependencies moved to devDependencies in the execjs-compatible-dummy app. Fixes CI lint-js-and-ruby failure for ExecJS dummy app: "Your lockfile needs to be updated, but yarn was run with --frozen-lockfile" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Applied the same fix as spec/dummy to prevent webpack config error when scss rule is not found in Shakapacker 9.3.0's generated config. Added guard check before attempting to push to the scss config's use array. Fixes build-dummy-app-webpack-test-bundles failure: TypeError: Cannot read properties of undefined (reading 'push') at commonWebpackConfig.js:32 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Shakapacker 9.3.0 defaults to SWC compiler if javascript_compiler is not explicitly set in shakapacker.yml. Update the using_swc? method to reflect this new default behavior. Changes: - using_swc? now returns true (SWC) by default when config doesn't exist - using_swc? returns true unless javascript_compiler is explicitly set to babel - Updated template shakapacker.yml to comment out javascript_compiler setting - Added clear documentation that Shakapacker 9.3.0+ defaults to SWC This ensures the generator correctly detects and installs SWC dependencies by default, matching Shakapacker 9.3.0's new default compiler. Addresses PR review comment on lib/generators/react_on_rails/base_generator.rb:225 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Change using_swc? helper to parse shakapacker.yml with YAML.safe_load_file instead of raw string matching, which incorrectly interpreted commented lines as active configuration. Changes: - Add require "yaml" to base_generator.rb - Parse YAML to read javascript_compiler from default section - Return true only when javascript_compiler is explicitly set to "swc" - Default to false (babel) when file is missing or key is absent - Add error handling for YAML parsing failures - Update template comment to reflect babel as default This ensures commented configuration lines don't affect compiler detection and provides more predictable behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Critical fixes: 1. using_swc? already properly parses YAML (no changes needed) 2. Make precompile hook cross-platform: - Replace Unix-specific `command -v` with Ruby's system() array form - Use File::NULL for cross-platform output redirection - Use array form of system() calls for better reliability 3. Fix fragile config detection in precompile hook: - Use regex to match only actual config assignments - Ignore comments and strings containing config names 4. Remove development documentation files: - ISSUE_ANALYSIS.md - PR_REVIEW_RESPONSE.md - package_json_issue_comment.md 5. Fix Rake task management: - Remove Rake::Task.clear (was clearing ALL tasks, not just ours) - Add task.reenable to support multiple invocations These changes improve cross-platform compatibility (Windows support), prevent false positives in config detection, and fix rake task issues. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Per code review feedback: - Remove precompile_hook from template shakapacker.yml - Remove javascript_compiler config from template shakapacker.yml - Remove bin/shakapacker-precompile-hook from generator templates These features are development/testing-specific and should not be in the default generator templates. They remain in spec/dummy for testing purposes only. Addresses review comments: https://github.com/shakacode/react_on_rails/pull/1896/files#r2489115925 https://github.com/shakacode/react_on_rails/pull/1896/files#r2489114681 https://github.com/shakacode/react_on_rails/pull/1896/files#r2489120422
…redirection Change run_via_bundle_exec method to use array form of system() instead of string form with shell redirection: - Silent mode: Use File::NULL for stdout/stderr redirection (cross-platform) - Non-silent mode: Use array form to avoid shell interpretation Benefits: - Cross-platform compatibility (Windows support) - Avoids shell injection vulnerabilities - No reliance on Unix-specific shell redirection (> /dev/null 2>&1) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add find_rails_root helper that walks upward from current directory looking for config/environment.rb to locate the Rails root, instead of assuming the current working directory is the Rails root. Changes: - Add find_rails_root() method that searches parent directories - Returns nil if Rails root cannot be found (reaches filesystem root) - Update generate_packs_if_needed to use Rails root for all paths - Build absolute path to config/initializers/react_on_rails.rb Benefits: - Works regardless of current working directory - More robust when hook is called from subdirectories - Gracefully handles non-Rails environments 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Remove unreachable Rails environment loading code that was guarded by 'unless defined?(Rails)'. This guard is dead code because: 1. run_rake_task_directly is only called when rails_available? is true 2. rails_available? explicitly checks defined?(Rails) and returns false if Rails is not defined 3. Therefore Rails is always defined when this method executes The removed line attempted to load config/environment using Dir.pwd, which was both unreachable and used the wrong path resolution method. Since Rails is guaranteed to be available in this context, we can rely on Rails.application.load_tasks directly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add React 'use client' directive to RSCProvider.tsx to ensure this component is treated as a client component in React Server Components architecture. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Reverted the array-form system calls back to string form to match the test expectations in pack_generator_spec.rb. This change (commit dabb298) was unrelated to the Shakapacker 9.3.0 upgrade and broke 3 tests: - runs pack generation successfully in verbose mode - runs pack generation successfully in quiet mode - exits with error when pack generation fails The tests expect the old string-based format: system "bundle exec rake react_on_rails:generate_packs" Addresses review comment from @justin808 about unrelated changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…er.tsx files Files ending with .server.tsx are intended for server-side rendering and should not have the 'use client' directive. This directive causes webpack to bundle these files as client components, which leads to errors when React 19's server exports don't include client-only APIs like createContext, useContext, and Component. This fixes CI errors: - export 'createContext' was not found in 'react' - export 'useContext' was not found in 'react' - export 'Component' was not found in 'react' 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…ovider and RSCRoute Remove 'use client' directives from RSCProvider.tsx and RSCRoute.tsx to fix webpack compilation errors when these files are included in server bundles. In React 19, the server build doesn't export client-only APIs like createContext, useContext, and Component. When files with 'use client' are bundled into server bundles, webpack fails with "export not found" errors. The solution is to remove 'use client' from library files that need to work in both server and client contexts. The 'use client' boundary should be established in consuming components, not in the library files themselves. Also update import style to use ReactClient from 'react/index.js' for better compatibility with React 19's dual package structure. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add custom ESLint rule no-use-client-in-server-files to catch and prevent 'use client' directives in .server.tsx files, which causes React 19 server bundle compilation errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Update Capybara to >= 3.40 for Rack 3 compatibility - Fix generator to inject shakapacker 9.3.0 instead of >= 0 - Allow Ruby >= 3.0.0, < 3.5.0 in execjs-compatible-dummy These changes fix test failures caused by Rack::Handler removal in Rack 3 and bundler conflicts from shakapacker version mismatches during generator tests. 🤖 Generated with [Claude Code](https://claude.com/claude.code) Co-Authored-By: Claude <[email protected]>
These were temporary files used to test the ESLint rule and should not have been committed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This change leverages Shakapacker's new precompile_hook feature to automatically generate packs before webpack compilation, replacing the need to manually modify assets:precompile tasks or bin/dev scripts. Changes: - Add bin/shakapacker-precompile-hook script to templates and spec/dummy - Update shakapacker.yml to configure precompile_hook - Add PackerUtils.shakapacker_precompile_hook_configured? method - Skip generate_packs in configuration and PackGenerator when hook configured - Update generator to copy hook script and make it executable The precompile hook runs before webpack compilation and is properly validated by Shakapacker to ensure it points to a file within the project root. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code Review - PR #1905: Add Shakapacker precompile hook supportSummaryThis PR successfully implements integration with Shakapacker's precompile hook feature to automatically generate packs before webpack compilation. The implementation is clean, well-structured, and follows the repository's conventions. ✅ Strengths
🔍 Potential Issues & Suggestions1. Missing Test Coverage (High Priority)The new Recommendation: Add tests to describe ".shakapacker_precompile_hook_configured?" do
let(:mock_config) { instance_double("Shakapacker::Config") }
before do
allow(::Shakapacker).to receive(:config).and_return(mock_config)
end
it "returns true when precompile_hook is configured" do
allow(mock_config).to receive(:send).with(:data).and_return({ precompile_hook: 'bin/shakapacker-precompile-hook' })
expect(described_class.shakapacker_precompile_hook_configured?).to be(true)
end
it "returns false when precompile_hook is nil" do
allow(mock_config).to receive(:send).with(:data).and_return({ precompile_hook: nil })
expect(described_class.shakapacker_precompile_hook_configured?).to be(false)
end
it "returns false when precompile_hook is empty string" do
allow(mock_config).to receive(:send).with(:data).and_return({ precompile_hook: '' })
expect(described_class.shakapacker_precompile_hook_configured?).to be(false)
end
it "returns false when Shakapacker is not defined" do
hide_const("::Shakapacker")
expect(described_class.shakapacker_precompile_hook_configured?).to be(false)
end
it "returns false on StandardError" do
allow(mock_config).to receive(:send).and_raise(StandardError.new("test error"))
expect(described_class.shakapacker_precompile_hook_configured?).to be(false)
end
end2. Private Method Access (Medium Priority)
Concerns:
Recommendation: Consider alternatives:
3. Rainbow Dependency (Low Priority)The hook script template ( Recommendation: Add graceful fallback: def colorize(text, color)
defined?(Rainbow) ? Rainbow(text).send(color) : text
end
puts colorize("🔄 Running React on Rails precompile hook...", :cyan)4. File Permission Check Timing (Low Priority)
Recommendation: Consider adding the shebang's execute bit to the source file in the repo, then the chmod becomes defensive rather than required. 📊 Performance Considerations
🔒 Security Review✅ The PR description correctly notes that Shakapacker validates the hook script is within project root, preventing path traversal attacks. 📝 Code Quality
🎯 Recommendations PriorityBefore Merge:
Consider for Follow-up: Overall AssessmentThis is a well-implemented feature that elegantly integrates with Shakapacker's hook system. The main gap is test coverage for the new detection method. Once tests are added, this will be ready to merge. 🤖 Generated with Claude Code |
f86c684 to
843f1f7
Compare
Summary
This PR leverages Shakapacker's new
precompile_hookfeature to automatically generate packs before webpack compilation, replacing the need to manually modify assets:precompile tasks or bin/dev scripts.Base branch:
justin808/shakapacker-9.3.0(to be merged after that PR is merged to master)Changes
PackerUtils.shakapacker_precompile_hook_configured?method to detect when hook is configuredconfiguration.rbto skip generate_packs when hook is configuredPackGeneratorto skip pack generation when hook is configuredServerManagerto avoid redundant pack generation in bin/devbin/shakapacker-precompile-hookscript template for generatorshakapacker.ymltemplates to configureprecompile_hookBenefits
Note on spec/dummy/bin/shakapacker-precompile-hook
The shakapacker-9.3.0 branch already has a comprehensive precompile hook that includes ReScript support and cross-platform compatibility. This PR adds the React on Rails specific logic to work with that existing hook infrastructure.
Test plan
🤖 Generated with Claude Code
This change is