Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to phoenix_live_view 0.9.0 #5

Closed
1 task done
nelsonic opened this issue Mar 10, 2020 · 6 comments
Closed
1 task done

Update to phoenix_live_view 0.9.0 #5

nelsonic opened this issue Mar 10, 2020 · 6 comments
Labels
chore enhancement New feature or request help wanted Extra attention is needed T2h technical

Comments

@nelsonic
Copy link
Member

nelsonic commented Mar 10, 2020

phoenix_live_view 0.9.0 was released two days ago: https://hex.pm/packages/phoenix_live_view
I've attempted to update to 0.9.0 but it breaks:
image

For reference, this is what it should look like:
phoenix-liveview-counter-single-windowl

view-source:http://localhost:4000 suggests that the layout template is not being rendered:
image

Todo

  • Investigate why the layout is not being rendered!
@nelsonic nelsonic added enhancement New feature or request help wanted Extra attention is needed chore T2h technical labels Mar 10, 2020
@nelsonic
Copy link
Member Author

@nelsonic
Copy link
Member Author

Once #4 is merged we will be able to open an issue on https://github.com/phoenixframework/phoenix_live_view/issues with a full explanation and steps to reproduce!

@nelsonic
Copy link
Member Author

@nelsonic
Copy link
Member Author

Attempted to add put_root_layout to :browser pipeline in router.ex as instructed in the changelog.

Getting:

== Compilation error in file lib/live_view_counter_web/router.ex ==
** (CompileError) lib/live_view_counter_web/router.ex: undefined function put_root_layout/2
    (elixir 1.10.1) src/elixir_locals.erl:114: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
    (stdlib 3.11.2) erl_eval.erl:680: :erl_eval.do_apply/6

There are only 6 Google search results for "phoenix put_root_layout":
https://www.google.com/search?q=phoenix+put_root_layout

google-search-phoenix-put_root_layout

I've read through all 6 results and put_root_layout is a function in the controller.ex
image

it looks like the Phoenix generator
is about to have a new --live option as in:

mix phx.new --live

See: phoenixframework/phoenix#3680

That will significantly reduce the number of setup steps.
I'm going to keep my eyes on the phoenix releases https://github.com/phoenixframework/phoenix/releases
and if a new version is released I will revisit this.

@nelsonic
Copy link
Member Author

** (exit) an exception was raised:
    ** (ArgumentError) assign @conn not available in eex template.

Replaced all instances of @conn in lib/live_view_counter_web/templates/layout/app.html.leex

Now seeing the following error:

[error] GenServer #PID<0.486.0> terminating
** (ArgumentError) :flash is a reserved assign by LiveView and it cannot be set directly. Use the appropriate flash functions instead.
    (phoenix_live_view 0.9.0) lib/phoenix_live_view.ex:1425: Phoenix.LiveView.validate_assign_key!/1
    (phoenix_live_view 0.9.0) lib/phoenix_live_view.ex:1419: anonymous fn/2 in Phoenix.LiveView.assign/2
    (stdlib 3.11.2) maps.erl:232: :maps.fold_1/3
    (live_view_counter 0.9.0) lib/live_view_counter_web/live/counter.ex:25: LiveViewCounterWeb.Counter.handle_info/2
    (phoenix_live_view 0.9.0) lib/phoenix_live_view/channel.ex:113: Phoenix.LiveView.Channel.handle_info/2
    (stdlib 3.11.2) gen_server.erl:637: :gen_server.try_dispatch/4
    (stdlib 3.11.2) gen_server.erl:711: :gen_server.handle_msg/6
    (stdlib 3.11.2) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: %Phoenix.Socket.Broadcast{event: "inc", payload: %{flash: %{}, live_view_action: nil, live_view_module: LiveViewCounterWeb.Counter, val: 1}, topic: "live"}
State: %{components: {%{}, %{}, 0}, join_ref: "4", serializer: Phoenix.Socket.V2.JSONSerializer, socket: #Phoenix.LiveView.Socket<assigns: %{flash: %{}, live_view_action: nil, live_view_module: LiveViewCounterWeb.Counter, val: 0}, changed: %{}, endpoint: LiveViewCounterWeb.Endpoint, id: "phx-FfsCpTRMyIBxyQBh", parent_pid: nil, root_pid: #PID<0.486.0>, router: LiveViewCounterWeb.Router, view: LiveViewCounterWeb.Counter, ...>, topic: "lv:phx-FfsCpTRMyIBxyQBh", transport_pid: #PID<0.483.0>, uri: %URI{authority: nil, fragment: nil, host: "localhost", path: nil, port: 4000, query: nil, scheme: "http", userinfo: nil}}

The line in the code is:

 %Phoenix.Socket.Broadcast{
  event: "inc",
  payload: %{
    flash: %{},
    live_view_action: nil,
    live_view_module: LiveViewCounterWeb.Counter,
    val: 1
  },
  topic: "live"
}

After a bit of debugging I figured it out! 🙌

@nelsonic
Copy link
Member Author

Fixed in #6 :shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore enhancement New feature or request help wanted Extra attention is needed T2h technical
Projects
None yet
Development

No branches or pull requests

1 participant