Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Phoenix Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-phoenix-knowledge-patch)
---
name: phoenix-knowledge-patch
description: Phoenix
version: "1.8.x"
license: MIT
metadata:
author: Nevaberry
---
# Phoenix Knowledge Patch
Load this skill when upgrading Phoenix, adapting generated applications,
configuring scoped data access and authentication, or working on routing,
channels, Presence, and JavaScript transports.
## Reference index
| Reference | Topics |
| --- | --- |
| [Runtime, security, and routing](references/runtime-security-and-routing.md) | Upgrade selection, runtime requirements, browser headers, controller declarations, endpoint configuration, verified routes, assigns, channel limits, and server broadcasts |
| [Generators, clients, and testing](references/generators-client-and-testing.md) | Project creation, templates, components, deployment setup, certificates, JavaScript socket behavior, LongPoll, channel messages, and test assertions |
| [Scopes and authentication](references/scopes-and-auth.md) | Scope selection, ownership columns, nested routes, context calls, LiveView hooks, PubSub, test helpers, authentication migration, delivery, and privacy |
## Upgrade and migration checks
Phoenix 1.8 requires Erlang/OTP 25 or later.
Upgrade to Phoenix 1.8.17 for fixes to topic-wide denial of service caused by
channel serialization failures and a Presence tracker crash involving presence
keys. Consult the runtime reference for advisory links and Hex version flags.
`put_secure_browser_headers` defaults to the CSP
`base-uri 'self'; frame-ancestors 'self';` when no policy is set.
To embed the app on another origin, set your own `frame-ancestors` policy and
account for the removal of the default `x-frame-options` and `x-download-options`
headers. Parameters matching `token` join `password` in default log filtering
starting in 1.8.7.
Apps with authentication generated in Phoenix 1.7 or earlier can adopt scopes
independently of magic links. To migrate to passwordless registration, add a new
migration making `hashed_password` nullable with `null: true`. Clear
`hashed_password` to `nil` for every unconfirmed account when retiring the old
password-recovery flow.
## Controller and endpoint declarations
Declare controller formats explicitly:
```elixir
use Phoenix.Controller, formats: [:html]
```
Use `formats: []` when formats are determined later. Replace deprecated
`:namespace` and `:put_default_views` options with explicit view configuration.
Pass the layout module with the layout name:
```elixir
put_layout(conn, html: {MyAppWeb.Layouts, :print})
```
Replace the injected endpoint `config` variable with `Application.compile_env/3`
at module scope. Keep settings read this way consistent between compilation
and boot.
```elixir
@endpoint_config Application.compile_env(:my_app, __MODULE__, [])
```
## Verified routes and router pipelines
The router's `:trailing_slash` option is deprecated. Use verified routes for URL
generation, such as `~p"/posts/"` when a trailing slash is needed.
Phoenix 1.8.14 raises at compile time if the `:router` option to
`use Phoenix.VerifiedRoutes` is anything other than a compile-time literal.
Pass the router module directly:
```elixir
use Phoenix.VerifiedRoutes,
endpoint: MyAppWeb.Endpoint,
router: MyAppWeb.Router
```
From 1.8.6, using `Phoenix.VerifiedRoutes` more than once in a module or
interpolating a list into a verified route raises.
Starting in 1.8.2, verified routes omit configured path prefixes for static paths.
For deterministic query parameter order in verified-route tests, set
`config :phoenix, :sort_verified_routes_query_params, true` in `config/test.exs`
starting in 1.8.3.
Starting in 1.8.10, `pipe_through` accepts a plug and options as a tuple:
```elixir
pipe_through [:browser, {MyAppWeb.RequireRole, :admin}]
```
## Scope selection and scoped access
`mix phx.gen.auth` makes its generated user scope the default when the app has
no default scope. Schema, context, LiveView, HTML, and JSON generators
automatically use the single scope marked `default: true`.
Select a named scope with `--scope`:
```console
mix phx.gen.live Blog Post posts title:string --scope organization
```
Generated context functions take the scope struct first. For example,
`Blog.get_post!(scope, id)` raises `Ecto.NoResultsError` for an ID outside the
scope; Phoenix renders this as a 404 with `debug_errors: false`.
Put generated LiveView routes for user-owned resources in the authentication
generator's `:require_authenticated_user` live session. On routes allowing
anonymous visitors, use `{MyAppWeb.UserAuth, :mount_current_scope}` to load
`:current_scope`, which is `nil` for signed-out visitors.
A scoped `mix phx.gen.live` resource subscribes through its context, for example
`Blog.subscribe_posts(socket.assigns.current_scope)`. Its generated LiveView
handles `{:created, %Post{}}`, `{:updated, %Post{}}`, and `{:deleted, %Post{}}`
messages for that scope in `handle_info/2`.
## Nested ownership and scope tests
Configure `access_path` for the database ownership key and `route_access_path`
for the value interpolated into the route. When `route_prefix` is set and
`route_access_path` is omitted, the generator drops the final key from
`access_path`, keeping the original path if the result would be empty.
Resolve an organization from its route parameter through the signed-in user's
scope so the lookup enforces membership. Populate the organization in
`:current_scope` after `fetch_current_scope_for_user` in the browser pipeline
and in an `on_mount` hook after the authentication scope hook in `live_session`.
The `test_data_fixture` module must provide a zero-argument fixture named after
the scope that returns a unique scope struct. The `test_setup_helper` function
must be available to generated controller and LiveView tests as an ExUnit
setup callback supplying `conn` and `scope`.
See the scopes reference for ownership columns without a backing table,
migration foreign key types, MyXQL generation, and umbrella configuration.
## Generated authentication behavior
Generated authentication blocks unconfirmed accounts.
`UserAuth.require_sudo_mode` enforces recent authentication for sensitive routes.
`redirect_if_user_is_authenticated` is generated only for controller-based
authentication.
Authentication generated with Phoenix 1.8.12 clears the stored return path after
sign-in. If the path persists across sign-ins in an existing app, update its
generated authentication code.
If the notifier logs account messages to the terminal, connect it to your
delivery backend to send confirmation and sign-in links. With the default
`mix phx.new` Swoosh setup, view delivered development mail at `/dev/mailbox`.
Generated registration reports an already registered email address. If account
membership must stay private, account for response disclosures and timing in
registration, sign-in, and other notification flows.
`mix phx.gen.auth` expects `phoenix_html.js` in the JavaScript bundle and warns
when esbuild is absent. Include that asset with a different build setup.
## Project and generator changes
`mix phx.new` initializes a repository when Git is installed, adds `mix precommit`,
and generates an `AGENTS.md` compatible with `usage_rules`. The installer ships
Phoenix rules for syncing into projects.
Phoenix 1.8.6 adds `mix phx.new --interactive`.
Context, HTML, JSON, and LiveView generators can infer the context from the
schema's plural name: `mix phx.gen.html Post posts title:string` generates `Posts`.
The generators use Ecto 3.13's `Repo.transact/2` for generated transactions.
Starting in 1.8.6, maintain `phx.gen.*` templates with an `.eex` filename suffix.
Phoenix 1.8.2 restores hidden fields in the generated `<.input>` component.
Existing apps with an older `CoreComponents` copy need its hidden-input clause
to use `<.input field={@form[:return_to]} type="hidden" />`.
## Channel limits and LongPoll
LongPoll is active by default in 1.8.0 and 1.8.1 and returns to opt-in in 1.8.2:
```elixir
socket "/socket", MyAppWeb.UserSocket, longpoll: true
```
Phoenix 1.8.9 enforces 100 events per LongPoll request. If your application may
send larger batches, upgrade to 1.8.7 before deploying 1.8.9.
`max_channels_per_transport` caps concurrent channels per transport, with a
default of 100 in 1.8.9. Starting in 1.8.16, set it in `Phoenix.Endpoint.socket/3`
for a particular socket declaration:
```elixir
socket "/socket", MyAppWeb.UserSocket, max_channels_per_transport: 50
```
Phoenix 1.8.17 supports binary channel messages over LongPoll and sends the
fallback health check before a buffered channel join when falling back to it.
## JavaScript reconnection and channel messages
Starting in 1.8.2, the JavaScript socket pauses reconnection attempts while the
page is hidden. In 1.8.17, pass `reconnectWhenHidden: true` to the JavaScript
`Socket` constructor to allow reconnection attempts while the tab is hidden.
Starting in 1.8.16, WebSocket close code `1000` alone no longer suppresses
automatic reconnection; normal closures follow the client's usual reconnect rules.
Starting in 1.8.3, incoming channel messages with stale join references are
dropped. Use the current join reference after rejoining. Phoenix 1.8.12 accepts
messages that omit `join_ref`; versions 1.8.3 through 1.8.11 can drop them.
## Assign updates and channel assertions
In 1.8.2, `Phoenix.Socket.assign/2` and `Phoenix.Controller.assign/2` accept a
function receiving existing assigns and returning updates to merge. The
controller API also accepts a map or keyword list directly.
```elixir
Phoenix.Socket.assign(socket, fn assigns -> %{count: Map.get(assigns, :count, 0) + 1} end)
```
Starting in 1.8.4, `assert_push`, `assert_broadcast`, and `assert_reply` support
guards, for example `assert_push "new_msg", %{body: body} when is_binary(body)`.