You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a custom helper in a subexpression and it returns "false" (as interpreted by the with and if helpers, such as when the helper returns an empty object), it gets called twice.
In this scenario, the helper returns an object when a parameter is passed to it, and nothing otherwise.
When the helper returns an object (so it's understood as "true" by the if helper), everything works as expected. However, when the if check fails, the helper is called twice. The entire output of the program looks like:
Called helper
something
Called helper
Called helper
nothing
The same behaviour occurs with a with helper as well, and regardless of if there's an else block or not.
I know that this is not a problem in most cases (as helpers don't usually have demanding code), and my use case (making network requests from within helpers) is not typical, but I think fixing this would be good for performance in general use cases such as HTML templating as well.
The text was updated successfully, but these errors were encountered:
This happens when call_inner returns Ok(None) we treated it as default implementation. To workaround this, you can return Ok(Some(json!(null).into())) for your case.
I will think about to fix this via API change or documentation.
@ilyazzz In #437 I will change the return type of call_inner and remove the Option to avoid misleading of None returns. I wish this is the latest breaking change before 4.0 release.
When using a custom helper in a subexpression and it returns "false" (as interpreted by the
with
andif
helpers, such as when the helper returns an empty object), it gets called twice.Here's a reproducible example of this behaviour:
In this scenario, the helper returns an object when a parameter is passed to it, and nothing otherwise.
When the helper returns an object (so it's understood as "true" by the
if
helper), everything works as expected. However, when theif
check fails, the helper is called twice. The entire output of the program looks like:The same behaviour occurs with a
with
helper as well, and regardless of if there's anelse
block or not.I know that this is not a problem in most cases (as helpers don't usually have demanding code), and my use case (making network requests from within helpers) is not typical, but I think fixing this would be good for performance in general use cases such as HTML templating as well.
The text was updated successfully, but these errors were encountered: