# `CredoHotUpgrades.Check.LiveViewClosure`
[🔗](https://github.com/deployex/credo_hot_upgrades/blob/main/lib/credo_hot_upgrades/check/live_view_closure.ex#L1)

## Basics

> #### This check is disabled by default. {: .neutral}
>
> [Learn how to enable it](`e:credo:config_file.html#checks`) via `.credo.exs`.

This check has a base priority of `high` and works with any version of Elixir.

## Explanation

A LiveView or a LiveComponent is a process that lives as long as the page
is open, often for hours, and its socket is its state. A function kept in
that socket outlives the module version that built it:

    socket
    |> attach_hook(:filters, :handle_params, &apply_filters/3)
    |> assign(:formatter, fn value -> format(value) end)

After a hot upgrade of the module, the page still holds the capture of
the old version. The process is killed when the old code is purged, or
raises `BadFunctionError` on the next event that calls the function. The
user sees the page crash and reconnect, and loses what the page held.

Keep a capture that resolves through the module by name,
`&__MODULE__.apply_filters/3` or `&MyAppWeb.Filters.apply/3`, and make the
function public. For an assign, keep the data and call the function where
it is rendered or handled, or keep `{module, function, args}`.

This check looks at `attach_hook`, at the values given to `assign`, and at
the `dom_id:` option of `stream` and `stream_configure`. It does not see a
function passed as an attribute inside a `~H` template, and it does not
follow a function through a variable. `assign` on a variable named
`assigns` or `conn` is left alone: the assigns of a function component
last for one render, and a connection for one request.

## Check-Specific Parameters

*There are no specific parameters for this check.*

## General Parameters

Like with all checks, [general params](`e:credo:check_params.html`) can be applied.

Parameters can be configured via the [`.credo.exs` config file](`e:credo:config_file.html`).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
