Skip to content

Commit 4dcbf89

Browse files
committed
fix: use dynamic function call for optional Phoenix.Component dependency
Use apply/3 to call Phoenix.Component.assign/3 conditionally to avoid compilation warnings when Phoenix.LiveView is not installed. This allows the Redux.LiveView module to compile successfully in CI where LiveView is not a dependency.
1 parent 5e8a764 commit 4dcbf89

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/phoenix/session_process/redux/live_view.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,12 @@ defmodule Phoenix.SessionProcess.Redux.LiveView do
232232
@spec handle_assign_update(Phoenix.LiveView.Socket.t(), atom(), any()) ::
233233
Phoenix.LiveView.Socket.t()
234234
def handle_assign_update(socket, assign_key, value) do
235-
Phoenix.Component.assign(socket, assign_key, value)
235+
if Code.ensure_loaded?(Phoenix.Component) do
236+
apply(Phoenix.Component, :assign, [socket, assign_key, value])
237+
else
238+
# Fallback if Phoenix.Component is not available
239+
Map.update!(socket, :assigns, &Map.put(&1, assign_key, value))
240+
end
236241
end
237242

238243
@doc """

0 commit comments

Comments
 (0)