Skip to content

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, mirroring css_sources/0. A module declares %{app:, file:, global:} entries; the new :phoenix_kit_js_sources compiler resolves each bundle via :code.priv_dir/1 (Hex + path deps), IIFE-wraps and concatenates them into priv/static/assets/vendor/phoenix_kit_modules.js, and folds each window.<Global> into window.PhoenixKitHooks (already spread into the host’s LiveSocket). One stable <script> tag is added by mix phoenix_kit.install; mix phoenix_kit.update backfills 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.pm instead of the hexdocs.pm/phoenix_kit path 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_fields keys. persist_tree_state/1 re-reads the user fresh from the DB before writing (matching persist_user_view_mode/2), because update_user_custom_fields replaces the entire custom_fields map 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 a custom_fields value 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 no compilers: key yet (the css_sources analogue had the same latent bug), in both install and update.
  • seed_modules_js_file/1 surfaces 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.