I recently encountered an issue where a partial or functional component was re-rendered multiple times, resulting in an inline function call being executed multiple times as well. This led to multiple database requests instead of just one. The problem was challenging to debug. I initially had some flaky tests and discovered that the issue was not related to render_async
which was my first suspect. Instead, something else was happening with my live view. Using an IO.puts
call, I found that my function was called six times instead of the expected single call.
I resolved the problem by assigning the specific assigns my function call depended on, rather than using {assigns}
when rendering the partial.
My question for the Elixir community is: Is there a way to trace and debug such scenarios? I’m aware of :dbg
and the possibility of mocking function calls using mox
or similar tools. However, I’m wondering if there’s an existing library that allows setting expectations about function calls and asserting on them.