Page re-renders on navigation within a slug
Unanswered
shadow_aya posted this in #help-forum
NextJS version: 14
Hello. I have a slug page on my website. The reason is that I have two similar pages, and navigating between the two only updates state in a Context, otherwise the two pages have identical structure and purpose:
Some parts of the component(s) sort through a pretty large list, which is expensive, so I did this to avoid re-renders - but they happen anyway.
I verified this by putting a log inside
Any idea how to prevent re-rendering here, or do I have to switch to a URL search parameter?
Hello. I have a slug page on my website. The reason is that I have two similar pages, and navigating between the two only updates state in a Context, otherwise the two pages have identical structure and purpose:
src/app/stratle/[mode]/page.tsx
export default function Page() {
return (
<section className={styles.page}>
<div>
<Inputs />
</div>
<div>
<StratagemPanel />
<Order />
</div>
</section>
);
}
Some parts of the component(s) sort through a pretty large list, which is expensive, so I did this to avoid re-renders - but they happen anyway.
I verified this by putting a log inside
StratagemPanel
's useEffect, and navigation fires it, even in prod. I navigate via next's Link
component.Any idea how to prevent re-rendering here, or do I have to switch to a URL search parameter?
3 Replies
after rethinking this, I don't think this is possible. I added my own solution with
window.history.pushState
, but if someone has a better idea, I'd appreciate any suggestionsFilipino Venus
Hi @shadow_aya
Could you please let me know how you solved the issue with
I'm having a similar issue with you now.
I'm showing products in the same route: /categories/[slug]/[page]/.
When I navigate the pages in the same slug, for example: /categories/apple/1/, /categories/apple/2/, .../categories/apple/10/, etc.
For this reason, I'm losing the previous page's content.
The page is re-rendering because the page param is changing. I know it's impossible to prevent the re-render.
I would like to know how you resolve the issue.
Thanks
Could you please let me know how you solved the issue with
window.history.pushState
?I'm having a similar issue with you now.
I'm showing products in the same route: /categories/[slug]/[page]/.
When I navigate the pages in the same slug, for example: /categories/apple/1/, /categories/apple/2/, .../categories/apple/10/, etc.
For this reason, I'm losing the previous page's content.
The page is re-rendering because the page param is changing. I know it's impossible to prevent the re-render.
I would like to know how you resolve the issue.
Thanks
@Filipino Venus Hi <@319526077506519041>
Could you please let me know how you solved the issue with `window.history.pushState`?
I'm having a similar issue with you now.
I'm showing products in the same route: /categories/[slug]/[page]/.
When I navigate the pages in the same slug, for example: /categories/apple/1/, /categories/apple/2/, .../categories/apple/10/, etc.
For this reason, I'm losing the previous page's content.
The page is re-rendering because the page param is changing. I know it's impossible to prevent the re-render.
I would like to know how you resolve the issue.
Thanks
I "solved" this by entirely scrapping navigation for that route. but I think there's a few approaches
1) layouts could be helpful
2) use components that are selectively memoized
1) layouts could be helpful
2) use components that are selectively memoized