Despite setting SSR to true, the NextJS Dynamic Component fails to render in server-side rendering

It seems like there might be a misunderstanding about how the next/dynamic components function. For example, when the code is written like this:

const RealContent = dynamic(() => import('./RealContentComponent'), {
  loading: () => <span>...placeholder Not Real Content...</span>,
  ssr: true,
}) 

One would expect that on the server-rendered HTML file, the <RealContent/> component would display what's in the ./RealContentComponent file.

However, after running next build and checking the

.next/server/pages/RealContent.html
page, only the span with ...placeholder Not Real Content is visible.

Shouldn't setting ssr: true force the actual component to render during build time? (Considering there are no client-dependent elements in the RealContentComponent)

Answer №1

After investigation, it seems that the issue lies within our code. To demonstrate how it functions, I have created a sample repository which showcases the solution... https://github.com/Chenzo/dynamic-ssr-test

If you enable Server-Side Rendering (SSR): True, it will render correctly when executing npm run build

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

when a statement has multiple conditions

I have a situation where I need to verify three conditions: sheet_exists = 1 recalc = 1 qty_total and new_qty_total are not equal Everything works fine when I only use the first two arguments in the if statement: if(sheet_exists === 1 && recal ...

when the keyboard appears on mobile, ensure that the input element is in focus

Is there a way to automatically scroll the page/form to focus when a user clicks on an input field and the keyboard pops up? I want the input field to be displayed within the current view. I've attempted two solutions, but neither seems to be effecti ...

Problem with jQuery datetimepicker plugin not being identified as a date by Date() object wrapper

I have a component that allows users to select a date and time using the datetimepicker plugin found at this link. Here is my current configuration: $('#startDate').datetimepicker({ format: 'Y-m-d\\TH:i:s', }); When I c ...

What is the best way to change the content of a table cell by clicking on a link?

I am dealing with a table that has data in three columns. The first two columns contain just one or two words each, but the third column contains around 1000 characters. I want to be able to toggle the visibility of this third column's data when click ...

Retrieve the ID of the button that was chosen

Hello, I have a card with 3 selectable buttons as described below. <ul class="nav nav-tabs border-0" role="tablist" id="FlightType" onclick="SelectedFlightType()"> <li cla ...

Enveloping elements with jQuery

I am currently utilizing AJAX with jQuery to retrieve some HTML content, and here is the success function: function handleSuccess(response) { var searchTerm = $("#input").val(); // Convert string of HTML to object var anchors = $('<d ...

I have a parent DIV with a child DIV, and I am looking to use jQuery to select the last child DIV. The parent DIV has an

In my HTML code, I have a parent div called "allcomments_4" which contains several child divs with unique IDs (oneEntry), each with their own children. My goal is to locate and retrieve the content inside the last child of the parent node (lastComment) and ...

Sharing data from a Provider to a function in React can be done through various methods

After developing an NPM library that contains various utility functions, including one for calling endpoints, I encountered a roadblock when trying to set the Axios.create instance globally. Initially, my idea was to create a Provider and establish a cont ...

Using JavaScript within PHP Functions

My JavaScript function works like this: $.msgBox({ title:"msgbox", content:"whatever" }); I am trying to use it inside a PHP Function. This is what I attempted: function MsgBox(){ echo'<script type="text/javascript ...

Retrieving the date and toggle button functionality on a React JS stepper

I'm currently developing a table reservation application for a restaurant that utilizes the Stepper component from Material UI. The first step involves selecting a date and an available table to proceed with the reservation process. However, I encount ...

What is the best way to store a set of tuples in a collection so that each tuple is distinct and

I am working with TypeScript and aiming to create a collection of unique objects, each with distinct properties. The combinations of these properties within the collection must be one-of-a-kind. For example, the following combinations would be considered ...

Difficulty with CasperJS multi-select functionality

I am currently attempting to utilize CasperJS for choosing both options in a multiple select within an HTML form: <select id="bldgs" name="bldgs" multiple="multiple" size="6" autocomplete="off"> <option value="249759290">Southeast Financia ...

Creating a jQuery function that replaces specific tags or keywords with a link tag

I am looking to implement a feature where I can highlight or replace matching tags/keywords in the main text of an article and convert those matches into clickable links. An example link format is shown below: en/search.aspx?language=en-US&issue=1& ...

Adjust the background hue within PNotify

I've integrated the Porto Admin Theme into my website, which can be found at This theme utilizes PNotify for notifications, available at: I'm looking to customize the notification colors in a light pastel scheme when choosing "Bootstrap 4" or B ...

Is it possible for Typescript to encounter an error when using console.log() with a variable of type "any"?

When using console.log(variable: any) in Typescript, I am concerned about potential errors and avoiding the need for try{}catch blocks throughout my code. Will console.log(any) trigger any errors or will it successfully print any input provided? public ...

How can I utilize JSON data to retrieve information using D3 library?

Currently, I am experimenting with learning D3 JS and endeavoring to create a bar chart using real-time data fetched from the openweather API. My aim is to display the City Name along with its corresponding temperature at the time of the query. However, a ...

The function User.find does not exist and it is not possible to replace the `users` model after it has

Currently, I am experimenting with using mongoose, mongoDB, next, and express in a test project. Despite referencing solutions like Cannot overwrite model once compiled Mongoose and others, I am encountering issues unique to my situation. Upon initializat ...

Place the values of an array into separate HTML textboxes

I am looking to display exam results for individuals from a Google spreadsheet. I have managed to find some code and develop an additional HTML page that successfully shows the desired outcome when I click the SHOW link. The app script is as follows: var ...

Error when importing 'useState' from 'react' in Next.js with Framer Motion: "Attempted import error: 'useState' is not exported from 'react' (imported as 'useState')"

In the midst of my next.js project, I decided to incorporate framer-motion. As a newbie to this technology, I encountered an obstacle during the installation and utilization of framer-motion. My goal was to create a motion.div component and implement it in ...

Are you initiating several Ajax requests simultaneously?

What is the best approach to updating multiple sections of a page using Ajax? I am working with two divs and two PHP files. My goal is to use jQuery Ajax to populate one div with data received from one PHP file and the other div with data from the second ...