Vue encountering RangeError due to string length inconsistency in specific environments only

My Vue component is currently live in production within a WordPress theme, but I am encountering an error:

jquery.min.js:2 Uncaught RangeError: Invalid string length
    at repeat$1 (vue.js:11398)
    at generateCodeFrame (vue.js:11380)
    at vue.js:11467
    at Array.forEach (<anonymous>)
    at compileToFunctions (vue.js:11464)
    at Vue.$mount (vue.js:11688)
    at Vue._init (vue.js:4901)
    at new Vue (vue.js:4967)
    at HTMLDocument.<anonymous> ((index):234)
    at l (jquery.min.js:2)

Interestingly, when testing the component as a standalone file, no errors occur and everything works perfectly. It seems there may be some differences in the WordPress environment or server that are triggering this error.

Many sources suggest that the error is related to a long string, but without being able to replicate it locally, how can one resolve it? Are there any common pitfalls associated with WordPress integration?

The structure of the component itself is quite simple:

<div v-for="event in events" style="margin: 10px;" v-if="events">
    <button class="accordion" @click="show">
        <a :href="event.url"> Buy Now </a>
        <p v-text="event.name.text"></p>
        <span class="date">{{ event.start.local | date }}</span>
        <span class="capacity" v-if="event.capacity"> Capacity: <span v-text="event.capacity"></span></span>

    </button>

    <div class="panel">
        <div class="accordian-body" v-html="event.description.html"></div>
        <a :href="event.url" class="buy-bottom"> Buy Now </a>
    </div>

</div>
jQuery(document).ready(function($) {

    // Using a basic set of effects
    var vm = new Vue({
        el: '#main',
        data: {
                events: <?php echo json_encode($another); ?>, 
        },

        filters: {
            date: function (value) {
                return moment(value).format("dddd, MMM Do");   
            }
        },
        mounted: function () {

            console.log(this.events);
            this.$nextTick(function () {
                // code that assumes this.$el is in the document

                var acc = document.getElementsByClassName("accordion");
                var i;

                for (i = 0; i < acc.length; i++) {
                    acc[i].onclick = function(){
                        this.classList.toggle("active");
                        this.nextElementSibling.classList.toggle("show");
                    };
                }
            });
        },
        methods:{
            show: function(event){

                var clickedElement = event.target;
                $(clickedElement).siblings('panel').toggle("show");
            }
        }
    });

});

Answer №1

The issue can be deceiving at first glance. A similar situation happened to me, and I traced it back to a glitch within the inline template. Specifically, there was a problematic style tag causing trouble in my own project. Considering your scenario, the root of the problem might lie in the data object. To resolve this, try using a string literal in your events data object like so:

data: {

            events: `<?php echo json_encode($another); ?>`,
    },

Answer №2

Here is the solution for the mentioned error: https://github.com/vuejs/vue/issues/9504

The error in the template causes a JS error due to a bug either in generateCodeFrame() or repeat$1(), which might have been fixed in some way.

Answer №3

Yet Another Situation

The reason for the error in my particular situation was due to duplicating the same HTML attribute.

<div class="awesome wow"
     class="anotherawesome">
</div>

This will result in the same problem occurring.

Resolution

<div class="awesome wow anotherawesome">
</div>

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

Adjust the size of a Div/Element in real-time using a randomly calculated number

Currently, I am working on a script that is designed to change the dimensions of a div element when a button on the page is clicked. The JavaScript function connected to this button should generate a random number between 1 and 1000, setting it as both the ...

If IE's conditional comments are dysfunctional

Could this be a silly question? I feel puzzled by it. I've been using an if IE conditional statement to address some issues in IE6. In the head section, this is what I have: <!--[if lt IE 7] > <script type="text/javascript" src="js/ie6.js" ...

Identifying flex-wrap capabilities across different browsers

Currently, I am developing a project that involves implementing a responsive grid using the flex wrap property. However, since my project needs to support IE9 and older versions of Firefox (version 28 and below), I am in need of a way to determine their ...

Leverage the sync function within the await .then("sync") method in JavaScript

If a synchronous function is called within the .then part of an asynchronous await .then, such as: await asyncFunc(...) .then(res => sendMSG(res)) .catch(err => next(err)); function sendMSG(res){ xyz } The sync function sendMSG i ...

