Cohabitation with LiveView
- Dominant language
- Elixir
- Stars
- 878
- Forks
- 44
- PR merge metrics
- No merged PRs in 30d
Description
Since LiveView is now public, probably the developers will try to use both libraries in the same app, but at this time it is not possible because `Drab.Client.generate_drab_js/3` rises when it tries to get the controller module for a `LV` page, as `:phoenix_controller` is not present in the `conn` of a LiveView page.
Checking for the presence of `:live_view_module` in the `conn` parameters reveals if the page is suited or not for generating the drab js, for example:
```elixir
defp generate_drab_js(conn, connect?, assigns) do
if !conn.assigns[:live_view_module] do
controller = Phoenix.Controller.controller_module(conn)
...
```
This way both libraries can cohabit at the same time in the same app, using Drab only for pages based on Controllers/.eex templates (but not for LiveView pages because its js code will not be injected).
Edit:
The PR #192 solve this problem with a more general solution than the one initially proposed above
Contributor guide
Research direction
Start at Drab.Client.generate_drab_js/3 and inspect how LiveView connections differ from controller-backed pages, especially the :live_view_module and :phoenix_controller values. Review PR #192, which the issue says provides a more general solution, and verify that Drab and LiveView can coexist without injecting Drab JavaScript into LiveView pages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 20/100