Fix intermediate output ids to not change on finished evaluation (#622)

This commit is contained in:
Jonatan Kłosko 2021-10-20 00:32:48 +02:00 committed by GitHub
parent f29a2a37a0
commit aefe8d03c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -419,13 +419,19 @@ defmodule LivebookWeb.SessionLive.CellComponent do
<div class="flex flex-col rounded-lg border border-gray-200 divide-y divide-gray-200">
<%= for {output, index} <- @cell_view.outputs |> Enum.reverse() |> Enum.with_index(), output != :ignored do %>
<div class="p-4 max-w-full overflow-y-auto tiny-scrollbar">
<%= render_output(output, %{id: "cell-#{@cell_view.id}-evaluation#{@cell_view.number_of_evaluations}-output#{index}", socket: @socket}) %>
<%= render_output(output, %{
id: "cell-#{@cell_view.id}-evaluation#{evaluation_number(@cell_view.evaluation_status, @cell_view.number_of_evaluations)}-output#{index}",
socket: @socket
}) %>
</div>
<% end %>
</div>
"""
end
defp evaluation_number(:evaluating, number_of_evaluations), do: number_of_evaluations + 1
defp evaluation_number(_evaluation_status, number_of_evaluations), do: number_of_evaluations
defp render_output(text, %{id: id}) when is_binary(text) do
# Captured output usually has a trailing newline that we can ignore,
# because each line is itself an HTML block anyway.