I would really appreciate any guidance that I can get
After updating to Live View 0.18.3 from 0.16.x the app will no longer compile and there is very little debugging information. I’m sure it has to do with one or more of my components not conforming to the new API, but I have a lot of components and I’m trying to figure out where to start.
live_view code is crashing while passing arguments to for loop . Please log a bug in here - issues .
I realised that if I don’t see a proper error message and see ArgumentError, CaseCondError, etc without a proper context like source file name, line number, etc relating to code from project files - it is a bug in live_view. Happened to me earlier.
If you can’t figure out what is causing this crash - you can fork the project and add some logger statements around the line 1091 to know which component is causing this crash?
Thanks kartheek. I was just coming back to update this post because that’s exactly what I did. I wrapped it in a try…catch and logged the information which allowed me to work through my components and get everything fixed. It took some time to get all of the components working but it’s worth it for the new API which I really like.
tldr; All attributes passed to a Phoenix.Component function that are not either prefixed with phx- , aria- , data-, or are one of the html global elements must be declared with the attr macro.
In most cases my problem was not using the attr macro to declare attributes for function components. I thought the attr macro was just added for new functionality. I did not realize that most attributes must be declared. Since all my components were built before the attr macro, none of them had attributes specified.
Since the error message wasn’t helpful, once I figured out the issue I added some simple logging to the code you mentioned so I could see where the issues were.
I replaced this code:
with something like the following (this is just an example that may need some tweaks, I forget exactly what I used):
try do
for {name, {line, _column, _type_value}} <- attrs,
not (global_attr && __global__?(caller_module, Atom.to_string(name), global_attr)) do
message = "undefined attribute \"#{name}\" for component #{component_fa(call)}"
warn(message, call.file, line)
end
rescue
e ->
IO.puts ~s(
----------------------------------------------------------
#{inspect caller_module}
#{inspect attrs}
-----------------------------------------------------------
)
reraise e, __STACKTRACE__
end