Issue with TagCloud functionality when deployed on Vercel platform

Everything functions perfectly on my local machine, but once deployed to Vercel, the display disappears. I've double-checked the text, container, and TagCloud - all showing the correct responses. I even tried uninstalling and reinstalling TagCloud without success. I'm at a loss here and unable to troubleshoot further. Any assistance would be greatly appreciated. No errors are reported during the build or in the console.

import TagCloud from "TagCloud";
import { useEffect } from "react";
import "./textphere.css";

export const text = [
  "HTML",
  "CSS",
  "Tailwind",
  "Javascript",
  "Typescript",
  "NodeJS",
  "React",
  "Next JS",
  "Webpack",
  "Docker",
  "Babel",
  "Kubernetes",
  "ES6",
  "NoSQL",
  "SQL",
  "YAML",
  "SSR",
  "CSR",
  "SSG",
  "Stripe API",
  "REST API",
  "Graph QL",
] as string[];

function TextSphere() {
  useEffect(() => {
    return () => {
      const container = document.querySelector(".tagcloud") as any;

      console.log(container);
      console.log(text);
      console.log("TagCloud", TagCloud);

      const options: any = {
        radius: 300,
        maxSpeed: "normal",
        initSpeed: "normal",
        keep: true,
      };

      TagCloud(container, text, options);
    };
  }, []);

  return (
    <div>
      <div className="text-shpere">
        <span className="tagcloud"></span>
      </div>
    </div>
  );
}

export default TextSphere;
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;600;700;800;900&display=swap');

/* container */
.text-shpere {
    padding-top: 20px;
    position: relative;
    top: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgb(250 250 249 / var(--tw-bg-opacity))
}

/* textsphere */
.tagcloud {
    display: absolute;
    top: 0;
    left: 0;
    font-family: 'Inter', sans-serif;
}

/* Change color of each text in sphere on hover   */
.tagcloud--item {
    color: #f1c400;
    text-transform: uppercase;
}

.tagcloud--item:hover {
    color: #ff6347;
}


@media (min-width: 900px) {
    .text-shpere{
        width: 80%;
        height: 70vh;
       
    }
    .tagcloud{
        font-weight: 600;
        font-size: 1rem;
        letter-spacing: 0.0425em;
        right: 5rem
    }
}

@media (min-width: 1200px ){
    .text-shpere{
        padding-top: 10%;
        width: 100%;
    }
    .tagcloud{
        font-size: 1rem;
        transform: scale(1);
        border-radius: 50%;
        line-height: 100px;
    }

}

@media (min-width: 1400px ){

    .tagcloud{
        font-size: 1.5rem;
        transform: scale(1.11);
    }
}

@media (min-width: 1530px ){

    .tagcloud{
        font-size: 1.7rem;
        transform: scale(1.15);   
        margin-left: 80px;     
        padding-top: 40px;
    }
}

@media (min-width: 1900px){
    .tagcloud{
        padding-top: 100px;
    }
} 

Answer №1

Eliminate the "return" statement from the useEffect hook, locally display 2 spheres but only render one in production; this method has proven effective for me

import TagCloud from "TagCloud";
import { useEffect } from "react";
import "./textphere.css";

export const text = [
  "HTML",
  "CSS",
  "Tailwind",
  "Javascript",
  "Typescript",
  "NodeJS",
  "React",
  "Next JS",
  ...and more
] as string[];

function TextSphere() {
  useEffect(() => {
      const container = document.querySelector(".tagcloud");

      console.log(container);
      console.log(text);
      console.log("TagCloud", TagCloud);

      const options = {
        radius: 300,
        maxSpeed: "normal",
        initSpeed: "normal",
        keep: true
      };

      TagCloud(container, text, options);
  }, []);

  return (
    <div>
      <div className="text-shpere">
        <span className="tagcloud"></span>
      </div>
    </div>
  );
}

export default TextSphere;

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

Displaying components conditionally based on whether the user is authenticated

I am currently facing a challenge in my web application related to conditional rendering based on the user's authentication status. The Page component should display either the NotLoggedHome or LoggedHome component depending on the user's state. ...

When receiving JSON and attempting to store the data in a variable, I encounter an issue where it returns the error message "undefined is not iterable (cannot read property Symbol

I'm currently integrating the Advice Slip API into my project. I am experiencing an issue when trying to store the JSON data in a variable like so: let advice; fetch("https://api.adviceslip.com/advice").then(response => response.json()). ...

"An error stating 'Unexpected token '<', '<!DOCTYPE'... is indicating that the JSON is not valid" has been encountered while using Next.js

