An issue occurred in the nextTick function: "RangeError: The maximum call stack size has been surpassed" within the ViewTree component

Encountering an issue with selecting children in a tree view, here is the code snippet for my treeview:

<v-treeview
     v-model="selection"
     :items="questionnaires"
     :selection-type="selectionType"
     selectable
     return-object
     open-all
 ></v-treeview>

To populate items and their children, I utilize a computed function:

computed: {
        questionnaires () {
            const children = this.modules.map(module => ({
                id: module.id,
                name: module.MODULE_NOM,
                children: this.getChildren(module.id), <-- facing an issue here 
            }))
            return [{
                id: this.formData.id,
                name: this.formData.QSTAIRE_NOM,
                children,
            },]
        },
    },

When attempting to populate the children of children of a questionnaire, I encounter a stack overflow error:

getChildren(moduleId){
            axios
                .get(`/questionsDemo/${moduleId}`)
                .then(res => {
                    this.questions = res.data.data || [];
                })
                .catch(function(err) {
                    console.log("Error loading questions", err);
                });
            const questions = []
            console.log("Questions",this.questions);
            for (const question of this.questions) {
                console.log(question);
                questions.push({
                    ...question,
                    name: question.QUEST_TEXT,
                })
            }

            return questions.sort((a,b) => {
                return a.name > b.name ? 1 : -1
            })
        },       
    }

So, when trying to select the last children (questions), the following problem arises:

[Vue warn]: Error in nextTick: "RangeError: Maximum call stack size exceeded"

Found in

---> <VTreeviewNode>... (2 recursive calls)
       <VTreeview>
         <VCard>
           <VApp>
             <VContent>
               <VApp>
                 <Layout> at resources/js/components/Layout.vue
                   <Anonymous>
                     <VApp>
                       <App> at resources/js/App.vue
                         <Root>
warn @ app.js:77250
logError @ app.js:78509
globalHandleError @ app.js:78504
handleError @ app.js:78464
(anonymous) @ app.js:78607
flushCallbacks @ app.js:78531
Promise.then (async)
timerFunc @ app.js:78558
nextTick @ app.js:78615
Vue.$nextTick @ app.js:80140
(anonymous) @ app.js:118006
Promise.then (async)
click @ app.js:118004
invokeWithErrorHandling @ app.js:78479
invoker @ app.js:78804
original._wrapper @ app.js:84163
app.js:78513 RangeError: Maximum call stack size exceeded
    at Object.reactiveGetter [as nodes] (app.js:77655)
    at VueComponent.proxyGetter [as nodes] (app.js:81243)
    at VueComponent.getDescendants (app.js:117573)
    at VueComponent.getDescendants (app.js:117577)
    at VueComponent.getDescendants (app.js:117577)
    at VueComponent.getDescendants (app.js:117577)
    at VueComponent.getDescendants (app.js:117577)
    at VueComponent.getDescendants (app.js:117577)
    at VueComponent.getDescendants (app.js:117577)
    at VueComponent.getDescendants (app.js:117577)
logError @ app.js:78513
globalHandleError @ app.js:78504
handleError @ app.js:78464
(anonymous) @ app.js:78607
flushCallbacks @ app.js:78531
Promise.then (async)
timerFunc @ app.js:78558
nextTick @ app.js:78615
Vue.$nextTick @ app.js:80140
(anonymous) @ app.js:118006
Promise.then (async)
click @ app.js:118004
invokeWithErrorHandling @ app.js:78479
invoker @ app.js:78804
original._wrapper @ app.js:84163
app.0a5fabc74150bf603a11.hot-update.js:282 les questions [{…}, __ob__: Observer]

Answer №1

I have come across a few issues.

a) One problem is that you are calling an async method (an axios call) inside a computed property:

children: this.getChildren(module.id), <-- here

According to the Vue guide, it is recommended to use a watcher in this case:

Using the watch option allows us to perform an asynchronous operation (such as accessing an API), control the frequency of the operation, and manage interim states until we receive a final outcome. None of these functionalities are achievable with a computed property.

Alternatively, you can consider trying the vue-computed-async package.

