Skip to content

Fix resolve_hook_script_path to work without Rails.root#2568

Merged
justin808 merged 4 commits intomasterfrom
ihabadham/fix/resolve-hook-without-rails-root
Mar 8, 2026
Merged

Fix resolve_hook_script_path to work without Rails.root#2568
justin808 merged 4 commits intomasterfrom
ihabadham/fix/resolve-hook-without-rails-root

Conversation

@ihabadham
Copy link
Copy Markdown
Collaborator

@ihabadham ihabadham commented Mar 8, 2026

Summary

  • Adds project_root helper that resolves the project root without requiring Rails.root
  • Falls back to BUNDLE_GEMFILE dirname (reliable — always set after require "bundler/setup") then Dir.pwd
  • resolve_hook_script_path now uses project_root instead of hard-requiring Rails.root

Related to #2438 — addresses the hook detection root cause (hook not running from bin/dev context), though the exact symptom reported in that issue (pack generation failure) could not be reproduced.

Problem

resolve_hook_script_path returned nil whenever Rails.root wasn't available (e.g., from bin/dev which intentionally skips loading Rails for startup speed). This caused hook_configured? to return false even when the precompile hook was correctly configured in shakapacker.yml, leading to redundant pack generation after the hook already ran.

Companion PR

This works together with shakacode/shakapacker#963, which fixes Shakapacker::Env#current to resolve the environment from RAILS_ENV/RACK_ENV env vars when Rails isn't loaded. Together, these two fixes address the bin/dev hook detection issue.

With both fixes applied, bin/dev output shows the correct flow:

🔧 Running Shakapacker precompile hook...
   Command: bin/shakapacker-precompile-hook
✅ Precompile hook completed successfully
⏭️  Skipping pack generation (handled by shakapacker precompile hook: bin/shakapacker-precompile-hook)

Supersedes #2561

PR #2561 worked around the Shakapacker Env#current bug by re-implementing YAML config parsing. With the Shakapacker fix in place, that workaround is no longer needed — this PR provides only the minimal resolve_hook_script_path fix that was still necessary.

Test plan

  • Verified hook_configured? returns true from non-Rails context (test app with both fixes)
  • Verified bin/dev runs hook and skips redundant pack generation
  • Verified BUNDLE_GEMFILE correctly resolves project root even when Dir.pwd differs

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements

    • More robust project-root detection: falls back from Rails to Gemfile directory to current working directory for clearer path resolution across environments.
    • Improved hook-script detection and reporting, with better handling of self-guard patterns.
  • Tests

    • Added tests covering project-root detection with Rails present/absent and various Gemfile scenarios.

resolve_hook_script_path required Rails.root to resolve hook script
paths, returning nil in bin/dev context where Rails isn't loaded. This
caused hook_configured? to return false even when the hook was properly
configured, leading to redundant pack generation after the hook already
ran.

Add project_root helper that falls back to BUNDLE_GEMFILE dirname (set
by Bundler during require "bundler/setup") or Dir.pwd when Rails.root
is unavailable.

Companion to shakacode/shakapacker#963 which fixes Shakapacker::Env to
work without Rails. Together these two fixes fully resolve #2438 without
the YAML-parsing workaround in #2561.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 11891f1e-4645-4af1-b649-e790b97c1ed6

📥 Commits

Reviewing files that changed from the base of the PR and between 5f04527 and 9a710bf.

📒 Files selected for processing (1)
  • react_on_rails/spec/react_on_rails/packer_utils_spec.rb

Walkthrough

