Skip to content

Commit 9a3f3d0

Browse files
green-davidSteffenDE
authored andcommitted
Address review comments
1 parent d1eddec commit 9a3f3d0

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ jobs:
173173

174174
runs-on: ubuntu-latest
175175
container:
176-
image: mcr.microsoft.com/playwright:v1.56.1-jammy
176+
image: mcr.microsoft.com/playwright:v1.58.0-jammy
177177
env:
178178
ImageOS: ubuntu22
179179
HOME: /root

lib/phoenix_live_view/colocated_css.ex

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ defmodule Phoenix.LiveView.ColocatedCSS do
182182
{scope, data} = extract(opts, text_content, meta)
183183

184184
# we always drop colocated CSS from the rendered output
185-
{:ok, "", data, [root_tag_attribute: {"phx-css", scope}]}
185+
{:ok, "", data, [root_tag_attribute: {"phx-css-#{scope}", true}]}
186186
end
187187

188188
def transform(_ast, _meta) do
@@ -192,9 +192,8 @@ defmodule Phoenix.LiveView.ColocatedCSS do
192192
defp validate_phx_version! do
193193
phoenix_version = to_string(Application.spec(:phoenix, :vsn))
194194

195-
if not Version.match?(phoenix_version, "~> 1.8.0-rc.4") do
196-
# TODO: bump message to 1.8 once released to avoid confusion
197-
raise ArgumentError, ~s|ColocatedCSS requires at least {:phoenix, "~> 1.8.0-rc.4"}|
195+
if not Version.match?(phoenix_version, "~> 1.8.0") do
196+
raise ArgumentError, ~s|ColocatedCSS requires at least {:phoenix, "~> 1.8.0"}|
198197
end
199198
end
200199

@@ -234,10 +233,10 @@ defmodule Phoenix.LiveView.ColocatedCSS do
234233
# _build/dev/phoenix-colocated-css/otp_app/MyApp.MyComponent/line_no.css
235234
target_path = Path.join(target_dir(), inspect(meta.env.module))
236235

237-
scope = scope(meta)
236+
scope = scope(text_content, meta)
238237
root_tag_attribute = root_tag_attribute()
239238

240-
upper_bound_selector = ~s|[phx-css="#{scope}"]|
239+
upper_bound_selector = ~s|[phx-css-#{scope}]|
241240
lower_bound_selector = ~s|[#{root_tag_attribute}]|
242241

243242
lower_bound_selector =
@@ -266,11 +265,15 @@ defmodule Phoenix.LiveView.ColocatedCSS do
266265
{scope, filename}
267266
end
268267

269-
defp scope(meta) do
270-
hash("#{meta.env.module}_#{meta.env.line}")
268+
defp scope(text_content, meta) do
269+
hash("#{meta.env.module}_#{meta.env.line}: #{text_content}")
271270
end
272271

273272
defp hash(string) do
273+
# It is important that we do not pad
274+
# the Base32 encoded value as we use it in
275+
# an HTML attribute name and = (the padding character)
276+
# is not valid.
274277
string
275278
|> then(&:crypto.hash(:md5, &1))
276279
|> Base.encode32(case: :lower, padding: false)

test/phoenix_live_view/colocated_css_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ defmodule Phoenix.LiveView.ColocatedCSSTest do
152152
file_contents = File.read!(style)
153153

154154
file_contents =
155-
Regex.replace(~r/phx-css=".+?"/, file_contents, ~s|phx-css="SCOPE_HERE"|)
155+
Regex.replace(~r/\[phx-css-.+?\]/, file_contents, ~s|[phx-css-SCOPE_HERE]|)
156156

157157
# The scope is a generated value, so for testing reliability we just replace it with a known
158158
# value to assert against.
159159
assert file_contents ==
160-
~s|@scope ([phx-css="SCOPE_HERE"]) to ([phx-r]) { \n .sample-class { background-color: #FFFFFF; }\n }|
160+
~s|@scope ([phx-css-SCOPE_HERE]) to ([phx-r]) { \n .sample-class { background-color: #FFFFFF; }\n }|
161161

162162
# now write the manifest manually as we are in a test
163163
Phoenix.LiveView.ColocatedCSS.compile()
@@ -217,12 +217,12 @@ defmodule Phoenix.LiveView.ColocatedCSSTest do
217217
file_contents = File.read!(style)
218218

219219
file_contents =
220-
Regex.replace(~r/phx-css=".+?"/, file_contents, ~s|phx-css="SCOPE_HERE"|)
220+
Regex.replace(~r/\[phx-css-.+?\]/, file_contents, ~s|[phx-css-SCOPE_HERE]|)
221221

222222
# The scope is a generated value, so for testing reliability we just replace it with a known
223223
# value to assert against.
224224
assert file_contents ==
225-
~s|@scope ([phx-css="SCOPE_HERE"]) to ([phx-r] > *) { \n .sample-class { background-color: #FFFFFF; }\n }|
225+
~s|@scope ([phx-css-SCOPE_HERE]) to ([phx-r] > *) { \n .sample-class { background-color: #FFFFFF; }\n }|
226226

227227
# now write the manifest manually as we are in a test
228228
Phoenix.LiveView.ColocatedCSS.compile()

0 commit comments

Comments
 (0)