Help Forum I need help in the nextjs 14 version for SSRHtml document is created, but fetch serve
Unanswered
Alligator mississippiensis posted this in #help-forum
Alligator mississippiensisOP
import React, { FC } from 'react';
async function getData(id:any) {
try {
const response = fetch(
const data = (await response).json();
return data;
} catch (error) {
return null;
}
}
const ToDoDetails:FC<any> = async({params}) => {
const data = await getData(params?.id);
if (!data) {
return <div>No data available</div>;
}
return (
<div>
<p>{data?.id}</p>
<p>{data?.title}</p>
</div>
)
}
export default ToDoDetails;
async function getData(id:any) {
try {
const response = fetch(
https://jsonplaceholder.typicode.com/todos/${id});const data = (await response).json();
return data;
} catch (error) {
return null;
}
}
const ToDoDetails:FC<any> = async({params}) => {
const data = await getData(params?.id);
if (!data) {
return <div>No data available</div>;
}
return (
<div>
<p>{data?.id}</p>
<p>{data?.title}</p>
</div>
)
}
export default ToDoDetails;
59 Replies
Polish Hound
but code work fine soo what's wrong?
Alligator mississippiensisOP
I need to fetch the in whole HTML in this response but now this is not HTML format
import React, { FC } from 'react'
const getData = async (id:any) => {
try {
const response = await fetch(
const data = await response.json();
return data;
} catch (error) {
return [];
}
};
const ToDoDetails:FC<any> = async({params}) => {
const data = await getData(params?.id);
console.log(data,'---')
return (
<div>
<p>{data?.id}</p>
<p>{data?.title}</p>
</div>
)
}
export default ToDoDetails;
const getData = async (id:any) => {
try {
const response = await fetch(
https://jsonplaceholder.typicode.com/todos/${id});const data = await response.json();
return data;
} catch (error) {
return [];
}
};
const ToDoDetails:FC<any> = async({params}) => {
const data = await getData(params?.id);
console.log(data,'---')
return (
<div>
<p>{data?.id}</p>
<p>{data?.title}</p>
</div>
)
}
export default ToDoDetails;
Alligator mississippiensisOP
i have a list when i click a particular list shows http://localhost:3000/119?_rsc=1cywn URL has no fetch HTML
Alligator mississippiensisOP
@Polish Hound @Siberian
@Alligator mississippiensis import React, { FC } from 'react';
async function getData(id:any) {
try {
const response = fetch(`https://jsonplaceholder.typicode.com/todos/${id}`);
const data = (await response).json();
return data;
} catch (error) {
return null;
}
}
const ToDoDetails:FC<any> = async({params}) => {
const data = await getData(params?.id);
if (!data) {
return <div>No data available</div>;
}
return (
<div>
<p>{data?.id}</p>
<p>{data?.title}</p>
</div>
)
}
export default ToDoDetails;
They are ?rsc requests, returning the rsc payload not html. The client side router understands the rsc payload format and can use that info to handle client side navigation for you. You don’t need to worry about the content of these requests. They just work™️
Alligator mississippiensisOP
@joulev thanks for responding, but my other website gives me responses in rsc payload in HTML format , so need html in rsc response
Polish Hound
bro give me your live code and tell me what you want?
@Alligator mississippiensis <@484037068239142956> thanks for responding, but my other website gives me responses in rsc payload in HTML format , so need html in rsc response
I don’t get the question here. Why exactly do you need to worry about the requests that the router automatically makes and handles for you? Can just consider them a black box, whatever happens there is the router’s business not yours.
The thing still works right? Then why bother. If it doesn’t work then what is not working?
The thing still works right? Then why bother. If it doesn’t work then what is not working?
Polish Hound
but why you want html response?
@joulev I don’t get the question here. Why exactly do you need to worry about the requests that the router automatically makes and handles for you? Can just consider them a black box, whatever happens there is the router’s business not yours.
The thing still works right? Then why bother. If it doesn’t work then what is not working?
Polish Hound
same why he need html formate response? no need of that ever
Alligator mississippiensisOP
for SEO purpose
@Alligator mississippiensis for SEO purpose
If you disable JS, your <Link> will become pure <a> so crawlers perfectly understand them, SEO is fully good
@Alligator mississippiensis for SEO purpose
Polish Hound
for seo ??? what you
do ?
The rsc payload and client side navigation is only for the users, not for SEO
@Alligator mississippiensis import React, { FC } from 'react';
async function getData(id:any) {
try {
const response = fetch(`https://jsonplaceholder.typicode.com/todos/${id}`);
const data = (await response).json();
return data;
} catch (error) {
return null;
}
}
const ToDoDetails:FC<any> = async({params}) => {
const data = await getData(params?.id);
if (!data) {
return <div>No data available</div>;
}
return (
<div>
<p>{data?.id}</p>
<p>{data?.title}</p>
</div>
)
}
export default ToDoDetails;
Polish Hound
you are never wary about responses your SEO is just fine if you export metadata
Alligator mississippiensisOP
hmm, but my client requirement is that he needs rsc response in HTML format
@Alligator mississippiensis hmm, but my client requirement is that he needs rsc response in HTML format
Tell him that he doesn’t understand how nextjs works then. Or ditch <Link> completely and use <a> just because he wants that
@Alligator mississippiensis hmm, but my client requirement is that he needs rsc response in HTML format
Polish Hound
your client also has requirement to use nextJS?
Alligator mississippiensisOP
He mentioned that other sites provide responses in RSC HTML format, so why doesn't our site? It's showing an empty response.
@Polish Hound your client also has requirement to use nextJS?
Alligator mississippiensisOP
Yes
Polish Hound
can we have you code because i still struggled to figure out you issue 🤔
Alligator mississippiensisOP
import React, { FC } from 'react'
const getData = async (id:any) => {
try {
const response = await fetch(
const data = await response.json();
return data;
} catch (error) {
return [];
}
};
const ToDoDetails:FC<any> = async({params}) => {
const data = await getData(params?.id);
console.log(data,'---')
return (
<div>
<p>{data?.id}</p>
<p>{data?.title}</p>
</div>
)
}
export default ToDoDetails;
const getData = async (id:any) => {
try {
const response = await fetch(
https://jsonplaceholder.typicode.com/todos/${id});const data = await response.json();
return data;
} catch (error) {
return [];
}
};
const ToDoDetails:FC<any> = async({params}) => {
const data = await getData(params?.id);
console.log(data,'---')
return (
<div>
<p>{data?.id}</p>
<p>{data?.title}</p>
</div>
)
}
export default ToDoDetails;
Polish Hound
ok wait i try to figure out
Alligator mississippiensisOP
Okay
Polish Hound
ok so I make the environment now what you need ?
Alligator mississippiensisOP
i need look like this HTML format
@Polish Hound
Polish Hound
hmmm
Polish Hound
hey like this?
Alligator mississippiensisOP
Yes i need like this
@Polish Hound ok so I make the environment now what you need ?
Polish Hound
just dobble click on that ?_rsc=r3yhw
Alligator mississippiensisOP
oh let me check
Polish Hound
@Alligator mississippiensis
Alligator mississippiensisOP
i check in live but when I click, it opens in a new tab, but I need it to open with a single click.
@Polish Hound Click to see attachment
Polish Hound
are check this?
Alligator mississippiensisOP
wait i will share you video
Polish Hound
👍
Alligator mississippiensisOP
now we have to double click, i need a single click like this site
this is doument i have in a document in html but i need a
Polish Hound
so I explained to you that in nextJS when you use RSC ( react server components ) it always retun your code after compilation so it not in html formate
Alligator mississippiensisOP
plaese select fetch not All respone

Polish Hound
The rendered result of Server Components, is not html formate
Alligator mississippiensisOP
how to work on the video I shared with you above, and the complete HTML in rsc
Polish Hound
may be the different framework
?
Alligator mississippiensisOP
no it is a nextjs
Polish Hound
const test = await fetch(
console.log(test);
😁😁😁
http://localhost:3000/);console.log(test);
😁😁😁
Alligator mississippiensisOP
where is added
Polish Hound
/* eslint-disable react-hooks/exhaustive-deps */
"use client";
import React, { useEffect, useState } from "react";
export const ToDoDetails = ({ params }: { params: any }) => {
const [data, setData] = useState<any>(null);
const getData = async (id: any) => {
try {
const response = await fetch(
{
next: { revalidate: 1 },
headers: {
cache: "no-store",
},
}
);
const test = await fetch(
console.log(test);
const data = await response.json();
return data;
} catch (error) {
return [];
}
};
useEffect(() => {
getData(params?.id).then((data) => setData(data));
}, []);
return (
<div>
<p>{data?.id}</p>
<p>{data?.title}</p>
</div>
);
};
"use client";
import React, { useEffect, useState } from "react";
export const ToDoDetails = ({ params }: { params: any }) => {
const [data, setData] = useState<any>(null);
const getData = async (id: any) => {
try {
const response = await fetch(
https://jsonplaceholder.typicode.com/todos/${id},{
next: { revalidate: 1 },
headers: {
cache: "no-store",
},
}
);
const test = await fetch(
http://localhost:3000/);console.log(test);
const data = await response.json();
return data;
} catch (error) {
return [];
}
};
useEffect(() => {
getData(params?.id).then((data) => setData(data));
}, []);
return (
<div>
<p>{data?.id}</p>
<p>{data?.title}</p>
</div>
);
};
i make it client component
Alligator mississippiensisOP
Thanks for responding i will try'