Skip to content

Conversation

@jeffcarbs
Copy link

@jeffcarbs jeffcarbs commented Dec 18, 2025

We recently added this patch to our Rails app, so I figured I'd open a PR to see if you'd want to consider upstreaming it into Arbre.

Motivation

Our dilemma is that we have a bunch of custom Arbre components that we use in our admin app. Since you use Arbre components by their declared "builder_method" name, and not by referencing the class, they don't play well with zeitwerk/autoloading. This means you either need to:

  • Force all usages to require the right arbre component manually
  • More likely, add some sort of initializer to just require them all on app boot

We did the latter, and it was starting to become costly toward boot time since these components inevitably wound up pulling more things into memory. It's also wasteful since these components are only ever used in our admin app, but then they'd load on any app boot (e.g. rspec, rails console, background jobs, etc). You can obviously work around these things, but the beauty of Rails autoloading means you don't have to.

Solution

This PR makes it possible to autoload these components by introducing a simple convention: a component named foo_bar, is defined by a class named Arbre::Components::FooBar that's on some autoload path. This approach intentionally doesn't support deeper namespacing (e.g. Arbre::Components::Foo::Bar) since:

  • "builder_method" names don't have any namespacing, everything is global.
  • Allowing namespacing means two classes in different namespaces could have the same name, which means they’d register the same builder method. To my knowledge, nothing in the Arbre gem prevents this (maybe it should?), but at least this convention helps to prevent it.

I've updated the test suite to configure autoloading and added a test that fails before this change and passes after. Happy to help update documentation or whatever else, but first wanted to just put up this PR to see if it's even something you'd consider.

@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.36%. Comparing base (b75e00d) to head (cd6ef62).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #716      +/-   ##
==========================================
+ Coverage   94.33%   94.36%   +0.02%     
==========================================
  Files          17       17              
  Lines         459      461       +2     
==========================================
+ Hits          433      435       +2     
  Misses         26       26              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jeffcarbs jeffcarbs force-pushed the carbs-component-autoload branch from cd6ef62 to 9dc5bfb Compare December 18, 2025 20:26
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.

1 participant