diff --git a/lib/livebook/session.ex b/lib/livebook/session.ex index a94144e56..1053fa1d5 100644 --- a/lib/livebook/session.ex +++ b/lib/livebook/session.ex @@ -2889,34 +2889,22 @@ defmodule Livebook.Session do # attributes that are missing. defp normalize_runtime_output(output) - defp normalize_runtime_output(%{type: :input, attrs: attrs} = output) - when attrs.type in [:text, :textarea, :password, :number, :url, :range, :color] and - not is_map_key(attrs, :debounce) do - default = - case attrs.type do - :range -> 250 - _other -> :blur - end - - put_in(output.attrs[:debounce], default) - |> normalize_runtime_output() - end - # Traverse composite outputs - defp normalize_runtime_output(output) when output.type in [:frame, :tabs, :grid] do - outputs = Enum.map(output.outputs, &normalize_runtime_output/1) - %{output | outputs: outputs} - end + # defp normalize_runtime_output(output) when output.type in [:frame, :tabs, :grid] do + # outputs = Enum.map(output.outputs, &normalize_runtime_output/1) + # %{output | outputs: outputs} + # end - defp normalize_runtime_output(%{type: :frame_update} = output) do - {update_type, new_outputs} = output.update - new_outputs = Enum.map(new_outputs, &normalize_runtime_output/1) - %{output | update: {update_type, new_outputs}} - end + # defp normalize_runtime_output(%{type: :frame_update} = output) do + # {update_type, new_outputs} = output.update + # new_outputs = Enum.map(new_outputs, &normalize_runtime_output/1) + # %{output | update: {update_type, new_outputs}} + # end defp normalize_runtime_output(output) when is_map(output), do: output + # TODO: Remove this when Kino v0.10.0 is a long time in the past. # Rewrite tuples to maps for backward compatibility with Kino <= 0.10.0 defp normalize_runtime_output(:ignored) do @@ -3000,12 +2988,23 @@ defmodule Livebook.Session do end defp normalize_runtime_output({:input, attrs}) do - {fields, attrs} = Map.split(attrs, [:ref, :id, :destination]) + {fields, %{type: type} = attrs} = Map.split(attrs, [:ref, :id, :destination]) attrs = - case attrs.type do - :textarea -> Map.put_new(attrs, :monospace, false) - _other -> attrs + cond do + type in [:textarea] -> + attrs + |> Map.put_new(:monospace, false) + |> Map.put_new(:debounce, :blur) + + type in [:text, :password, :number, :url, :color] -> + Map.put_new(attrs, :debounce, :blur) + + type in [:range] -> + Map.put_new(attrs, :debounce, 250) + + true -> + attrs end Map.merge(fields, %{type: :input, attrs: attrs}) diff --git a/test/livebook_web/live/app_session_live_test.exs b/test/livebook_web/live/app_session_live_test.exs index f3a6df8df..41834096a 100644 --- a/test/livebook_web/live/app_session_live_test.exs +++ b/test/livebook_web/live/app_session_live_test.exs @@ -189,7 +189,7 @@ defmodule LivebookWeb.AppSessionLiveTest do ref: "ref1", id: "input1", destination: test, - attrs: %{type: :number, default: 1, label: "Name"} + attrs: %{type: :number, default: 1, label: "Name", debounce: :blur} } notebook = %{ diff --git a/test/livebook_web/live/session_live_test.exs b/test/livebook_web/live/session_live_test.exs index 508343219..0f658536a 100644 --- a/test/livebook_web/live/session_live_test.exs +++ b/test/livebook_web/live/session_live_test.exs @@ -490,7 +490,7 @@ defmodule LivebookWeb.SessionLiveTest do ref: "ref1", id: "input1", destination: test, - attrs: %{type: :number, default: 1, label: "Name"} + attrs: %{type: :number, default: 1, label: "Name", debounce: :blur} } Session.subscribe(session.id) @@ -746,7 +746,7 @@ defmodule LivebookWeb.SessionLiveTest do ref: "ref1", id: "input1", destination: test, - attrs: %{type: :number, default: 1, label: "Name"} + attrs: %{type: :number, default: 1, label: "Name", debounce: :blur} } Session.subscribe(session.id)