Display information in a paginated format using components

As a newcomer to React, I may use the wrong terms so please bear with me. I am attempting to implement pagination for an array of components. To achieve this, I have divided the array into pages based on the desired number of items per page and stored eac ...

Does angular have a feature comparable to JavaScript's .querySelectorAll()?

I developed an inventory calculator in JavaScript that provides item count based on weight. The calculator has 4 inputs, and now I'm looking to replicate the same functionality using Angular. Is there a method in Angular similar to .querySelectorAll() ...

Employing selenium.isElementPresent in Selenium 1 does not have the capability to identify an element that is dynamically added to the Document Object Model (

After trying out various locators, I have yet to find one that can detect an element that was added to the DOM. Below is my latest attempt at solving this issue: selenium.fireEvent("//button[2]", "click"); waitUntil(new Condition() { @Override pu ...

Tips on scrolling the web page until the desired web element is visible and carrying out necessary tasks

When searching for input, multiple table data is retrieved. A "show as text link" is present in different table rows that needs to be clicked. I wrote a code that works fine in IE on one machine but does not work on a different machine due to variations i ...

Exploring Deeply Nested Routing in Angular

I've been exploring the use of multiple router outlets and encountered an issue. When using the navigateBy function of the router, I am unable to view my child route and encounter an error. However, when I access it via the routerLink in HTML, I get ...

What are the steps to integrate TypeScript into JavaScript code?

How can I import a TypeScript class in a Node CommonJS JavaScript file? When using mongoose in my TypeScript code, I typically do the following: // user.model.ts export const UserModel = model<User>('User', schema); In my JavaScript code: ...

I'm struggling to concentrate and unable to type in the email field

Today while working on a website, I encountered something strange. In the footer section of the site, there is a quick contact form. However, I noticed that in Firefox, I am unable to focus on the email field. Surprisingly, this issue does not occur in Chr ...

Popup showing values that are not defined

I've encountered an issue with tooltips on my bar graph. The tooltips should display the values of boarding and alightings corresponding to each stopname column, but I'm seeing undefined values like this Below is my code snippet: <!DOCTY ...

What is the best way to select a specific button to handle the onSubmit event in a React form with multiple buttons

Imagine having the following HTML structure: <div id="container"></div> <p>Output: <span id="output"></span></p> accompanied by this block of JS code: function otherAction(e) { document.getElementById('output& ...

AngularJS modal not functioning properly after sending $http request

I have successfully implemented a pop-up modal in my Angular page using code from a reliable source. However, when I include a button for an HTTP request on the same page, the functionality of the AngularJS modal stops working after the HTTP request is mad ...

How can I limit auto-search results to a specific city in India on Google Maps?

How can we restrict autosearch to only Pune city in India? I attempted the following: autocomplete.setComponentRestrictions( {'country': ['in']},{'city':['Pune']}); ...

How can you send Django context data to a JavaScript variable?

I need to send each value of the {{ i.nsn }} to the ajax script one by one. {% for i in dibbs %} <p>{{ i.nsn }}</p> {% endfor %} Instead of repeating the ajax script, I want it to function with a single click. <script> var nsn = " ...

JQuery click event does not play nicely with Javascript array splice functionality

When using for loops, I noticed that array.splice doesn't seem to be working as expected. The array remains unchanged. I tried moving things around and found that it still doesn't work in Chrome. var menu =['#men','#wmen',&a ...

Is there a way to incorporate 3D tiles into Vue with cesium integration?

After researching, I set up a vue project that incorporates Cesium. However, when trying to use Cesium in the Vue component, an error stating that 'cesium is not defined' popped up. To address this issue, I included references to Cesium in Vue&a ...

The web server is serving an HTML file instead of the expected JSON response

Is there a way to extract the JSON data from ? I have tried using AJAX but it only retrieves the entire HTML page instead. $.ajax({ url: 'http://www.bartdekimpe.be/anoire/index.php/admin/getGamesUserJson/34', success: function(data) { ...

Master the art of zeroing in on your drawing once it's complete

Please review the Demo and provide instructions on how to enhance the zoom function for Google Maps after the map is drawn. let map; let drawingManager; $(document).ready(function () { const latlng = new google.maps.LatLng(49.241943, -122.889318); ...