Visitar URL original
Document importmap_watches and loading custom Arbre components by senid231 · Pull Request #9156 · activeadmin/activeadmin · GitHub
Skip to content

Document importmap_watches and loading custom Arbre components - #9156

Open
senid231 wants to merge 9 commits into
activeadmin:masterfrom
senid231:docs-javascript
Open

senid231 wants to merge 9 commits into
activeadmin:masterfrom
senid231:docs-javascript

Conversation

@senid231

@senid231 senid231 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Documents how to add JavaScript to Active Admin pages from an engine and how to load custom Arbre components.

Depends on #9148 and on #9153. This branch contains their commits; only the last two commits belong to this PR. I'll rebase it after they merge.

  • The engine example in the "JavaScript modules" section also appends to importmap_watches. It notes that Propshaft serves an engine's vendor/javascript only if the engine adds it to the asset paths.
  • A paragraph explains config.importmap_watches for modules that the host app pins, and says to append to it from an initializer because a later append raises.
  • "Custom components" in the Arbre docs explains why a component that calls builder_method must load before the register blocks that use it. It recommends eager-loading the component directory in config.to_prepare, and requiring files under lib/ from the same block.

Part of #9147.

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.11%. Comparing base (e1dad93) to head (e427785).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9156   +/-   ##
=======================================
  Coverage   99.11%   99.11%           
=======================================
  Files         139      140    +1     
  Lines        4071     4089   +18     
=======================================
+ Hits         4035     4053   +18     
  Misses         36       36           

☔ View full report in Codecov by Harness.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Active Admin pages render only ActiveAdmin.importmap and import only its
active_admin entry point, so a module pinned in the host's importmap loads
nothing. Themes and plugins copied _html_head to add their imports.

Co-Authored-By: Clanker
The setting default is one shared array, so appending to it leaked into every later Application.

Co-Authored-By: Clanker
Importmap::Map#cache_sweeper(watches:) builds a new watcher on each call,
so an engine that passed its own directory replaced ActiveAdmin's. The
sweeper is now built once in after_initialize from this list, which
engines and config/initializers can extend.

Co-Authored-By: Clanker
A request made from an earlier after_initialize hook ran before the
sweeper existed. The spec now edits an existing file instead of relying
on a new one, and restores the boot-time sweeper.

Co-Authored-By: Clanker
The sweeper reads the list once in after_initialize, so a directory
added later, for example from to_prepare, was silently never watched.

Co-Authored-By: Clanker
builder_method runs when the component class loads, and nothing
references the class constant, so autoloading never loads it before the
register blocks that use it.

Co-Authored-By: Clanker
Rails runs to_prepare blocks on the reloader, so a bare root is
undefined there, and appends to importmap_watches made after
after_initialize never reach the sweeper.

Co-Authored-By: Clanker
A plain frozen array already rejects late appends. The setting's comment
now says to append from an initializer.

Co-Authored-By: Clanker

This branch has not been deployed

No deployments
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