Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behavior: Prevent RazorTemplate from executing functions when binding placeholders #824

Open
burningice2866 opened this issue Mar 30, 2023 · 2 comments

Comments

@burningice2866
Copy link
Contributor

burningice2866 commented 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.

@burningice2866
Copy link
Contributor Author

burningice2866 commented Mar 30, 2023

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.

@burningice2866
Copy link
Contributor Author

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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant