Migrating from CB 5 to CB 6.9.0 Helper issue

We are trying to migrate to Coldbox 6.9.0 and I’m having an issue with view Helpers. In Coldbox 5 I can have a renderView of the same view and the Helper file for that view would only get included once. Now in Coldbox 6 the Helper file is getting included every time I renderview and it is causing problems because the Javascript functions located in the Helper are getting included every time.

For CB 5, the Renderer.cfc has a variable called isViewsHelperIncluded which runs the Helper once and then sets that variable to true so that the Helper is not included again.

For CB 6, that functionality was moved to RendererEncapsulator.cfm and it would appear that the variable isViewsHelperIncluded would always be false for each run of renderView and always include the Helper file.

Here is an example of what I’m talking about:
index.cfm
<div>
#renderView(view=“nameToDisplay”, args={name=“Hank”})#
#renderView(view=“nameToDisplay”, args={name=“Frank”})#
#renderView(view=“nameToDisplay”, args={name=“Bob”})#
</div>

nameToDisplay.cfm
<div class=“clickMe”>#args.name#</div>

nameToDisplayHelper.cfm
<script>
$(“document”).ready(function(){
$(“.clickMe”).click(function(){
alert("Hi " + $(this).text());
});
});
</script>

In CB 5, this would allow me to click on each name and the alert would only appear once. In CB 6, I now get the alert three times.

I recognize the fact that I can put that JS in the index.cfm but if I wanted to renderView the nameToDisplay on a different view, I would then have to copy and paste that Javascript and maintain it in multiple locations which is not ideal.

Any help would be greatly appreciated.

There is very likely a better way, however the first thing that comes to mind is to just use a request variable to track if it has ran and wrap the script in a cfif.

<cfparam name="request.nameToDisplayHelperScriptRan" type="boolean" default="false" />
<cfif NOT request.nameToDisplayHelperScriptRan >
    <script>
        $(“document”).ready(function(){
            $(“.clickMe”).click(function(){
                alert("Hi " + $(this).text());
            });
        });
    </script>
    <cfset request.nameToDisplayHelperScriptRan = true >
</cfif>

Thanks for the help.

That code is similar to the concept of what the Renderer.cfc was doing in CB 5. It would keep track of the Helpers that it ran in a struct, and then only include them if they haven’t already been included.

In CB 6, that logic got moved to a cfmodule call to RendererEncapsulator.cfm. The problem with that is that it is no longer keeping track of the Helpers that it has already called. Every time the module is called it is setting a local variable to structNew() so it is always including the Helper.