Skip to content

Commit bc31337

Browse files
authored
Require LiveView 1.0 at least (#159)
The ErrorTracker assets were compiled against an old (pre 1.0) version of LiveView. This caused issues in applications using LiveView 1.0 and newer. This commit gets rid of the warning about LiveView and ErrorTracker javascript version mismatch. We now follow LiveDashboard and Oban Web footsteps and import the LiveView assets directly.
1 parent 7c02598 commit bc31337

File tree

14 files changed

+69
-83
lines changed

14 files changed

+69
-83
lines changed

assets/bun.lockb

330 KB
Binary file not shown.

assets/js/app.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
// Establish Phoenix Socket and LiveView configuration.
2-
import { Socket, LongPoll } from "phoenix";
3-
import { LiveSocket } from "phoenix_live_view";
1+
// Phoenix assets are imported from dependencies.
42
import topbar from "topbar";
53

64
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content");
7-
let socketPath = document.querySelector("meta[name='socket-path']").getAttribute("content");
8-
let socketTransport = document.querySelector("meta[name='socket-transport']").getAttribute("content");
9-
let normalizedTransport = (socketTransport == "longpoll") ? LongPoll : WebSocket;
5+
let livePath = document.querySelector("meta[name='live-path']").getAttribute("content");
6+
let liveTransport = document .querySelector("meta[name='live-transport']") .getAttribute("content");
107

11-
let liveSocket = new LiveSocket(socketPath, Socket, { transport: normalizedTransport, params: { _csrf_token: csrfToken }});
8+
let liveSocket = new LiveView.LiveSocket(livePath, Phoenix.Socket, {
9+
transport: liveTransport === "longpoll" ? Phoenix.LongPoll : WebSocket,
10+
params: { _csrf_token: csrfToken },
11+
});
1212

1313
// Show progress bar on live navigation and form submits
1414
topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" });

dev.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Mix.install([
66
{:ecto_sqlite3, ">= 0.0.0"},
77
{:error_tracker, path: ".", force: true},
8-
{:phoenix_playground, "~> 0.1.7"}
8+
{:phoenix_playground, "~> 0.1.8"}
99
])
1010

1111
otp_app = :error_tracker_dev

lib/error_tracker/web.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ defmodule ErrorTracker.Web do
6262
```elixir
6363
config :error_tracker,
6464
socket: [
65-
path: "/my-custom-socket-path"
65+
path: "/my-custom-live-path"
6666
transport: :longpoll # (accepted values are :longpoll or :websocket)
6767
]
6868
```

lib/error_tracker/web/components/core_components.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule ErrorTracker.Web.CoreComponents do
2626
]}
2727
{@rest}
2828
>
29-
<%= render_slot(@inner_block) %>
29+
{render_slot(@inner_block)}
3030
</.link>
3131
"""
3232
end
@@ -42,7 +42,7 @@ defmodule ErrorTracker.Web.CoreComponents do
4242
]}
4343
{@rest}
4444
>
45-
<%= render_slot(@inner_block) %>
45+
{render_slot(@inner_block)}
4646
</button>
4747
"""
4848
end
@@ -80,7 +80,7 @@ defmodule ErrorTracker.Web.CoreComponents do
8080
class={["text-sm font-medium me-2 py-1 px-2 rounded-lg ring-1 ring-inset", @color_class]}
8181
{@rest}
8282
>
83-
<%= render_slot(@inner_block) %>
83+
{render_slot(@inner_block)}
8484
</span>
8585
"""
8686
end
@@ -124,9 +124,9 @@ defmodule ErrorTracker.Web.CoreComponents do
124124
:if={assigns[:title]}
125125
class={["text-sm font-semibold mb-2 uppercase text-gray-400", @title_class]}
126126
>
127-
<%= @title %>
127+
{@title}
128128
</h2>
129-
<%= render_slot(@inner_block) %>
129+
{render_slot(@inner_block)}
130130
</div>
131131
"""
132132
end

lib/error_tracker/web/components/layouts.ex

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@ defmodule ErrorTracker.Web.Layouts do
22
@moduledoc false
33
use ErrorTracker.Web, :html
44

5-
@default_socket_config %{path: "/live", transport: :websocket}
5+
phoenix_js_paths =
6+
for app <- ~w[phoenix phoenix_html phoenix_live_view]a do
7+
path = Application.app_dir(app, ["priv", "static", "#{app}.js"])
8+
Module.put_attribute(__MODULE__, :external_resource, path)
9+
path
10+
end
11+
12+
@static_path Application.app_dir(:error_tracker, ["priv", "static"])
13+
@external_resource css_path = Path.join(@static_path, "app.css")
14+
@external_resource js_path = Path.join(@static_path, "app.js")
615

7-
@css_path Application.app_dir(:error_tracker, ["priv", "static", "app.css"])
8-
@js_path Application.app_dir(:error_tracker, ["priv", "static", "app.js"])
16+
@css File.read!(css_path)
917

10-
@external_resource @css_path
11-
@external_resource @js_path
18+
@js """
19+
#{for path <- phoenix_js_paths, do: path |> File.read!() |> String.replace("//# sourceMappingURL=", "// ")}
20+
#{File.read!(js_path)}
21+
"""
1222