Adds Pathname support and a project_root resolver (prefers Rails.root, then Bundler's Gemfile dir, then Dir.pwd), updates hook path resolution to use project_root and short-circuit blank inputs, and introduces public helpers project_root, hook_script_has_self_guard?, and shakapacker_precompile_hook_value. Tests for project_root added.

Changes

Cohort / File(s) Summary
Packer Utils refactor & helpers
react_on_rails/lib/react_on_rails/packer_utils.rb
Require pathname. Add self.project_root to resolve base path (Rails.root → dirname of BUNDLE_GEMFILEDir.pwd). Use project_root for hook path resolution and short-circuit blank hook inputs. Add hook_script_has_self_guard? and shakapacker_precompile_hook_value.
Specs — project_root tests
react_on_rails/spec/react_on_rails/packer_utils_spec.rb
Add tests covering project_root behavior for Rails-defined root, Bundler Gemfile dirname fallback, and Dir.pwd fallback. (Duplicate test blocks present.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I tap each root with twitchy nose and ear,
Rails, Gemfile, or cwd — I sniff them clear.
I guard the hooks and find the script's way,
A tiny hop to tidy up the day. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main objective: refactoring resolve_hook_script_path to work without requiring Rails.root by introducing a project_root fallback mechanism.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ihabadham/fix/resolve-hook-without-rails-root

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread react_on_rails/lib/react_on_rails/packer_utils.rb Outdated
Comment thread react_on_rails/lib/react_on_rails/packer_utils.rb
Comment thread react_on_rails/lib/react_on_rails/packer_utils.rb
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Mar 8, 2026

Review

The fix is correct and well-scoped. resolve_hook_script_path previously short-circuited entirely when Rails was not loaded, so the fallback chain in project_root is exactly the right approach.

Minor nits (inline):

  • Pathname.new(Rails.root) is redundant — Rails.root is already a Pathname.
  • ENV.fetch("BUNDLE_GEMFILE", nil) can be simplified to ENV["BUNDLE_GEMFILE"].

More significant gap — test coverage:
The new project_root method has two fallback branches (BUNDLE_GEMFILE and Dir.pwd) that are not exercised by any spec. The existing tests for the script-file path scenario all stub Rails.root, so only the first branch is implicitly covered. A describe ".project_root" block covering all three branches would prevent silent regressions and document the intended priority order.

One edge case to be aware of:
BUNDLE_GEMFILE can be set to a relative path (e.g. Gemfile with no directory component). expand_path handles that correctly relative to Dir.pwd, so the current code is safe — but it is worth a comment since the behaviour is non-obvious.

Overall the approach is solid and the dependency on the companion shakapacker PR is clearly documented.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Mar 8, 2026

Greptile Summary

This PR fixes resolve_hook_script_path to work in non-Rails contexts (e.g., bin/dev) by extracting a new project_root helper that falls back from Rails.rootBUNDLE_GEMFILE dirname → Dir.pwd. The approach is sound and solves the described bin/dev hook-detection problem, but there is one logic-level regression introduced by unnecessarily wrapping Rails.root in Pathname.new().

Key changes:

  • New project_root method with a three-tier fallback for resolving the project directory without requiring Rails.
  • resolve_hook_script_path now uses project_root instead of bailing out early when Rails is absent.
  • require "pathname" added to make Pathname explicit.

Issues found:

  • Pathname.new(Rails.root) on line 238 is redundant (Rails.root is already a Pathname) and will break existing specs that mock Rails.root as an instance_double(Pathname) — calling Pathname.new on that double triggers an unstubbed to_path call, raising RSpec::Mocks::MockExpectationError in the test suite.
  • No automated tests cover the new BUNDLE_GEMFILE or Dir.pwd fallback branches of project_root.

Confidence Score: 3/5

  • The runtime fix is correct and minimal, but Pathname.new(Rails.root) will cause existing spec failures and the new fallback logic is untested.
  • The overall design is correct and the fallback chain is sensible. The score is reduced because the Pathname.new(Rails.root) wrapper is expected to break existing RSpec tests (the double's to_path method is called but never stubbed), and no new tests cover the critical BUNDLE_GEMFILE/Dir.pwd code paths that are the primary motivation of the PR.
  • react_on_rails/lib/react_on_rails/packer_utils.rb — specifically the project_root method and its interaction with the existing test doubles in packer_utils_spec.rb.

Important Files Changed

Filename Overview
react_on_rails/lib/react_on_rails/packer_utils.rb Adds project_root helper with Rails/BUNDLE_GEMFILE/Dir.pwd fallbacks and updates resolve_hook_script_path to use it; the logic is sound but Pathname.new(Rails.root) breaks existing specs that mock rails_root as an instance_double(Pathname).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["resolve_hook_script_path(hook_value)"] --> B{hook_value blank?}
    B -- yes --> C[return nil]
    B -- no --> D["project_root.join(hook_value.strip)"]
    D --> E["project_root()"]
    E --> F{Rails defined\n& Rails.root truthy?}
    F -- yes --> G["Pathname.new(Rails.root) ⚠️\n(redundant wrap — Rails.root\nalready returns a Pathname)"]
    F -- no --> H{BUNDLE_GEMFILE\nenv var set & non-blank?}
    H -- yes --> I["Pathname.new(BUNDLE_GEMFILE).expand_path"]
    I --> J{File exists?}
    J -- yes --> K[return gemfile_path.dirname]
    J -- no --> L["Pathname.new(Dir.pwd)"]
    H -- no --> L
    G --> M[potential_path]
    K --> M
    L --> M
    M --> N{potential_path.file?}
    N -- yes --> O[return potential_path]
    N -- no --> C
Loading

Last reviewed commit: f9f0115

Comment thread react_on_rails/lib/react_on_rails/packer_utils.rb Outdated
Comment thread react_on_rails/lib/react_on_rails/packer_utils.rb
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
react_on_rails/lib/react_on_rails/packer_utils.rb (1)

237-246: Add regression specs for the new non-Rails fallbacks.

This is the core fix, but the provided packer_utils_spec coverage only exercises the Rails.root.join(...) branch. Please lock down both the BUNDLE_GEMFILE and Dir.pwd paths so this behavior does not silently regress.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@react_on_rails/lib/react_on_rails/packer_utils.rb` around lines 237 - 246,
Add regression specs for ReactOnRails::PackerUtils.project_root that cover the
two non-Rails fallbacks: (1) when ENV["BUNDLE_GEMFILE"] is set to a valid
Gemfile path, assert project_root returns the Gemfile's directory by creating a
temporary Gemfile, setting ENV["BUNDLE_GEMFILE"] to its path, undefining or
stubbing Rails/root, and calling project_root; and (2) when no Rails.root and no
BUNDLE_GEMFILE, assert project_root returns Pathname.new(Dir.pwd) by clearing
ENV["BUNDLE_GEMFILE"], ensuring Rails is not present or has no root, calling
project_root, and comparing to Pathname.new(Dir.pwd). Remember to restore ENV
and any Rails constant/state after each example to avoid test leakage.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@react_on_rails/lib/react_on_rails/packer_utils.rb`:
- Around line 237-246: Add regression specs for
ReactOnRails::PackerUtils.project_root that cover the two non-Rails fallbacks:
(1) when ENV["BUNDLE_GEMFILE"] is set to a valid Gemfile path, assert
project_root returns the Gemfile's directory by creating a temporary Gemfile,
setting ENV["BUNDLE_GEMFILE"] to its path, undefining or stubbing Rails/root,
and calling project_root; and (2) when no Rails.root and no BUNDLE_GEMFILE,
assert project_root returns Pathname.new(Dir.pwd) by clearing
ENV["BUNDLE_GEMFILE"], ensuring Rails is not present or has no root, calling
project_root, and comparing to Pathname.new(Dir.pwd). Remember to restore ENV
and any Rails constant/state after each example to avoid test leakage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2a4ddadf-f3cd-4b41-b741-17a4638325ad

📥 Commits

Reviewing files that changed from the base of the PR and between 61b1f49 and f9f0115.

📒 Files selected for processing (1)
  • react_on_rails/lib/react_on_rails/packer_utils.rb

Rails.root already returns a Pathname, so wrapping it in Pathname.new()
caused instance_double(Pathname) in specs to fail on unstubbed to_path.

Added unit tests for all three project_root branches: Rails.root,
BUNDLE_GEMFILE dirname, and Dir.pwd fallback.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Comment thread react_on_rails/spec/react_on_rails/packer_utils_spec.rb
Comment thread react_on_rails/spec/react_on_rails/packer_utils_spec.rb
Comment thread react_on_rails/spec/react_on_rails/packer_utils_spec.rb
Comment thread react_on_rails/lib/react_on_rails/packer_utils.rb
Comment thread react_on_rails/lib/react_on_rails/packer_utils.rb
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Mar 8, 2026

Review Summary

The fix is conceptually correct and well-motivated — using BUNDLE_GEMFILE as a fallback for Rails.root is a sound approach since Bundler guarantees it is set after require "bundler/setup". The project_root implementation logic is clean. A few issues need attention before merging:

Critical: Test stubs do not match the implementation

All three new tests under "when Rails is not defined" stub ENV.[] via allow(ENV).to receive(:[]), but the implementation calls ENV.fetch("BUNDLE_GEMFILE", nil). In MRI Ruby, ENV.fetch and ENV.[] are separate methods — RSpec stubs on [] do not intercept fetch. In a real CI run, BUNDLE_GEMFILE is always set by Bundler, so:

  • The "valid file" test will use the real Gemfile path instead of __FILE__, producing a wrong expected_dir.
  • The "not set" and "non-existent file" tests will find the real, valid BUNDLE_GEMFILE, so project_root returns the Gemfile directory instead of Dir.pwd — both assertions fail.

The simplest fix is to change the implementation to use ENV["BUNDLE_GEMFILE"] (functionally identical; nil default is the same), which matches the stub style already used throughout the spec. Alternatively, change all three stubs to allow(ENV).to receive(:fetch).with("BUNDLE_GEMFILE", nil). See inline comments for suggested diffs.

Missing higher-level test coverage

The new specs test the project_root helper directly, but there is no spec for resolve_hook_script_path exercising the non-Rails path. A test that verifies "resolves a hook path relative to BUNDLE_GEMFILE dirname when Rails is not loaded" would give more confidence that the actual public-facing fix works end-to-end and would survive a future refactor of project_root.

project_root visibility

project_root is only called internally by resolve_hook_script_path. Leaving it as a public class method makes it an accidental part of the module's API surface. Consider private_class_method :project_root to signal it is an internal helper and to hint that behaviour should be tested through resolve_hook_script_path, not the helper directly.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@react_on_rails/spec/react_on_rails/packer_utils_spec.rb`:
- Around line 357-377: The tests are stubbing ENV.[] but the code calls
ENV.fetch("BUNDLE_GEMFILE", nil), so update the specs around the project_root
examples to stub ENV.fetch instead of ENV.[]; use allow(ENV).to
receive(:fetch).and_call_original and then override .with("BUNDLE_GEMFILE",
nil).and_return(__FILE__) for the valid-file case, .and_return(nil) for the "not
set" case, and .and_return("/non/existent/Gemfile") for the non-existent-file
case so the project_root expectations exercise the intended branches.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e6096592-08bf-4ec8-b835-f4145f514cb8

📥 Commits

Reviewing files that changed from the base of the PR and between f9f0115 and a658da1.

📒 Files selected for processing (2)
  • react_on_rails/lib/react_on_rails/packer_utils.rb
  • react_on_rails/spec/react_on_rails/packer_utils_spec.rb

Comment thread react_on_rails/spec/react_on_rails/packer_utils_spec.rb
The implementation uses ENV.fetch("BUNDLE_GEMFILE", nil) but tests
stubbed ENV.[]. In MRI Ruby these are separate methods — the stub
didn't intercept fetch, causing the "valid file" test to fail.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Mar 8, 2026

PR Review: Fix resolve_hook_script_path to work without Rails.root

Overall this is a well-motivated and correctly-scoped fix. The fallback chain (Rails.root → BUNDLE_GEMFILE → Dir.pwd) is a sound approach. A few things worth addressing:

1. Missing test: Rails.root returns nil/falsy

The project_root guard handles the case where Rails.root is nil (e.g., during engine initialization before Rails is fully booted). However, there is no spec for this — the test suite only covers Rails being fully defined with a valid root, or Rails being absent entirely. A spec where Rails.root returns nil would prevent regressions.

2. resolve_hook_script_path behavior change is undocumented

The old comment (Hook value might be a script path relative to Rails root) has been removed without replacement. A short note explaining the project_root fallback chain would help future readers understand why Rails is no longer required.

3. project_root visibility

project_root is a module-level self. method and becomes part of the public API. If it is only intended as an internal helper, consider private_class_method :project_root to prevent unintended external use.

Positive notes

  • The fallback chain is correct and well-ordered.
  • Tests cover the three main branches of project_root.
  • expand_path on BUNDLE_GEMFILE is the right defensive move.
  • Keeping the change minimal (no YAML re-implementation) is the right call given the companion Shakapacker fix.

Comment thread react_on_rails/lib/react_on_rails/packer_utils.rb
Comment thread react_on_rails/lib/react_on_rails/packer_utils.rb
Comment thread react_on_rails/spec/react_on_rails/packer_utils_spec.rb
stub_const("ENV", ENV.to_h.merge(...)) replaces the entire ENV object,
so all access methods ([], fetch, key?) work consistently. This avoids
coupling tests to the specific ENV method the implementation uses.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Comment thread react_on_rails/lib/react_on_rails/packer_utils.rb
Comment thread react_on_rails/lib/react_on_rails/packer_utils.rb
Comment thread react_on_rails/spec/react_on_rails/packer_utils_spec.rb
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@react_on_rails/spec/react_on_rails/packer_utils_spec.rb`:
- Around line 357-363: The test for the BUNDLE_GEMFILE branch can accidentally
pass if Dir.pwd equals Pathname.new(__FILE__).expand_path.dirname; update the
example so it forces a different current working directory before calling
described_class.project_root (e.g., stub Dir.pwd or Dir.getwd to return a path
different from expected_dir) while still stubbing ENV.fetch("BUNDLE_GEMFILE",
nil) to __FILE__, ensuring project_root must use the BUNDLE_GEMFILE dirname
branch; reference the BUNDLE_GEMFILE stub and the described_class.project_root
call when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4c03d671-4500-43e3-9f4d-ce65931d2bed

📥 Commits

Reviewing files that changed from the base of the PR and between a658da1 and 5f04527.

📒 Files selected for processing (1)
  • react_on_rails/spec/react_on_rails/packer_utils_spec.rb

Comment thread react_on_rails/spec/react_on_rails/packer_utils_spec.rb
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Mar 8, 2026

Review

The approach is sound — removing the hard Rails.root dependency from resolve_hook_script_path via a dedicated project_root helper with a sensible fallback chain is the right fix. The companion Shakapacker PR makes this complete.

Minor issues:

  1. project_root visibility (see inline): It's an internal helper and could be marked private_class_method to avoid leaking it into the public API surface.

  2. Dir.pwd fallback is silent (see inline): If the fallback fires with the wrong directory, resolve_hook_script_path silently returns nil and the hook is treated as unconfigured. A warning log would make this much easier to diagnose.

  3. Missing integration test for the core fix (see inline): project_root is well-tested in isolation, but there's no spec for resolve_hook_script_path in a non-Rails context — which is the exact scenario this PR is designed to fix. Adding that test would ensure the fix stays covered under refactoring.

Otherwise the implementation is clean, the commit history tells a clear story, and the test structure for project_root is thorough.

@justin808 justin808 merged commit df6fc24 into master Mar 8, 2026
40 checks passed
@justin808 justin808 deleted the ihabadham/fix/resolve-hook-without-rails-root branch March 8, 2026 23:45
justin808 added a commit that referenced this pull request Mar 9, 2026
Add entries for user-visible changes since v16.4.0.rc.6:
- #2539: env-var-driven ports in Procfile templates
- #2417: rspack generator config path fix
- #2419: precompile hook load-based execution fix
- #2577: create-react-on-rails-app validation improvements
- #2416: StreamResponse status fallback fix (Pro)
- #2566: empty-string license plan mismatch fix (Pro)
- Updated #2561 entry to include #2568 contributor credit

Co-Authored-By: Claude Opus 4.6 <[email protected]>
justin808 added a commit that referenced this pull request Mar 9, 2026
## Summary

- Add changelog entries for 6 user-visible PRs merged since v16.4.0.rc.6
that were missing from `[Unreleased]`
- Update existing #2561 entry to include #2568 contributor credit

### New entries added

| Section | PR | Description |
|---|---|---|
| Added | #2539 | Environment-variable-driven ports in Procfile
templates |
| Fixed | #2417 | Rspack generator config path fix |
| Fixed | #2419 | Precompile hook load-based execution fix |
| Fixed | #2577 | `create-react-on-rails-app` validation improvements |
| Pro Fixed | #2416 | StreamResponse status fallback fix |
| Pro Fixed | #2566 | Empty-string license plan mismatch fix |

### Skipped PRs (not user-visible)

Docs (#2406, #2414, #2479, #2494, #2518, #2537, #2544), CI/internal
(#2533, #2547, #2555, #2557, #2558, #2564), dependabot (#2387, #2541),
dev dependencies (#2559, #2569, #2573).

## Test plan

- [ ] Verify changelog formatting matches existing entries
- [ ] Verify all user-visible PRs since v16.4.0.rc.6 are covered

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Documentation-only changelog updates with no runtime or build behavior
changes.
> 
> **Overview**
> Updates `CHANGELOG.md`’s **[Unreleased]** section to include
previously missing user-facing entries: Procfile templates now support
env-driven ports, several generator/`bin/dev` precompile-hook and
rspack-path fixes are documented, and `create-react-on-rails-app`
validation improvements are noted.
> 
> Also adds two Pro fix entries (StreamResponse status fallback and
license plan empty-string validation) and updates the existing `bin/dev`
precompile-hook entry to credit an additional PR/contributor.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
e75d2b5. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Claude Opus 4.6 <[email protected]>
ihabadham added a commit that referenced this pull request Mar 9, 2026
…2580)

## Summary

- Reverts #2561 (squash commit 769d120), which was merged after #2568
already landed on master
- #2568 +
[shakacode/shakapacker#963](shakacode/shakapacker#963)
fix the root cause of #2438#2561's YAML-parsing fallback is redundant
- CHANGELOG entry updated to reference #2568 only

## What's removed

All of #2561's additions on top of #2568:
- `extract_precompile_hook_from_yaml` /
`extract_precompile_hook_from_shakapacker_config` split
- `extract_script_from_command` interpreter-prefix stripping
- `extract_hash_for_environment` / `current_shakapacker_environment`
helpers
- `SHAKAPACKER_CONFIG_PATH` constant, `require "erb"`, `require "yaml"`
- `rubocop:disable Metrics/ModuleLength`
- `GENERATE_PACKS_PATTERN` expansion for `generate_packs_if_needed`
- 72 lines of #2561-specific specs

## What remains (from #2568 + shakapacker#963)

- `project_root` helper (Rails.root → BUNDLE_GEMFILE → Dir.pwd fallback)
- `resolve_hook_script_path` using `project_root`
- `require "pathname"`
- 3 project_root specs
- Shakapacker `Env#current` guard (separate repo, already merged)

## Why

#2568 was designed to supersede #2561 — its PR description says so
explicitly. Both were merged, resulting in unnecessary complexity (YAML
config re-parsing, ERB evaluation, environment fallback chain) that
duplicates what Shakapacker already handles after #963.

## Test plan

- `bundle exec rspec
react_on_rails/spec/react_on_rails/packer_utils_spec.rb`
- `bundle exec rubocop react_on_rails/lib/react_on_rails/packer_utils.rb
react_on_rails/spec/react_on_rails/packer_utils_spec.rb`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved bin/dev startup reliability with enhanced hook script path
resolution during early startup when Rails.root is unavailable.
  * Removed YAML configuration dependency, streamlining hook detection.
* Added validation checks for hook script existence to prevent runtime
errors.
  * Simplified hook script pattern matching for better clarity.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants