Skip to content

Commit bbdec7b

Browse files
committed
Upgrade Phoenix to 1.8, LiveView to 1.1
- Bump phoenix ~> 1.8, phoenix_live_view ~> 1.1, y_ex ~> 0.10.2, oban ~> 2.20, phoenix_storybook ~> 1.0, mix_test_watch ~> 1.4 - Add lazy_html test dependency (required by LiveView 1.1) - Add :phoenix_live_view compiler to mix.exs compilers list - Migrate ErrorView to format-specific ErrorHTML and ErrorJSON modules to match Phoenix 1.7+ conventions; update render_errors config and all put_view call sites across controllers and plugs - Remove dead live routes for SettingsLive.Index and JobLive.Index that LiveView 1.1 now validates at compile time
1 parent cb45eaf commit bbdec7b

20 files changed

Lines changed: 77 additions & 154 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
mix docs
2525
2626
- name: Deploy 🚀
27-
uses: JamesIves/github-pages-deploy-action@v4.7.6
27+
uses: JamesIves/github-pages-deploy-action@v4.8.0
2828
with:
2929
branch: gh-pages # The branch the action should deploy to.
3030
folder: doc # The folder the action should deploy.

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ RUN mix lightning.install_adaptor_icons
6666
RUN mix lightning.install_schemas
6767
RUN npm install --prefix assets
6868

69-
# compile assets
70-
RUN mix assets.deploy
71-
7269
# Compile the release
7370
RUN mix compile
7471

72+
# compile assets
73+
RUN mix assets.deploy
74+
7575
# Changes to config/runtime.exs don't require recompiling the code
7676
COPY config/runtime.exs config/
7777

assets/js/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import * as Sentry from '@sentry/react';
2828
import { enableMapSet } from 'immer';
2929
import { Socket } from 'phoenix';
3030
import { LiveSocket } from 'phoenix_live_view';
31+
import { hooks as colocatedHooks } from 'phoenix-colocated/lightning';
3132

3233
import topbar from '../vendor/topbar.cjs';
3334

@@ -55,6 +56,7 @@ window.sentry = sentry;
5556
const hooks = {
5657
LogViewer,
5758
...Hooks,
59+
...colocatedHooks,
5860
};
5961

6062
// @ts-ignore

