Commit 03a4737
committed
Fix Issue JSONAPI-Resources#1464: Rails 7.1 Zeitwerk autoloading race condition
Issue JSONAPI-Resources#1464 reported intermittent 'NameError: uninitialized constant
JSONAPI::ResourceController' errors in Rails 7.1 when eager_load is disabled.
Root cause:
- ActiveSupport.on_load(:action_controller_base) lazy loading mechanism
- Causes race condition with Zeitwerk autoloading in Rails 7.1+
- Errors occur randomly during test execution
- Only happens locally, not in CI with eager loading enabled
Solution:
- Remove conditional lazy loading with ActiveSupport.on_load
- Always require 'jsonapi/resource_controller' directly
- Eliminates race condition with Zeitwerk
The fix ensures ResourceController is always available without
depending on ActionController::Base load timing.
Workarounds no longer needed:
- config.eager_load = true in test environment
- Manual require 'jsonapi/resource_controller' before use
- Switching to ActsAsResourceController mixin
Related: https://github.com/cerebris/jsonapi-resources/issues/14641 parent e057af8 commit 03a4737
1 file changed
Lines changed: 4 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
19 | 16 | | |
20 | 17 | | |
21 | 18 | | |
| |||
0 commit comments