b) In your method where the axios call is made, you are not waiting for the results as the method returns before the promise is resolved or rejected:

      getChildren(moduleId){
                axios
                    .get(`/questionsDemo/${moduleId}`)
                    .then(res => {
                        this.questions = res.data.data || [];
                    })
                    .catch(function(err) {
                        console.log("An error occurred while loading questions", err);
                    });
     
                <!-- FROM HERE YOU ARE NOT WAITING FOR THE THEN BLOCK -->
                const questions = []
                console.log("Questions",this.questions);
                for (const question of this.questions) {
                    console.log(question);
                ....

You can resolve this issue by using await or by moving the subsequent logic inside the then() block.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Secure access with Keycloak authentication in a .NET Core API and Vue.js Single Page Application

Currently, I am utilizing .NET Core for the backend REST API and Vue.js for the frontend. In my current setup, I have implemented authentication through a cookie. However, I am now looking to switch to authenticating via Keycloak. The goal is to have the ...

Tips for transferring a Vuex-stored value to a variable within Vuejs 3 (Quasar 2)

Currently, I have a Vuex store where I am storing a date (referred to as date). In my Vue.js template (using Quasar 2 beta 12), I can easily access this date using {{ date }}. If I make changes to the date in the store, it reflects immediately in the {{ ...

Having trouble with your angular.jg ng controller functioning properly?

Having trouble getting any content to show up from the media object! The plate object seems to be malfunctioning. <!DOCTYPE html> <html lang="en" ng-app="confusionApp"> <head> <meta charset="utf-8"> <met ...

Having trouble retrieving client data on the server-side using Ionic and Express.js

I have a question regarding my Ionic project setup. I have a Node.js and express.js project running on localhost to handle my http requests. When I send data from the client-side to the server-side, the data received looks like this when I log it: { &apos ...

What is the method for striking through a line in a table?

I developed a unique jQuery script: <script type="text/javascript"> $(document).ready(function () { $('tr.inactive').each(function (index) { var tr = $(this); tr.find('td:first').after(function ...

Route is not simply a component in this context. When using Routes, all component children must be either a Route or wrapped within

I am currently working on my App.js file and encountering an issue while creating paths. I have wrapped a Route element around my IsUserRedirect, but the error persists. import React, {Fragment} from 'react'; import * as ROUTES from './cons ...

Please explain the concept of the Node.js event loop

I've spent countless hours poring over guides and resources on the event loop, yet I still can't grasp its essence. It's common knowledge that the libuv library is responsible for implementing the event loop, but what exactly is this entity ...

Vue/Antd radio button group styles not being applied properly due to binding issue

I have encountered a peculiar issue while developing a small Vue component. Initially, when I crafted the HTML for a radio button group, everything functioned flawlessly. However, upon transitioning the code to bind to a data source, although it operated ...

Reposition the checked box to the top of the list

My goal is to click on each item, and the selected item should move to the top of the list and be rendered at the top. However, I encountered an issue where when clicking on an item, it moves to the top but the item that replaces it also gets checked. Bel ...

Attempt to retrieve node information using the useStaticQuery method in Gatsby

I am facing an issue where I am trying to retrieve information from GraphQL Gatsby using useStaticQuery, but the data returned is showing as undefined. I am confused as to why this is happening because when I check my http://localhost:8000/___graphql endpo ...

Apply styles specifically to elements that contain a child element

I have a scenario where there are multiple <p> elements with the same class names, but only one of them has a child element. My objective is to highlight only the <p> that contains a child, however, my current code ends up highlighting all of t ...

Using codeigniter and JQuery, I have developed a unique Javascript function to selectively extract a specific portion of text

I'm currently working with the following syntax: $("#orderbynumber").autocomplete( { source: "get_orders_by_order_number", messages: { noResults: '', results: function() {} }, select: function( event, ui ) { var select ...

Struggling to locate the element for clicking or sending keys in Selenium using Java?

Hi everyone, I'm a new member of this forum and I'm just starting out with coding for the first time. I have encountered an issue with a specific part of my code: md-input-container class="md-default-theme md-input-invalid">> label for="i ...

What could be causing the type error in Vue 3.3 when using a generic v-for key?

My application is built on Vue 3.3.4 with the latest support for generics in single file components. One of the components I'm working on is a generic list, which iterates over a set of items passed as a prop. There is also a prop called itemKey, used ...

Manipulate JQuery plug-in properties within an AJAX request using MVC

Currently, I am utilizing a Jquery time picker sourced from Within the view, there exists this time picker control. $("#startTime").timePicker({ startTime: "09.00", endTime: new Date(0, 0, 0, 19, 0, 0), show24Hours: false, ...

Why does Drupal's Advagg display several css and js files?

After installing the Advag module, I noticed that it is combining files, but there seems to be an issue: <link type="text/css" rel="stylesheet" href="/sites/default/files/advagg_css/css__sqX0oV0PzZnon4-v--YUWKBX0MY_EglamExp-1FI654__IOPiOtulrIZqqAM0BdQC ...

Using a single package manager for both backend and frontend development - is it possible? (Yarn/NPM)

Before, I relied on NPM for server-side tasks and Bower for frontend. NPM would install packages in the node_modules/ directory, while a .bowerrc file directed package installations to public/lib. Recently, I've made the switch to Yarn from NPM, and ...

Seeking assistance in loading the webpage content when the button is clicked

<html> <body> <a href="samepage.php"><img src="button.png"></a> <div> //page content, database queries, calculations etc </div> </body> </html> I'm interested in loading the DIV content dynamicall ...

Redux, Retrieving the entire state rather than just the specified state

Experiencing a strange issue with react-redux. I am receiving all the state data instead of just the specific state that was passed. Here is the code snippet: Action.js import socketIOClient from 'socket.io-client' const DATA_URL = "LINK TO AP ...

Is it possible to incorporate a variable into an object?

If you are wondering whether it is possible to utilize a variable in the following scenario, the reason for my inquiry is connected to the potential of utilizing an input element to dynamically modify the variable: var str = "pineapples" var cost = { pine ...