config/config.exs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ config :hammer,
2323
config :lightning, LightningWeb.Endpoint,
2424
url: [host: "localhost"],
2525
render_errors: [
26-
view: LightningWeb.ErrorView,
27-
accepts: ~w(html json),
26+
formats: [html: LightningWeb.ErrorHTML, json: LightningWeb.ErrorJSON],
2827
layout: false
2928
],
3029
pubsub_server: Lightning.PubSub,
@@ -101,6 +100,7 @@ config :esbuild,
101100
--external:path
102101
--external:/fonts/*
103102
--external:/images/*
103+
--alias:@=.
104104
js/app.js
105105
js/storybook.js
106106
js/editor/Editor.tsx
@@ -131,7 +131,9 @@ config :esbuild,
131131
end
132132
end),
133133
cd: Path.expand("../assets", __DIR__),
134-
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
134+
env: %{
135+
"NODE_PATH" => [Path.expand("../deps", __DIR__), Mix.Project.build_path()]
136+
}
135137
]
136138

137139
# https://fly.io/phoenix-files/tailwind-standalone/

config/dev.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ config :phoenix, :stacktrace_depth, 20
127127
# Initialize plugs at runtime for faster development compilation
128128
config :phoenix, :plug_init_mode, :runtime
129129

130+
config :phoenix_live_view,
131+
debug_heex_annotations: true,
132+
debug_attributes: true,
133+
enable_expensive_runtime_checks: true
134+
130135
config :lightning, :is_resettable_demo, true
131136

132137
config :lightning, :apollo, endpoint: "http://localhost:3000", timeout: 30_000

lib/lightning_web/components/viewers.ex

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule LightningWeb.Components.Viewers do
1616
import React
1717

1818
alias Lightning.Invocation.Dataclip
19-
alias LightningWeb.Components.Icon
19+
# alias LightningWeb.Components.Icon
2020
alias Phoenix.LiveView.JS
2121

2222
require Lightning.Run
@@ -340,39 +340,6 @@ defmodule LightningWeb.Components.Viewers do
340340
"""
341341
end
342342

343-
attr :id, :string, required: true
344-
345-
attr :type, :atom,
346-
default: nil,
347-
values: [nil | Dataclip.source_types()]
348-
349-
defp dataclip_type(assigns) do
350-
assigns =
351-
assign(assigns,
352-
icon: Icon.dataclip_icon_class(assigns.type),
353-
color: Icon.dataclip_icon_color(assigns.type)
354-
)
355-
356-
~H"""
357-
<div
358-
id={@id}
359-
class={[
360-
"absolute top-0 right-0 flex items-center gap-2 group z-10"
361-
]}
362-
>
363-
<div class="hidden group-hover:block font-mono text-white text-xs">
364-
type: {@type}
365-
</div>
366-
<div class={[
367-
"rounded-bl-md rounded-tr-md p-1 pt-0 opacity-70 group-hover:opacity-100 content-center",
368-
@color
369-
]}>
370-
<.icon :if={@icon} name={@icon} class="h-4 w-4 inline-block align-middle" />
371-
</div>
372-
</div>
373-
"""
374-
end
375-
376343
defp step_finished?(%{finished_at: %_{}}), do: true
377344

378345
defp step_finished?(_other), do: false

lib/lightning_web/controllers/api/provisioning_controller.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ defmodule LightningWeb.API.ProvisioningController do
8787
{:error, error} ->
8888
conn
8989
|> put_status(:forbidden)
90-
|> put_view(LightningWeb.ErrorView)
90+
|> put_view(json: LightningWeb.ErrorJSON)
9191
|> render(:"403",
9292
error:
9393
case error do
Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
defmodule LightningWeb.ErrorView do
1+
defmodule LightningWeb.ErrorHTML do
22
@moduledoc false
33

4-
# This module needs to be changed to use Layouts
5-
use LightningWeb, :view
6-
7-
use Phoenix.Component
4+
use LightningWeb, :html
85

96
def render("404.html", assigns) do
107
~H"""
11-
<.logo_bar conn={@conn} />
8+
<.logo_bar />
129
<div class="min-h-[25em] flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
1310
<div class="max-w-md w-full space-y-6 p-12 rounded-md shadow-md border bg-white">
1411
<div>
@@ -26,7 +23,7 @@ defmodule LightningWeb.ErrorView do
2623

2724
def render("401.html", assigns) do
2825
~H"""
29-
<.logo_bar conn={@conn} />
26+
<.logo_bar />
3027
<div class="min-h-[25em] flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
3128
<div class="max-w-md w-full space-y-6 p-12 rounded-md shadow-md border bg-white">
3229
<div>
@@ -37,7 +34,7 @@ defmodule LightningWeb.ErrorView do
3734
:if={assigns[:error]}
3835
class="mt-4 p-4 text-xs font-mono text-gray-600 border rounded-md bg-gray-200 grid grid-cols-2 gap-2"
3936
>
40-
<%= for {k,v} <- @error do %>
37+
<%= for {k, v} <- @error do %>
4138
<div class="text-right font-bold">{k}</div>
4239
<div>{v}</div>
4340
<% end %>
@@ -48,40 +45,23 @@ defmodule LightningWeb.ErrorView do
4845
"""
4946
end
5047

48+
def render(template, _assigns) do
49+
Phoenix.Controller.status_message_from_template(template)
50+
end
51+
5152
defp logo_bar(assigns) do
5253
~H"""
5354
<nav class="bg-secondary-800">
5455
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
5556
<div class="flex items-center justify-between h-16">
5657
<div class="flex items-center">
5758
<div class="flex-shrink-0">
58-
<img
59-
class="h-8 w-8"
60-
src={Routes.static_path(@conn, "/images/square-logo.png")}
61-
alt="OpenFn"
62-
/>
59+
<img class="h-8 w-8" src={~p"/images/square-logo.png"} alt="OpenFn" />
6360
</div>
6461
</div>
6562
</div>
6663
</div>
6764
</nav>
6865
"""
6966
end
70-
71-
# By default, Phoenix returns the status message from
72-
# the template name. For example, "404.html" becomes
73-
# "Not Found".
74-
def template_not_found(template, assigns) do
75-
if String.match?(template, ~r/.json$/) do
76-
%{
77-
"error" =>
78-
case assigns do
79-
%{error: error} -> error
80-
_ -> Phoenix.Controller.status_message_from_template(template)
81-
end
82-
}
83-
else
84-
Phoenix.Controller.status_message_from_template(template)
85-
end
86-
end
8767
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defmodule LightningWeb.ErrorJSON do
2+
@moduledoc false
3+
4+
def render(_template, %{error: error}) do
5+
%{"error" => error}
6+
end
7+
8+
def render(template, _assigns) do
9+
%{"error" => Phoenix.Controller.status_message_from_template(template)}
10+
end
11+
end

lib/lightning_web/controllers/fallback_controller.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ defmodule LightningWeb.FallbackController do
1010
def call(conn, {:error, :not_found}) do
1111
conn
1212
|> put_status(:not_found)
13-
|> put_view(LightningWeb.ErrorView)
13+
|> put_view(html: LightningWeb.ErrorHTML, json: LightningWeb.ErrorJSON)
1414
|> render(:"404")
1515
end
1616

1717
def call(conn, {:error, :bad_request}) do
1818
conn
1919
|> put_status(:bad_request)
20-
|> put_view(LightningWeb.ErrorView)
20+
|> put_view(html: LightningWeb.ErrorHTML, json: LightningWeb.ErrorJSON)
2121
|> render(:"400")
2222
end
2323

2424
def call(conn, {:error, :unauthorized}) do
2525
conn
2626
|> put_status(:unauthorized)
27-
|> put_view(LightningWeb.ErrorView)
27+
|> put_view(html: LightningWeb.ErrorHTML, json: LightningWeb.ErrorJSON)
2828
|> render(:"401")
2929
end
3030

3131
def call(conn, {:error, :forbidden}) do
3232
conn
3333
|> put_status(:forbidden)
34-
|> put_view(LightningWeb.ErrorView)
34+
|> put_view(html: LightningWeb.ErrorHTML, json: LightningWeb.ErrorJSON)
3535
|> render(:"403")
3636
end
3737

@@ -61,7 +61,7 @@ defmodule LightningWeb.FallbackController do
6161
def call(conn, {:error, error}) when is_map(error) do
6262
conn
6363
|> put_status(:unauthorized)
64-
|> put_view(LightningWeb.ErrorView)
64+
|> put_view(html: LightningWeb.ErrorHTML, json: LightningWeb.ErrorJSON)
6565
|> render(:"401", error: error)
6666
end
6767
end

0 commit comments

Comments
 (0)