+ Start a Discussion
Andy Kallio 7Andy Kallio 7 

Maximum call stack size exceeded force:refreshview

Hello friends. I'm a junior developer and running into the following error: 
Uncaught Action failed: c:pdfDI_SelectTemplate2$controller$refresh [Maximum call stack size exceeded]
My project is to generate visualforce pdfs with these lightning components. So the main body of the component you see below is a picklist where the user will select the vfpage to be rendered as pdf. And the child component is just an inframe that will then display the selected pdf. All of that is working nicely but I noticed that if the record is edited then the pdf is not refreshed. So, I had a go with force:refreshview which gives me the error. I also found a suggestion for location.reload() but that refreshes the entire page. Hoping someone out there can help me solve this error.  Thanks!!
Here is my code:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId,force:hasSObjectName,lightning:isUrlAddressable" 
    <aura:attribute name="selectedTemplate" type="String"/>
    <aura:attribute name="templateOptions" type="List"/>
    <aura:attribute name="simpleRecord" type="Object"/> 
    <aura:attribute name="vfPage" type="String"/>
    <aura:handler event="force:refreshView" action="{!c.refresh}" />
    <force:recordData aura:id="recordLoader"
        fields="Name, RecordTypeId"
    <lightning:layout multipleRows="false">
        <lightning:layoutItem size="6">
        	<div class="row">
                <aura:if isTrue="{!v.templateOptions != null}">
                    <ui:inputSelect class="single" aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}">
                        <option value="">...Select a Template...</option>
                        <aura:iteration items="{!v.templateOptions}" var="t_opt" indexVar="key">
                            <ui:inputSelectOption text="{!t_opt.value}" label="{!t_opt.key}"/>
    	<lightning:layoutItem size="6">
        <div class="slds-p-left_large">
    	 	<lightning:button label="Save PDF" title="Save PDF" onclick="{! c.savePDF }"/>
	<div class="slds-p-top_large">
        <p>PDF Preview:</p>
    	<c:pdfDI_DisplayTemplate selectedTemplate="{!v.selectedTemplate}" recordId2="{!v.recordId}" vfPage="{!v.vfPage}"/>
    refresh : function(component, event, helper) {
    handleRecordUpdated: function(cmp, event, helper) {
        var eventParams = event.getParams();
        if(eventParams.changeType === "LOADED") {
            var actionVF = cmp.get("c.getVFPage");
                sObjectName : cmp.get("v.sObjectName"),
                recordTypeId : cmp.get("v.simpleRecord.RecordTypeId")
            actionVF.setCallback(this, function(response) {
                var stateVF = response.getState();
            	if(stateVF == "SUCCESS") {
                	var vfpage;
                    vfpage = response.getReturnValue();
                    cmp.set("v.vfPage", vfpage);
           // Send action off to be executed
            //get template options
            var actionComp = cmp.get("c.getTemplateOptions");
                sObjectName : cmp.get("v.sObjectName"),
                recordTypeId : cmp.get("v.simpleRecord.RecordTypeId")
            // Add callback behavior for when response is received
            actionComp.setCallback(this, function(response) {
                var state = response.getState();
                if (state === "SUCCESS") {
                    var custs = [];
                    var conts = response.getReturnValue();
                    for(var key in conts) {
                        custs.push({value:conts[key], key:key});
                else {
                    console.log("Failed with state: " + state);
            // Send action off to be executed
        } else if(eventParams.changeType === "CHANGED") {
        } else if(eventParams.changeType === "REMOVED") {
            // record is deleted
        } else if(eventParams.changeType === "ERROR") {
            var errors = response.getError();
            console.log('errors '+errors);
    onSingleSelectChange: function(cmp) {
        var selectCmp = cmp.find("InputSelectSingle");
        cmp.set("v.selectedTemplate", selectCmp.get("v.value"));
    savePDF : function(cmp, event, helper) {
        var recordId = cmp.get("v.recordId");
        var selectedTemplate = cmp.get("v.selectedTemplate");
        var qName = cmp.get("v.simpleRecord.Name");
        var pdfName = selectedTemplate;
        var vfPage = cmp.get("v.vfPage"); 
        var action = cmp.get("c.savePDF_Quote");
            "vfPage": vfPage, 
            "recordId" : recordId, 
            "selectedTemplate" : selectedTemplate, 
            "pdfName" : qName
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                alert('Attachment saved successfully');
            else if (state === "INCOMPLETE") {
                // do something
                else if (state === "ERROR") {
                    var errors = response.getError();
                    if (errors) {
                        if (errors[0] && errors[0].message) {
                            console.log("Error message: " + 
                    } else {
                        console.log("Unknown error");