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?
1 Reply
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 suggestions