liveview-native / liveview-client-swiftui

MIT License
349 stars 29 forks source link

_format query param is getting added over and over again on reconnect attempts #1344

Closed bcardarella closed 1 month ago

bcardarella commented 1 month ago

Stack trace: Note the url in the stack trace and all of the _format=swiftui query params

14:00:31.529 [debug] MOUNT ServerWeb.ExampleLive
  Parameters: %{"_format" => "swiftui"}
  Session: %{"_csrf_token" => "8xeok9RX8fsM3KesJNS-DDcR"}

14:00:31.529 [debug] Replied in 113µs

14:00:31.559 [error] GenServer #PID<0.5913.0> terminating
** (UndefinedFunctionError) function ServerWeb.ExampleLive.SwiftUI.render/1 is undefined (module ServerWeb.ExampleLive.SwiftUI is not available)
    ServerWeb.ExampleLive.SwiftUI.render(%{socket: #Phoenix.LiveView.Socket<id: "phx-F8wMb5NgqGwbLfOH", endpoint: ServerWeb.Endpoint, view: ServerWeb.ExampleLive, parent_pid: nil, root_pid: #PID<0.5913.0>, router: ServerWeb.Router, assigns: #Phoenix.LiveView.Socket.AssignsNotInSocket<>, transport_pid: #PID<0.5907.0>, ...>, flash: %{}, __changed__: %{tickets: true}, live_action: nil, tickets: 0})
    (phoenix_live_view 0.20.14) lib/phoenix_live_view/renderer.ex:73: Phoenix.LiveView.Renderer.to_rendered/2
    (phoenix_live_view 0.20.14) lib/phoenix_live_view/channel.ex:961: anonymous fn/4 in Phoenix.LiveView.Channel.render_diff/3
    (telemetry 1.2.1) /Users/brooklin/Library/Caches/mix/installs/elixir-1.16.2-erts-14.2.2/175d0f6f4a858c1884fc97816cedfab3/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
    (phoenix_live_view 0.20.14) lib/phoenix_live_view/channel.ex:957: Phoenix.LiveView.Channel.render_diff/3
    (phoenix_live_view 0.20.14) lib/phoenix_live_view/channel.ex:554: Phoenix.LiveView.Channel.maybe_call_mount_handle_params/4
    (phoenix_live_view 0.20.14) lib/phoenix_live_view/channel.ex:1178: Phoenix.LiveView.Channel.verified_mount/8
    (phoenix_live_view 0.20.14) lib/phoenix_live_view/channel.ex:84: Phoenix.LiveView.Channel.handle_info/2
Last message: {Phoenix.Channel, %{"params" => %{"_csrf_token" => "TQw1WSdNOioBFzoJYwQSNzJ9MVR9IjUDutP6Lthr9qIDPOwDx3by9fVQ", "_format" => "swiftui", "_lvn" => %{"app_build" => "1.0", "app_version" => "1.0", "bundle_id" => "com.example.LvnWorkshop", "format" => "swiftui", "os" => "iOS", "os_version" => "17.4", "target" => "phone"}, "_mounts" => 0}, "session" => "SFMyNTY.g2gDaAJhBXQAAAAIdwJpZG0AAAAUcGh4LUY4d01iNU5ncUd3YkxmT0h3B3Nlc3Npb250AAAAAHcKcGFyZW50X3BpZHcDbmlsdwR2aWV3dxxFbGl4aXIuU2VydmVyV2ViLkV4YW1wbGVMaXZldwZyb3V0ZXJ3F0VsaXhpci5TZXJ2ZXJXZWIuUm91dGVydwhyb290X3BpZHcDbmlsdwlyb290X3ZpZXd3HEVsaXhpci5TZXJ2ZXJXZWIuRXhhbXBsZUxpdmV3DGxpdmVfc2Vzc2lvbmgCdwdkZWZhdWx0bggAzCfdj28MzBduBgDyZ50_jwFiAAFRgA.Uz0caxeHacX75ACPHiXwCauvH5UqLy8IeL_8nFYbYMY", "static" => "SFMyNTY.g2gDaAJhBXQAAAADdwJpZG0AAAAUcGh4LUY4d01iNU5ncUd3YkxmT0h3BWZsYXNodAAAAAB3CmFzc2lnbl9uZXdqbgYA8medP48BYgABUYA.GHIf9CeLZEM5prc6LsDUohJAFDja28CCUeHHxGBx29M", "url" => "http://localhost:4000//?_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui&_format=swiftui"}, {#PID<0.5907.0>, #Reference<0.377048611.3259498497.187030>}, %Phoenix.Socket{assigns: %{}, channel: Phoenix.LiveView.Channel, channel_pid: nil, endpoint: ServerWeb.Endpoint, handler: Phoenix.LiveView.Socket, id: nil, joined: false, join_ref: "7", private: %{connect_info: %{session: %{"_csrf_token" => "8xeok9RX8fsM3KesJNS-DDcR"}}}, pubsub_server: Server.PubSub, ref: nil, serializer: Phoenix.Socket.V2.JSONSerializer, topic: "lv:phx-F8wMb5NgqGwbLfOH", transport: :websocket, transport_pid: #PID<0.5907.0>}}
State: #Reference<0.377048611.3259498500.122182>

14:00:31.572 [error] an exception was raised:
    ** (UndefinedFunctionError) function ServerWeb.ExampleLive.SwiftUI.render/1 is undefined (module ServerWeb.ExampleLive.SwiftUI is not available)
        ServerWeb.ExampleLive.SwiftUI.render(%{socket: #Phoenix.LiveView.Socket<id: "phx-F8wMb5NgqGwbLfOH", endpoint: ServerWeb.Endpoint, view: ServerWeb.ExampleLive, parent_pid: nil, root_pid: #PID<0.5913.0>, router: ServerWeb.Router, assigns: #Phoenix.LiveView.Socket.AssignsNotInSocket<>, transport_pid: #PID<0.5907.0>, ...>, flash: %{}, __changed__: %{tickets: true}, live_action: nil, tickets: 0})
        (phoenix_live_view 0.20.14) lib/phoenix_live_view/renderer.ex:73: Phoenix.LiveView.Renderer.to_rendered/2
        (phoenix_live_view 0.20.14) lib/phoenix_live_view/channel.ex:961: anonymous fn/4 in Phoenix.LiveView.Channel.render_diff/3
        (telemetry 1.2.1) /Users/brooklin/Library/Caches/mix/installs/elixir-1.16.2-erts-14.2.2/175d0f6f4a858c1884fc97816cedfab3/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
        (phoenix_live_view 0.20.14) lib/phoenix_live_view/channel.ex:957: Phoenix.LiveView.Channel.render_diff/3
        (phoenix_live_view 0.20.14) lib/phoenix_live_view/channel.ex:554: Phoenix.LiveView.Channel.maybe_call_mount_handle_params/4
        (phoenix_live_view 0.20.14) lib/phoenix_live_view/channel.ex:1178: Phoenix.LiveView.Channel.verified_mount/8
        (phoenix_live_view 0.20.14) lib/phoenix_live_view/channel.ex:84: Phoenix.LiveView.Channel.handle_info/2
warning: no LiveViewNative plugin for :html found
  livebooks/interactive-swiftui-views.livemd#cell:4z43eake44uqtbbp:16: ServerWeb.ExampleLive (module)

warning: no LiveViewNative plugin for :jetpack found
  livebooks/interactive-swiftui-views.livemd#cell:4z43eake44uqtbbp:16: ServerWeb.ExampleLive (module)

@BrooklinJazz reported this and suspects it is happening during reconnects where the QP keeps getting added onto the previous URL on each query param attempt

BrooklinJazz commented 1 month ago

I should mention I think I've seen it grow before, however in this example it was the same length each time

carson-katri commented 1 month ago

Are you still seeing this after #1337

bcardarella commented 1 month ago

@BrooklinJazz can you try updating to main on the kino lib and see if this is still happening?

BrooklinJazz commented 1 month ago

Will do!

BrooklinJazz commented 1 month ago

@bcardarella It seems like it still occurs. I can replicate the problem by just raising an error in Livebook:

defmodule ServerWeb.ExampleLive.SwiftUI do
  use ServerNative, [:render_component, format: :swiftui]

  def render(assigns) do
    ~LVN"""
    <Text>Hello, from LiveView Native!</Text>
    """
  end
end

defmodule ServerWeb.ExampleLive do
  use ServerWeb, :live_view
  use ServerNative, :live_view

  @impl true
  def render(assigns), do: ~H""

  def mount(_params, _session, socket) do
    raise "ERROR"
  end
end
bcardarella commented 1 month ago

That is so strange. I don't see the same in a regular setting. I am not using with an umbrella app so I can test that later but I don't see why the server would be doing this.

carson-katri commented 1 month ago

The fix was on the client side, so you would need to depend on main for liveview-client-swiftui in your Xcode project.

BrooklinJazz commented 1 month ago

Oh, roger! I'll update and test

carson-katri commented 1 month ago

Is this issue still occurring?

BrooklinJazz commented 1 month ago

Apologies for the lack of follow up. I haven't seen the issue since. I think we can close