I'm working on a Next.js project and have implemented a password reset form like the example below: After users enter their email, a POST request is sent to the /api/request-password-reset route: import { NextRequest, NextResponse } from "next/s ...

Utilizing the array result obtained from the fetch function

Seeking assistance with a coding issue. I am puzzled as to why I am unable to utilize the data returned from an API call outside of its function, even though there are no errors occurring. The fetchUser function successfully retrieves the data from the API ...

Tips for creating consistent spacing between elements using Tailwind CSS version 3

I am currently utilizing Tailwind CSS in conjunction with next.js for my project. I have a total of 8 images, each varying in size, and my goal is to display 4 images per row on medium and large devices, while displaying 2 images per row on small devices. ...

What could be causing the need to restart the server every time a style change is made?

I'm currently developing a NextJS application that utilizes PurgeCSS. It's quite frustrating because every time I tweak the classname of a component, I have to restart the server. Here is a snippet from my postcss.config.js: plugins: [ [ ...

Struggling to convert my VueJS component from JavaScript to TypeScript, feeling a bit lost

I am new to VueJS and I am facing a challenge converting my VueJS project to use TypeScript. I have been trying to bind functions to certain variables in JavaScript, but I am struggling with accomplishing the same in TypeScript. Even though there are no er ...

Bring in numerous variables into a Gatsby component using TypeScript and GraphQL Typegen

import { graphql } from 'gatsby'; const Footer = ({phone}: { phone?: Queries.FooterFragment['phone'];}): JSX.Element => { return <footer>{phone}</footer>; }; export default Footer export const query = graphql` fragm ...

I am unable to access the properties of an undefined element, specifically the 'size' property in Next.js 13

I encountered a problem today while working with Next.js version 13.4 and backend integration. When using searchParams on the server side, I received an error message: "Cannot read properties of undefined (reading 'size')" while destructuring siz ...

Guide on how to connect several Subjects within an object literal to their corresponding Observables in another object literal

I am currently developing a class using Angular and I need to share multiple states associated with that class. To accomplish this, I have created several instances of BehaviorSubject private subjects = { a : new BehaviorSubject<A>(this.a), b ...

Error message: The content of the webpage does not align with the server-rendered HTML

I'm currently working on setting up next.js with Azure AD B2C using the MSAL (React) library. The MSAL library provides a convenient component called <MsalAuthenticationTemplate /> to handle authentication. To demonstrate this, I created a basi ...

A problem arises when using the visibility:hidden property with the useEffect hook in Next JS

Having trouble with the CSS property visibility: hidden; in combination with useEffect. I created a basic component containing two divs, each with text. My goal is to split the letters and wrap them in individual span elements. This function works as expec ...

Nextjs server needs to restart for updates from getServerSideProps to reflect

Initially, I believed that using getServerSideProps would automatically update the data whenever the page is reloaded. However, in my specific scenario, this does not seem to be the case. In the situation where an admin accesses this page, a button will a ...

Angular: utilizing input type="date" to set a default value

Looking for a way to filter data by date range using two input fields of type "date"? I need these inputs to already display specific values when the page loads. The first input should have a value that is seven days prior to today's date, while the ...

The axios GET request failed to return a defined value

My current issue involves making a get request using the following code snippet: router.get('/marketUpdates',((request, response) => { console.log("market updates"); var data: Order[] axios.get('http://localhost:8082/marketUpdates& ...

What is the reason behind the NgForOf directive in Angular not supporting union types?

Within my component, I have defined a property array as follows: array: number[] | string[] = ['1', '2']; In the template, I am using ngFor to iterate over the elements of this array: <div *ngFor="let element of array"> ...

Suggestions for importing by Typescript/VS Code

Imagine you have a file called a.ts that contains 4 named imports: export const one = 1 export const two = 2 export const three = 3 export const four = 4 Next, you have a file named b.ts and you want to import some variables from a.ts. import {} from &a ...

Discovering the breakpoints for Angular ng-bootstrapUncover the angular ng

Utilizing ng-bootstrap in my latest project has allowed me to easily create a grid with breakpoints, like so: <div class="row"> <div class="col-sm-12 col-md-6 col-xl-4"></div> </div> Although these breakpoints are convenient, ...

How can I implement a user and admin dashboard toggle in my Next.js application effectively?

Seeking guidance on implementing different user flows post-login in a web application. Currently, I am utilizing a method where upon successful validation, the user is categorized as an admin or regular user based on their token. Administrators are direc ...

Seeking assistance with managing Yarn workspaces

My current project involves working on a React Native application for a client. After I had already written a significant amount of code, my client requested a new feature to be added. This feature should have been simple to implement, but due to the compl ...