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
The MasterTemplate system does not behave in this way, here a null is passed and this will the placeholders be executed after the actual template has had a chance to run.
Why is this important? Its important if the functions added to the content of the placeholders rely on data in the FunctionContextContainer which is set by the template.
While this works fine for MasterPage templates, the same function no longer works on a RazorTemplate since the FunctionContextContainer it relies on is empty when the function executes.
I can't see what the advantage is to execute all functions when binding the placeholders rather than when our template runs and outputs the content of the placeholders.
The text was updated successfully, but these errors were encountered:
I believe lots of the headaches around FunctionContextContainer could be avoided by removing PageRenderer.GetPageRenderFunctionContextContainer() and make a virtual method on the template-class the same way as we have ie. Configure so the template itself can return the FunctionContextContainer it need for handling its request.
After a lot of digging through the sourcecode i kinda got to wrap my head around whats going on and it seems to point back to this Donut caching which also caused issues here
While its prob. all a very interesting feature, it looks like its enabled by default so while this is not really a bug-bug its more in the category of weird not-production-ready behavior which should clearly have been left as an opt-in experimental feature.
I've worked around it by adding the following to all my Razor functions
public override bool PreventFunctionOutputCaching => true;
burningice2866
changed the title
BUG: Prevent RazorTemplate from executing functions when binding placeholders
Weird behavior: Prevent RazorTemplate from executing functions when binding placeholders
Mar 30, 2023
There is a bug in RazorTemplates where it always executes all functions in content when binding the placeholders.
This happens when FunctionContextContainer is not null, and while we have a check for it in the TemplateDefinitionHelper.BindPlaceholders method, the RazorTemplate always passes an instance of a empty FunctionContextContainer to this function, and therefor are the placeholder content executed as this point.
The MasterTemplate system does not behave in this way, here a null is passed and this will the placeholders be executed after the actual template has had a chance to run.
Why is this important? Its important if the functions added to the content of the placeholders rely on data in the FunctionContextContainer which is set by the template.
While this works fine for MasterPage templates, the same function no longer works on a RazorTemplate since the FunctionContextContainer it relies on is empty when the function executes.
I can't see what the advantage is to execute all functions when binding the placeholders rather than when our template runs and outputs the content of the placeholders.
The text was updated successfully, but these errors were encountered: