Having trouble with script tag not loading content in Next.js, even though it works perfectly fine in React

Currently, I am attempting to utilize a widget that I have developed in ReactJS by utilizing script tags as shown below-

React Implementation

import React from "react";
import { Helmet } from "react-helmet";

const Dust = () => {
  return (
    <div>
      <Helmet>
        <link
          href="https://master--testasdfasdfadsf.netlify.app/widget/index.css"
          rel="stylesheet"
        />
        <script
          async
          src="https://master--testasdfasdfadsf.netlify.app/widget/index.js"
        ></script>
      </Helmet>
    </div>
  );
};

export default Dust;

Everything is functioning well with the above implementation in React JS and I can see the content displayed on my screen.

NextJs Implementation

import Image from "next/image";
import { Inter } from "next/font/google";
import Script from "next/script";
import Head from "next/head";

const inter = Inter({ subsets: ["latin"] });

export default function Home() {
  return (
    <main
      className={`flex min-h-screen flex-col items-center justify-between p-24 ${inter.className}`}
    >
      <Head>
        <link
          href="https://master--testasdfasdfadsf.netlify.app/widget/index.css"
          rel="stylesheet"
        />
      </Head>
      <Script
        src="https://master--testasdfasdfadsf.netlify.app/widget/index.js"
        strategy="lazyOnload"
      />
    </main>
  );
}

Unfortunately, the implementation for Next Js is not working, even though both the JavaScript and CSS files are loading in the network tab. What could be a potential solution for achieving functionality in Nextjs?

Answer №1

After some investigation, I managed to find the answer on my own. It turns out that I had originally created a widget with the id "root" in my index.html file located within the public folder. In order to utilize this widget from a script, it is necessary for there to be an element with the id "root" or any other custom name of your choosing.

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

"Enhancing Your List: A Comprehensive Guide to Editing List Items with the Power of AJAX, jQuery, and

At the moment, I am able to edit a list item by clicking the 'Edit' link. However, I would prefer to simply click on the list item itself to initiate the editing process. This is the content of my _item.html.erb partial. In this case, each proj ...

Effortlessly sleek horizontal navigation bar designed with Liquid CSS

I've been exploring online tutorials to create a responsive horizontal drop-down menu navigation bar using just CSS and HTML. The tutorial process has been smooth so far, but I'm aiming to make my navigation bar fluid so that it adjusts seamlessl ...

Styling with CSS: How to Adjust Word Wrap in a Container that Resizes Dynam

I'm struggling to ensure that long lines of text break and wrap correctly within a chat feature I am developing. The crucial elements in question are .chat__messages__item and .chat__messages__body (these are all contained within a parent element set ...

When using requirejs and vue.js together, the error message "Vue is not defined" may be encountered

My code snippet looks like this: <script type="text/javascript" src="../../node_modules/requirejs/require.js"></script> <script type="text/javascript" src="../../node_modules/vue/dist/vue.js"></script> <script>console.log(Vue ...

Leveraging npm packages within a Meteor project through cosmos:browserify

Trying to implement Radium, a JavaScript library for inline CSS, by following the instructions located here. In my app.browserify.js file: Radium = require("radium"); Within package.json: "radium": "0.13.4" Upon attempting to utilize Radium in the app&a ...

I desire to activate the textbox only when the radiobtnlist value equals 1

I am trying to disable a textbox based on the selected value of a RadioButtonList in my code. However, the functionality is not working as expected and I am unsure why. <script type="text/javascript"> $(function () { $("#RadioButton ...

Uploading a collection of objects to Node.js for storage in a database with Mongoose

I have developed a ReactJS form that allows users to dynamically add form "parts" (sections with form input fields). Let me illustrate this concept with an example: <div> <input placeholder="Author" /> <input placeholder="Age" /> ...

Just outputting props.children in React

Greetings: As a budding React enthusiast, I find myself pondering on the possibilities of creating a component solely dedicated to logic without incorporating any visible elements. Consider the following example: class LogicComponent extends Component { ...

Images that are automatically generated cannot be interacted with by clicking on them

I currently have 4 images loaded onto my website. Whenever I click on one of the images, it becomes highlighted as desired using the following code: JavaScript Function 1 : var ImageSelector = function() { var imgs = null; var selImg = null; retu ...

What criteria does Next.js use to determine which component to display in a layout?

While I've mastered Angular, I'm currently tackling a simple demo in next.js. I can't wrap my head around how next.js (or React, technically) determines which component to display within a layout. Take this example: https://github.com/ver ...

ReactJs: How useEffect is invoked before onClick function in NextJS

I am facing an issue with a button in my Next project. Here is the code for the button: <Button minWidth={'140px'} onClick={() => exec(scope)} >Save</Button> When this button is clicked, it triggers the following function: c ...

Display a loading message before fetching remote data in the Bootstrap modal box

Here is the code I am using to load remote PHP data into a Bootstrap modal box: $(function() { $(window).bind("resize", function() { if ($(this).width() < 400) { $('#tabs-content').removeClass('col-xs-10').ad ...

I am encountering the error message "Utils is not defined" while attempting to generate a chart using chart.js

Attempting to replicate the example provided in chart.js documentation : link to example Unfortunately, I am encountering the error: Uncaught ReferenceError: Utils is not defined Despite its simplicity, I am struggling to identify the issue...! ...

Is there a way to fetch a random record from a MongoDb collection and exhibit all the fields of that haphazardly chosen document in HTML?

In my current project, I am fetching a random document from a MongoDB Collection and attempting to showcase all the fields of that document in HTML. Although I can successfully retrieve a random document, the issue arises when trying to display its fields ...

Discover specific element details using the id with Strapi and React

I am currently studying react with strapi and I have encountered an issue. I have successfully displayed all elements from a database, but I am facing a problem when trying to display specific information on clicking an element. Although I can retrieve t ...

What is the best way to transmit information using the POST method in JavaScript?

When using javascript, the typical way to redirect a page with a parameter is the following: window.location = "add-new-cos.jsp?id="+id; However, the id value is sent to the next page using the GET method. I am interested in sending it using the POST met ...

Is there a way to present both Javascript and templates from parallel directories using express?

QUERY: Is there a way to modify the server.js file so that the three.js script in index.html does not display an error message like Cannot GET /node_modules/three/three.js? Code Snippet: index.html <!DOCTYPE html> <html lang="en"> <head&g ...

Is there a method to detect the presence of a bot in your discord server using another bot?

I am developing my own unique discord bot and I am looking to implement a feature that can determine if a specific bot is present in the server. Here's how I've been approaching it: if (!message.guild.args[0]) In this code, args[0] represents ...

Searching and Substituting Elements with jQuery in a Text String

After making an Ajax call, I have retrieved HTML as a string. headings .... <div class="wrapper"> <input type="text" name="email" value="" /> </div> .... I have extracted the .wrapper and input elements from the HTML string. var el ...

The footer refuses to adhere to the bottom of the page

On the Contact Page of our client's website, there seems to be an issue with the footer not sticking to the bottom of the page and hiding the submit button. https://i.stack.imgur.com/txqAS.png We attempted to fix this using CSS, but it either sticks ...