#`IO.inspect(get_connect_params(socket))` always `nil` - Phoenix Liveview `mount`

2 messages · Page 1 of 1 (latest)

spice knoll
#

When I/O inspecting get_connect_params, nil is always returned in local dev.

However, I am setting them when creating the socket:

let liveSocket = new LiveSocket("/live", Socket,
  {
    params: {
      _csrf_token: csrfToken,
      _locale: Intl.NumberFormat().resolvedOptions().locale,
      _timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
      _timezone_offset: -(new Date().getTimezoneOffset() / 60)
    },
    hooks: Hooks
  })

Why is I/O inspect returning nil?

forest owl
#

https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#get_connect_params/1

Connect params are only sent when the client connects to the server and only remain available during mount. nil is returned when called in a disconnected state and a RuntimeError is raised if called after mount.
are you seeing nil because you're looking at the intial http request? When doing a fresh load of a LiveView, it will mount and render twice, the first one is "disconnected" (a plain http request), no JS has run and so no connect params are available. The second mount and render will have them