13-
@css File.read!(@css_path)
14-
@js File.read!(@js_path)
23+
@default_socket_config %{path: "/live", transport: :websocket}
1524

1625
embed_templates "layouts/*"
1726

@@ -97,7 +106,7 @@ defmodule ErrorTracker.Web.Layouts do
97106
class="whitespace-nowrap flex-0 block py-2 px-3 rounded-lg text-white hover:text-white hover:bg-gray-700 md:hover:bg-transparent md:border-0 md:hover:text-sky-500"
98107
{@rest}
99108
>
100-
<%= render_slot(@inner_block) %>
109+
{render_slot(@inner_block)}
101110
</a>
102111
</li>
103112
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<.navbar id="navbar" {assigns} />
22
<main class="container px-4 mx-auto mt-4 mb-4">
3-
<%= @inner_content %>
3+
{@inner_content}
44
</main>

lib/error_tracker/web/components/layouts/root.html.heex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<meta name="csrf-token" content={get_csrf_token()} />
8-
<meta name="socket-path" content={get_socket_config(:path)} />
9-
<meta name="socket-transport" content={get_socket_config(:transport)} />
8+
<meta name="live-path" content={get_socket_config(:path)} />
9+
<meta name="live-transport" content={get_socket_config(:transport)} />
1010

11-
<title><%= assigns[:page_title] || "🐛 ErrorTracker" %></title>
11+
<title>{assigns[:page_title] || "🐛 ErrorTracker"}</title>
1212

1313
<style nonce={@csp_nonces[:style]}>
1414
<%= raw get_content(:css) %>
@@ -19,6 +19,6 @@
1919
</head>
2020

2121
<body class="bg-gray-800 text-white">
22-
<%= @inner_content %>
22+
{@inner_content}
2323
</body>
2424
</html>

lib/error_tracker/web/live/dashboard.html.heex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@
6464
>
6565
<td scope="row" class="px-4 py-4 font-medium text-white relative">
6666
<.link navigate={error_path(@socket, error, @search)} class="absolute inset-1">
67-
<span class="sr-only">(<%= sanitize_module(error.kind) %>) <%= error.reason %></span>
67+
<span class="sr-only">({sanitize_module(error.kind)}) {error.reason}</span>
6868
</.link>
6969
<p class="whitespace-nowrap text-ellipsis overflow-hidden">
70-
(<%= sanitize_module(error.kind) %>) <%= error.reason %>
70+
({sanitize_module(error.kind)}) {error.reason}
7171
</p>
7272
<p
7373
:if={ErrorTracker.Error.has_source_info?(error)}
7474
class="whitespace-nowrap text-ellipsis overflow-hidden font-normal text-gray-400"
7575
>
76-
<%= sanitize_module(error.source_function) %>
76+
{sanitize_module(error.source_function)}
7777
<br />
78-
<%= error.source_line %>
78+
{error.source_line}
7979
</p>
8080
</td>
8181
<td class="px-4 py-4">
82-
<p>Last: <%= format_datetime(error.last_occurrence_at) %></p>
83-
<p>Total: <%= @occurrences[error.id] %></p>
82+
<p>Last: {format_datetime(error.last_occurrence_at)}</p>
83+
<p>Total: {@occurrences[error.id]}</p>
8484
</td>
8585
<td class="px-4 py-4">
8686
<.badge :if={error.status == :resolved} color={:green}>Resolved</.badge>

lib/error_tracker/web/live/show.html.heex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
<div id="header">
88
<p class="text-sm uppercase font-semibold text-gray-400">
9-
Error #<%= @error.id %> @ <%= format_datetime(@occurrence.inserted_at) %>
9+
Error #{@error.id} @ {format_datetime(@occurrence.inserted_at)}
1010
</p>
1111
<h1 class="my-1 text-2xl w-full font-semibold whitespace-nowrap text-ellipsis overflow-hidden">
12-
(<%= sanitize_module(@error.kind) %>) <%= @error.reason
12+
({sanitize_module(@error.kind)}) {@error.reason
1313
|> String.replace("\n", " ")
14-
|> String.trim() %>
14+
|> String.trim()}
1515
</h1>
1616
</div>
1717

@@ -38,9 +38,9 @@
3838
class="border-b bg-gray-400/10 border-gray-900 last:border-b-0"
3939
>
4040
<td class="w-11 pl-2 py-4 font-medium text-white relative text-right">
41-
<%= length(@occurrence.breadcrumbs) - index %>.
41+
{length(@occurrence.breadcrumbs) - index}.
4242
</td>
43-
<td class="px-2 py-4 font-medium text-white relative"><%= breadcrumb %></td>
43+
<td class="px-2 py-4 font-medium text-white relative">{breadcrumb}</td>
4444
</tr>
4545
</table>
4646
</div>
@@ -95,7 +95,7 @@
9595
value={occurrence.id}
9696
selected={occurrence.id == @occurrence.id}
9797
>
98-
<%= format_datetime(occurrence.inserted_at) %>
98+
{format_datetime(occurrence.inserted_at)}
9999
</option>
100100
</select>
101101
</form>

0 commit comments

Comments
 (0)