@@ -15,7 +15,9 @@ defmodule LiveDebuggerWeb.Live.Traces.Components.Trace do
1515 alias LiveDebuggerWeb.Hooks.Flash
1616 alias LiveDebuggerWeb.Live.Traces.Components
1717
18- @ required_assigns [ :lv_process , :displayed_trace ]
18+ @ required_assigns [ :lv_process , :displayed_trace , :parent_pid ]
19+
20+ @ trace_not_found_close_delay_ms 200
1921
2022 @ doc """
2123 Initializes the trace component by attaching the hook to the socket and checking the required assigns.
@@ -25,6 +27,7 @@ defmodule LiveDebuggerWeb.Live.Traces.Components.Trace do
2527 socket
2628 |> check_assigns! ( @ required_assigns )
2729 |> attach_hook ( :trace , :handle_event , & handle_event / 3 )
30+ |> attach_hook ( :trace , :handle_info , & handle_info / 2 )
2831 |> register_hook ( :trace )
2932 end
3033
@@ -183,9 +186,13 @@ defmodule LiveDebuggerWeb.Live.Traces.Components.Trace do
183186 |> TraceService . get ( trace_id )
184187 |> case do
185188 nil ->
189+ Process . send_after (
190+ self ( ) ,
191+ { :trace_wrapper_not_found , string_trace_id } ,
192+ @ trace_not_found_close_delay_ms
193+ )
194+
186195 socket
187- |> Flash . push_flash ( "Trace has been removed." , socket . assigns . root_pid )
188- |> push_event ( "#{ :existing_traces } -#{ string_trace_id } -collapsible" , % { action: "close" } )
189196
190197 trace ->
191198 socket
@@ -199,4 +206,13 @@ defmodule LiveDebuggerWeb.Live.Traces.Components.Trace do
199206 end
200207
201208 defp handle_event ( _ , _ , socket ) , do: { :cont , socket }
209+
210+ defp handle_info ( { :trace_wrapper_not_found , string_trace_id } , socket ) do
211+ socket
212+ |> Flash . push_flash ( "Trace has been removed." , socket . assigns . parent_pid )
213+ |> push_event ( "#{ :existing_traces } -#{ string_trace_id } -collapsible" , % { action: "close" } )
214+ |> halt ( )
215+ end
216+
217+ defp handle_info ( _ , socket ) , do: { :cont , socket }
202218end
0 commit comments