grych / drab

Remote controlled frontend framework for Phoenix.

Home Page:https://tg.pl/drab

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Assigns not found in Drab EEx template on poke

mbaleczny opened this issue · comments

Elixir: 1.6.5
Phoenix: 1.3.3
Drab: 0.8.3

Calling handlers next_week / previous_week in drab partial

<div id="<%= @current_week_monday %>" style="display: none;"></div>
<div id="weekdays">
    <img src="<%= static_path(@conn, "/images/arrow.svg") %>" class="arrow" drab="click:previous_week">
    <%= for day <- @weekdays do %>
        <%= day %>
    <% end %>
    <img src="<%= static_path(@conn, "/images/arrow.svg") %>" class="arrow ar-right" drab="click:next_week">
</div>

raise an error:

[error] Drab Handler failed with the following exception:
** (ArgumentError) assign @weekdays not found in Drab EEx template.

Please make sure all proper assigns have been set. If this
is a child template, ensure assigns are given explicitly by
the parent template as they are not automatically forwarded.

Available assigns:
[:current_week_monday]

    (drab) lib/drab/live.ex:1020: Drab.Live.raise_assign_not_found/2
    (drab) lib/drab/live.ex:710: anonymous fn/3 in Drab.Live.assigns_to_update_keys/2
    (elixir) lib/enum.ex:1899: Enum."-reduce/3-lists^foldl/2-0-"/3
    (drab) lib/drab/live.ex:708: Drab.Live.assigns_to_update_keys/2
    (drab) lib/drab/live.ex:723: Drab.Live.amperes_to_update/4
    (drab) lib/drab/live.ex:745: Drab.Live.update_javascripts/5
    (drab) lib/drab/live.ex:652: Drab.Live.process_poke/9
    (drab) lib/drab.ex:349: anonymous fn/7 in Drab.handle_event/6

BUT after change showed below there's no error. Is there any explanation to this?

<div id="<%= @current_week_monday %>" style="display: none;"></div>
<div id="weekdays">
    # REMOVE LINE BELOW
    <img src="<%= static_path(@conn, "/images/arrow.svg") %>" class="arrow" drab="click:previous_week">
    <%= for day <- @weekdays do %>
        <%= day %>
    <% end %>
     # ADD LINE BELOW
    <img src="<%= static_path(@conn, "/images/arrow.svg") %>" class="arrow" drab="click:previous_week">
    <img src="<%= static_path(@conn, "/images/arrow.svg") %>" class="arrow ar-right" drab="click:next_week">
</div>

Many thanks for reporting!
It is a bug. Looks like it can't find the proper tag to anchor in, in this particular case. Must be a corner case - non-closing html tag with a special assign (@conn) inside.

For the (ugly) workaround, add <span></span> before the for comprehension.

It was a bug in how Drab.Live is treating non-closing (<img>, <br>, etc) tags. Fix is coming.