surface-ui / surface

A server-side rendering component library for Phoenix
https://surface-ui.org
MIT License
2.06k stars 152 forks source link

Elixir 1.15.0 app startup error #694

Closed noozo closed 1 year ago

noozo commented 1 year ago

Describe the bug

With Elixir 1.15.0 a phoenix app using surface will not start up:

** (MatchError) no match of right hand side value: {:error, {~c"no such file or directory", ~c"passion_fruit.app"}}
    (surface 0.11.0) lib/surface.ex:258: Surface.components/1
    (surface 0.11.0) lib/mix/tasks/compile/surface.ex:167: Mix.Tasks.Compile.Surface.run/1
    (mix 1.15.0) lib/mix/task.ex:447: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.15.0) lib/mix/tasks/compile.all.ex:124: Mix.Tasks.Compile.All.run_compiler/2
    (mix 1.15.0) lib/mix/tasks/compile.all.ex:104: Mix.Tasks.Compile.All.compile/4
    (mix 1.15.0) lib/mix/tasks/compile.all.ex:93: Mix.Tasks.Compile.All.with_logger_app/2
    (mix 1.15.0) lib/mix/tasks/compile.all.ex:56: Mix.Tasks.Compile.All.run/1
    (mix 1.15.0) lib/mix/task.ex:447: anonymous fn/3 in Mix.Task.run_task/5

Your Environment

Surface: v0.11.0 LiveView: v0.19.2 Elixir: v1.15.0

msaraiva commented 1 year ago

It seems we can no longer rely on Application.ensure_loaded/1 when running the surface compiler on Elixir v1.15. It appears it only runs successfully when the Elixir compiler, which runs previously, actually compiles something, not when it returns :noop.

I could reproduce this by running mix compile twice on a clean project. The compilation works the first time (since the elixir compiler also runs) but it fails the second time as it now returns :noop. If you change any .ex file and run mix compile again, it works normally.

https://github.com/surface-ui/surface/blob/5f1f4662fd9dbba2f66a690b24764ac7830c94bc/lib/surface.ex#L258

@josevalim this behavior seems inconsistent. I wonder if this was intended or a new bug. In case it was intended, is there any other way around to ensure the module is loaded when running a custom compiler?

For context, I need to load the application (modules) in order to introspect information about the components.

josevalim commented 1 year ago

This is fixed in Elixir main and v1.15 branches. :) So hold on tight!

josevalim commented 1 year ago

Actually, please give main and v1.15 branches a try. It seems this one is slightly different than the one I fixed.

msaraiva commented 1 year ago

I just tried it out using main as well as v1.15 and they both work just fine!

I guess all we have to do is wait for a new release :)

@josevalim thank you! 💜

msaraiva commented 1 year ago

Closing this one as the issue has already been fixed. Confirmed using 1.15.2-otp-26. Thank you again, José!