Link Navigation is too Slow
Unanswered
Tramp ant posted this in #help-forum
Tramp antOP
Hi I am currently building a course lesson navigational component for an LMS.
There I am fetching the lesson syllabus from a third-party application using rest api and map the lessons as below. What I am trying to do is when a user click on lesson I update the url lid query param according to the relavant lesson id. After that I will fetch the lesson data using an api in a separate component.
What I noticed here is, when I click on a Link it takes 3-4s to the current link to get updated with new lid query param. What could be the cause for this and how can I optimize this.
Anyway I didn't see any significant latency on fetching lesson data relevant to the lid once it get update.
There I am fetching the lesson syllabus from a third-party application using rest api and map the lessons as below. What I am trying to do is when a user click on lesson I update the url lid query param according to the relavant lesson id. After that I will fetch the lesson data using an api in a separate component.
What I noticed here is, when I click on a Link it takes 3-4s to the current link to get updated with new lid query param. What could be the cause for this and how can I optimize this.
Anyway I didn't see any significant latency on fetching lesson data relevant to the lid once it get update.
import axios from "axios";
import { redirect } from "next/navigation";
import Link from "next/link";
import React from "react";
const ListLessons = async ({ link }: { link: string }) => {
const result = await axios.get(link, {
auth: {
username: ,
password: ,
},
});
return (
<div className="my-3">
{result.data.map((lesson: any) => (
<div className="my-2">
<Link
className="text-lg hover:text-blue-500"
href={`?lid=${lesson.id}`}
>
{lesson.title.rendered}
</Link>
</div>
))}
</div>
);
};
export default ListLessons;7 Replies
Havana
You could swap the component to be client, and then change the searchparams based on the lesson id
Its much faster, in fact instant
Check the useSearchParams hook
@Havana Check the useSearchParams hook
Tramp antOP
will try out that, any particular reason to happen this with link component. I have seen this issue was raised in different support environments. Some says it only occur in dev environment.
@Tramp ant will try out that, any particular reason to happen this with link component. I have seen this issue was raised in different support environments. Some says it only occur in dev environment.
Havana
Not sure, but my guess is it can take long time, because the components that depend on that search param, re-render.
Another theory, is that it prefetches the page with that certain id, but the issue is, the id is undefined initially, which can cause bugs like this.
Try setting the prefetch to false and let me know if it changes anything
Another theory, is that it prefetches the page with that certain id, but the issue is, the id is undefined initially, which can cause bugs like this.
Try setting the prefetch to false and let me know if it changes anything
In my case, link doesn't take more than 0.3 seconds to navigate
But I never used it for setting searchParams