Urgent.News

What's breaking now, across thousands of outlets.

Tech

Using searchParams in a Next.js Page Silently Opts It Out of Static Rendering Too

I wrote earlier about a buried cookies() call silently forcing an entire page into dynamic rendering. searchParams causes the exact same category of behavior, through a completely different, and in some ways more surprising, mechanism, since using it doesn't look like reading anything server-specific at all. Why This One Is Extra Surprising cookies() and headers() at least sound like they're…

Using searchParams in a Next.js page can cause it to be treated as dynamic, even if the page doesn't actually use the query parameters. This is because Next.js checks if a component accepts and reads searchParams, regardless of whether it is used to change the page's output. This can lead to unnecessary dynamic rendering, which can negatively impact caching and performance.

To avoid this issue, check your build output for pages that accept searchParams but don't use it to change the rendered content. If a page doesn't need to vary based on query parameters, simply remove the searchParams prop from the component's type signature or destructuring. If the params are genuinely needed for a small, specific piece of UI, consider using useSearchParams() inside a small client component to handle them without forcing the whole page to be dynamic.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

A/B testing: how to test your test

Source post: https://4thwithme.dev/blog/ab-testing-how-to-test-your-test/ Posts 3 and 4 were about the math: what "significant" actually means, and which test design fits which situation.

More from Monday 14 September →