live_svelte/lib/dynamic_slots.ex
John Barker 2f5ecbc077
Fixes issue with slot warnings and use of slots when using LiveSvelte use macro (#196)
* Fixes issue with slot warnings and use of slots when using LiveSvelte. Components use macro
2026-02-02 23:19:33 +02:00

26 lines
996 B
Elixir

defmodule LiveSvelte.DynamicSlots do
@moduledoc false
@doc false
defmacro __before_compile__(_env) do
quote do
# Mark Phoenix's generated __components__/0 as overridable, then override it.
# Phoenix generates __components__/0 but doesn't mark it as overridable.
defoverridable __components__: 0
# Override Phoenix's __components__/0 to skip slot validation for the svelte component.
#
# Phoenix LiveView 1.x uses __components__/0 to get component definitions for validation.
# The verification code does:
# component = submod.__components__()[fun]
#
# If this returns nil, the verification is skipped entirely for that component.
# This allows LiveSvelte to accept arbitrary slot names without warnings.
def __components__ do
# Return empty map so __components__()[:svelte] returns nil
# This skips slot/attr validation entirely for the svelte component
%{}
end
end
end
end