Visitar URL original
Add importmap_watches setting for the import map cache sweeper by senid231 · Pull Request #9153 · activeadmin/activeadmin · GitHub
Skip to content

Add importmap_watches setting for the import map cache sweeper - #9153

Open
senid231 wants to merge 4 commits into
activeadmin:masterfrom
senid231:importmap-watches
Open

senid231 wants to merge 4 commits into
activeadmin:masterfrom
senid231:importmap-watches

Conversation

@senid231

@senid231 senid231 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Adds config.importmap_watches, the directories whose JavaScript changes clear the ActiveAdmin.importmap cache in development and test. It starts with Active Admin's own app/javascript.

Importmap::Map#cache_sweeper(watches:) builds a new watcher on each call, so an engine passing its own directory replaced Active Admin's. Now engines append to the list, and Active Admin builds the sweeper once in after_initialize. That also lets the host append from config/initializers/active_admin.rb, which runs after engine initializers.

Things a reviewer may ask:

  • A plugin that still calls cache_sweeper(watches:) itself loses its watcher to the one built in after_initialize. It should append to importmap_watches instead.
  • Once the sweeper is built, the list is frozen, so appending to it raises a FrozenError. The setting's comment and the docs say to append from an initializer. A late append, for example from config.to_prepare, would otherwise never be watched.
  • Rails' file watcher skips directories under Gem.path, so only path gems and in-app engines benefit.
  • Application#settings dups the default per application, as Add javascript_modules setting to import modules on every page #9148 does for javascript_modules. The two PRs conflict on that line; the resolution keeps both.

Part of #9147. Specs cover the default, the per-application copy, the error on a late append, and a cache clear after editing a file in an added directory.

@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 (1bad7b1).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9153   +/-   ##
=======================================
  Coverage   99.11%   99.11%           
=======================================
  Files         139      139           
  Lines        4071     4077    +6     
=======================================
+ Hits         4035     4041    +6     
  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.

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
senid231 added a commit to activeadmin-plugins/active_admin_scoped_collection_actions that referenced this pull request Nov 12, 2026
Replacing ActiveAdmin's cache sweeper outright drops directories other
engines register through importmap_watches (activeadmin/activeadmin#9153).
Rebuild the sweeper only when that setting is missing.

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