Got errors with file uploads in Phoenix LiveView 0.18?
Phoenix LiveView 0.18 is out, and it comes with a bunch of cool new features that I’m eager to take advantage of. However, it comes with a few hidden gotchas for upgraders from previous versions…
A couple of them I noticed were around file uploads, and previews of said file uploads.
My form doesn’t do anything when I submit it, anymore…#
tl;dr - upgrade to LiveView 0.18.1.
If you’re seeing nothing happening after submitting a form with a file uploaded in it, but you are seeing JS errors in your console, you’ve probably run into this bug. It’s already been fixed and released in LiveView 0.18.1, so upgrade to that and you’re golden!
But now LiveView crashes when trying to preview an uploaded file 😭#
You might be seeing something like the following:
And that line (in my case, lib/my_app_web/live/components/forms/inputs/file_upload.ex:42) directly maps to my live_img_preview/2 call:
The error doesn’t make a lot of sense, but it is telling you what the problem is - you’re calling a function component, but not in the right way.