PhoenixKit 1.7.146: Modules can ship their own JavaScript hooks
PhoenixKit 1.7.146 lets add-on modules bring their own LiveView JavaScript hooks without any setup in the host app, the way they already bring CSS. It also fixes a media browser bug that could undo a user’s saved preferences.
A module lists its hook bundles in js_sources/0. A new compiler joins them into priv/static/assets/vendor/phoenix_kit_modules.js and adds their hooks to window.PhoenixKitHooks. The build fails with a clear error when a bundle is missing or two modules use the same global name.
Opening or closing a folder in the media sidebar saved the tree state from the copy of the user loaded with the page. A preference saved elsewhere since then, such as notification settings, could be quietly reverted. The tree state is now written over a fresh copy. The installer also keeps Mix’s default compilers when it adds its own to a mix.exs that had no compilers: list.
Upgrading
Run mix phoenix_kit.update. It adds the compiler to mix.exs and one <script> tag for the module hooks to the root layout.
Full release notes: PhoenixKit 1.7.146
1.7.146 · 14 June 2026
Added
js_sources/0— a zero-config mechanism for external PhoenixKit modules to ship LiveView JS hook bundles into the host app, mirroringcss_sources/0. A module declares%{app:, file:, global:}entries; the new:phoenix_kit_js_sourcescompiler resolves each bundle via:code.priv_dir/1(Hex + path deps), IIFE-wraps and concatenates them intopriv/static/assets/vendor/phoenix_kit_modules.js, and folds eachwindow.<Global>intowindow.PhoenixKitHooks(already spread into the host’sLiveSocket). One stable<script>tag is added bymix phoenix_kit.install;mix phoenix_kit.updatebackfills it on existing installs. The compiler fails loudly on a missing bundle, a duplicate global, or a non-identifier global. Hook names must also be namespaced to stay unique across modules and the core hooks (documented on the callback) — the merge is last-write-wins.
Changed
- PhoenixKit self-doc links now point at
phoenix-kit.hexdocs.pminstead of thehexdocs.pm/phoenix_kitpath form (install/update task footers, the not-installed warning, and the per-module-i18n guide).
Fixed
- Media sidebar tree-state persistence no longer clobbers other
custom_fieldskeys.persist_tree_state/1re-reads the user fresh from the DB before writing (matchingpersist_user_view_mode/2), becauseupdate_user_custom_fieldsreplaces the entirecustom_fieldsmap with no server-side merge. The 1.7.145 version wrote from the stale in-socket copy, so expanding/collapsing a folder could silently revert acustom_fieldsvalue saved elsewhere since the browser loaded (e.g. notification preferences). - The CSS/JS source compilers are now prepended to
Mix.compilers()instead of replacing the list when a host has nocompilers:key yet (thecss_sourcesanalogue had the same latent bug), in both install and update. seed_modules_js_file/1surfaces a seed-write failure as an installer warning instead of swallowing it (the file is still recreated on the next compile).
PhoenixKit 1.7.146. Install or update: {:phoenix_kit, "~> 1.7"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.