Skip to content
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

Fix engine loading for Rails < 7.2 #1707

Merged
merged 2 commits into from
Nov 6, 2023
Merged

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Nov 3, 2023

Motivation

Closes #1706

In #1702, I was trying to avoid having to spread a bunch of conditionals in our code to handle the Rails 7.2 configuration rename. For some reason, the approach doesn't work properly for Rails < 7.2.

Implementation

Switched the configuration patching to just use conditionals where we look for eager load paths.

Tests

We have a specific test for verifying that RBIs include classes defined under the app folder in engines. I'm not sure why this isn't failing in the Rails main build.

I verified that this works on Rails 7.2 and older manually.

@vinistock vinistock self-assigned this Nov 3, 2023
Comment on lines 113 to 118
# https://github.com/rails/rails/commit/ebfca905db14020589c22e6937382e6f8f687664
eager_load_paths = if Rails::VERSION::MAJOR >= 7 && Rails::VERSION::MINOR >= 2
engine.config.all_eager_load_paths
else
engine.config.eager_load_paths
end
Copy link
Member

Choose a reason for hiding this comment

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

I am not a huge fan of version checks if we don't have to, feature detection is always nicer.

Can we instead check for the existence of the all_eager_load_paths method instead and encapsulate the lookup in a method?

Suggested change
# https://github.com/rails/rails/commit/ebfca905db14020589c22e6937382e6f8f687664
eager_load_paths = if Rails::VERSION::MAJOR >= 7 && Rails::VERSION::MINOR >= 2
engine.config.all_eager_load_paths
else
engine.config.eager_load_paths
end
eager_load_paths = eager_load_paths(engine)

and

def eager_load_paths(engine)
  config = engine.config

  (config.respond_to?(:all_eager_load_paths) && config.all_eager_load_paths) || config.eager_load_paths
end

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. I made the change.

However, we still need to duplicate the logic for the symbol loader, which I don't exactly love.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's not great, but I think the real fix is to extract an engine handler class to unify the logic. Not really a concern that needs to be addressed by this PR, though.

@vinistock vinistock force-pushed the vs/fix_engine_loading_older_rails branch from 9347ab3 to e42529f Compare November 3, 2023 17:21
@vinistock
Copy link
Member Author

I also upgraded rbi and restricted the prism version temporarily. There's a bug in how we were generating the Prism RBIs and until that is fixed we can't use Prism v0.16 or higher in Tapioca (because the tapioca gem --verify would fail).

@vinistock
Copy link
Member Author

Note: the latest RBI has the fixes we need and I opened a PR to upgrade our dependency #1708, which I can merge immediately after this one.

@paracycle
Copy link
Member

because the tapioca gem --verify would fail

I don't quite get why this would be the case. Can you explain more?

@vinistock
Copy link
Member Author

I don't quite get why this would be the case. Can you explain more?

We added automatic RBI generation to Prism, which means Tapioca picks it up from rbi. However, the versions before Prism v0.17.1 had a bug in the RBI generation that always led to typechecking errors in the RBIs themselves.

That unfortunately means that CI would never pass. If we generated the RBIs for rbi, then typechecking would fail. If we didn't, then tapioca gem --verify would fail because the RBIs for rbi aren't up to date.

Version v0.17.1 fixes the RBIs, so now we can properly generate it.

@vinistock vinistock merged commit 14acb51 into main Nov 6, 2023
29 checks passed
@vinistock vinistock deleted the vs/fix_engine_loading_older_rails branch November 6, 2023 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gem RBI generation is missing Rails engines files after upgrading to v0.11.10
3 participants