@@ -399,14 +399,28 @@ defmodule Phoenix.LiveView.Engine do
399399
400400 root = Keyword . get ( opts , :root , meta [ :root ] )
401401
402+ dynamic =
403+ if dynamic == [ ] do
404+ quote do
405+ fn _ ->
406+ _ = unquote ( @ assigns_var )
407+ [ ]
408+ end
409+ end
410+ else
411+ quote do
412+ fn track_changes? ->
413+ changed = unquote ( changed )
414+ vars_changed = if track_changes? , do: vars_changed
415+ unquote ( { :__block__ , [ ] , block } )
416+ unquote ( dynamic )
417+ end
418+ end
419+ end
420+
402421 { :ok ,
403422 quote do
404- dynamic = fn track_changes? ->
405- changed = unquote ( changed )
406- vars_changed = if track_changes? , do: vars_changed
407- unquote ( { :__block__ , [ ] , block } )
408- unquote ( dynamic )
409- end
423+ dynamic = unquote ( dynamic )
410424
411425 % Phoenix.LiveView.Rendered {
412426 static: unquote ( static ) ,
@@ -898,7 +912,26 @@ defmodule Phoenix.LiveView.Engine do
898912 ) do
899913 with { call , meta , [ ^ key , [ do: block ] ] } <- inner_block ,
900914 :inner_block <- extract_call ( call ) do
901- inner_block = { call , meta , [ key , [ do: maybe_block_to_rendered ( block , vars , caller ) ] ] }
915+ inner_block =
916+ case block do
917+ [
918+ { :-> , _ ,
919+ [
920+ [ { :_ , _ , _ } ] ,
921+ { :__block__ , [ live_rendered: true ] ++ _meta , [ { :safe , _ } ] } = static_block
922+ ] }
923+ ] ->
924+ # This is an optimization that removes the extra anonymous function from
925+ # the TagEngine's build_component_clauses function used for slots.
926+ # We can do this when the slot does not contain any dynamics, which also helps
927+ # to prevent uncovered lines when rendering a component with only a named slot.
928+ # In that case, the component still has an inner_block, but it only consists of
929+ # whitespace.
930+ maybe_block_to_rendered ( static_block , vars , caller )
931+
932+ _ ->
933+ { call , meta , [ key , [ do: maybe_block_to_rendered ( block , vars , caller ) ] ] }
934+ end
902935
903936 { :%{} , map_meta , [ __slot__: key , inner_block: inner_block ] ++ attrs }
904937 else
@@ -1320,17 +1353,6 @@ defmodule Phoenix.LiveView.Engine do
13201353 quote line: line , do: Phoenix.HTML.Safe.List . to_iodata ( unquote ( literal ) )
13211354 end
13221355
1323- # Calls to attributes escape is always safe
1324- defp to_safe (
1325- { { :. , _ , [ Phoenix.LiveView.TagEngine , :attributes_escape ] } , _ , [ _ ] } = safe ,
1326- line ,
1327- _extra_clauses?
1328- ) do
1329- quote line: line do
1330- elem ( unquote ( safe ) , 1 )
1331- end
1332- end
1333-
13341356 defp to_safe ( expr , line , false ) do
13351357 quote line: line , do: unquote ( __MODULE__ ) . safe_to_iodata ( unquote ( expr ) )
13361358 end
0 commit comments