r/nextjs • • 17h ago

Are most devs sticking with Next.JS?

34 Upvotes

Hi everyone,

I’ve recently started learning TanStack Start, and it’s great, don’t get me wrong. However, there’s quite a bit of assembly involved. Next.js, on the other hand, seems pretty great to work with due to the many out-of-the-box features it provides.

How’s the mental model of working it with? According to the Stack overflow dev survey, this is one of top complaints.

How has your experience been with Next.js? What are some things you like or dislike about using it?

I’m retired so I mainly still code by hand mostly.


r/nextjs • • 6h ago

Next.js 16 moved caching to opt-in. What changed in your apps after upgrading?

4 Upvotes

Next.js 16 changes how caching works in the App Router. According to the docs, Cache Components are enabled with the cacheComponents flag, and caching is opt-in through the use cache directive. The existing fetch and unstable_cache caching still works as a separate layer while you migrate. The version 16 upgrade guide also says that dynamic, revalidate, and fetchCache route segment exports will error once Cache Components is enabled.

The part I find most worrying is the silent load change. Code that was fast because of implicit caching can start hitting the database on every request, and nothing in the code looks different. Tests can pass while query volume climbs.

For people who have already upgraded, I'd like to hear:

  1. Did you turn on Cache Components all at once or route by route, and what made you choose that approach?
  2. How did you catch query-count or latency regressions before production? Logging, load tests, or something else?
  3. Which cacheLife profiles and tags have worked well, and which ones did you change later?
  4. Did anything break in a way the upgrade guide didn't cover?

r/nextjs • • 14m ago

PSA for Next.js 15 App Router + serverless webhooks: why Math.max(localCount, liveApiCount) silently broke our tiered seat counter

1 Upvotes

Sharing a subtle production bug we just caught on Next.js 15 App Router (deployed serverless on Vercel) in case anyone else is building limited-seat / escalating-tier pricing with payment webhooks.

Our Route Handler (/api/pricing) originally tried to be "resilient" by taking Math.max(localStoreCount, livePaymentApiCount) whenever computing seats sold. It looked safe in local dev and completely fell apart under real webhook traffic for 4 separate reasons:

  1. Duplicate webhook events on a single purchase:

Payment providers routinely fire both payment.succeeded (pay_...) and membership.went_valid (mem_...) for the exact same order. Without deduplicating by order/payment ID and tracking a boolean seatCounted flag, a single checkout incremented our local counter twice.

2. $0 trials, comps, 100%-off coupons, and refunded test orders:

Because Math.max() can never go down, a single refunded test payment or $0 comp membership permanently inflated the seat counter and risked prematurely bumping real buyers into the next price tier.

3. Silent reset to 0 on upstream API timeout:

When the payment API hiccupped, catching the error and falling back to 0 caused the UI to flash "0 sold" (wrong tier price) instead of failing safely.

4. Unbounded pagination silently truncating counts:

Paginating live payments with a hard cap (e.g., 20 pages) without throwing if has_next_page is still true would silently undercount once volume crosses that threshold.

What actually fixed it cleanly in our App Router Route Handlers:

- Treat live paid (> $0, excluding trialing/refunded/void/drafted) upstream payments as the single source of truth (live ?? local, never Math.max).

- Cache lastGoodCounts with a short TTL + 10s AbortSignal timeout; if the upstream API fails AND no valid cache exists, fail closed with HTTP 503 instead of guessing 0.

- In the webhook Route Handler, fail closed with HTTP 503 in production if the webhook signing secret env var is missing, verify HMAC signatures against the raw request body (await req.text()), and make every seat increment strictly idempotent on payment ID.

Curious how others running Next.js App Router on Vercel handle strict transactional counters — do you always push them to Postgres/Redis transactions, or rely on the payment provider's API + short-lived cache when volume is low?


r/nextjs • • 5h ago

next-intl on Next.js 16: /apple-touch-icon.png and /ads.txt returned 500 until we gave not-found metadata an explicit locale

2 Upvotes

The server log gave us this:

Error: Page changed from static to dynamic at runtime /apple-touch-icon.png, reason: headers

The site is a client's B2B catalog on Next 16.2.9 and next-intl 4.13.0 (Cache Components off), every page under app/[locale]/. Paths that aren't real routes and aren't caught by the proxy matcher fall into [locale] with the path segment as the locale. /apple-touch-icon.png, /favicon.png, /ads.txt, /manifest.json, /sitemap_index.xml, /v1 and /trpc all returned 500, for every user agent we tried.

The locale layout already called notFound() for an unknown locale, so that wasn't it. The trouble came a step later. Next resolved [locale]/not-found.tsx's generateMetadata in a separate render, one where setRequestLocale had never run, and the implicit getTranslations("errors") made next-intl read request headers inside an ISR render. That's the 500 where a 404 should have been.

Two things we tried first did nothing. A pass-through root layout with a root not-found gave the same 500 and the same stack, and a locale guard on its own changed nothing either. What worked was making the metadata take params and translate with a locale we choose:

const { locale } = await params
const t = await getTranslations({
  locale: hasLocale(routing.locales, locale) ? locale : routing.defaultLocale,
  namespace: "errors",
})

We also added a hasLocale guard that calls notFound() at the top of the layout's generateMetadata, before any message fetch. On a local build /favicon.png, /ads.txt, /v1 and /trpc/contacts now return 404, and the log has no more "static to dynamic" errors. The apple touch icons return 200 because we copied the site's existing 180x180 icon into public/ for iOS probes that skip the link tag.

One catch: those junk paths now render once and get cached as ISR 404s, so a scanner could grow that cache. We'd filter them in nginx or the proxy.

A curl check on the same site also showed missing pages answering 200. With Cache Components off, a loading.tsx at the [locale] segment makes every route below it stream, and the Next docs say plainly that streamed responses start with a 200. The noindex tag was there, so indexing wasn't hurt, but the status was wrong. We removed the file, and on a local clean build the missing pages now return 404.

The price: the spinner now lives only on the two leaf segments that never call notFound(), so navigation into catalog, product, portfolio and CMS pages lost it.

Curl /ads.txt on your own app and see whether you get 404 or 500.


r/nextjs • • 11h ago

Wrote a guide for deploying a MERN app on a Hostinger VPS (Nginx, PM2, SSL) after fixing a bunch of real mistakes in my own setup

Thumbnail
medium.com
1 Upvotes

I spent a while fighting through a Hostinger VPS deployment for a MERN app: firewall rule ordering, Nginx config mix-ups, the classic "my frontend env changes aren't doing anything" issue. Wrote up everything I ran into along with the actual fixes, covering a brand new deploy, pushing new code to an app that's already live, Nginx as a reverse proxy, free SSL with Certbot, and Redis if you need it.

Sharing it in case it saves someone else the same debugging loop: https://medium.com/@kmahesh18001/how-to-deploy-a-mern-app-on-a-hostinger-vps-nginx-pm2-ssl-8180f7f2f019

Happy to answer questions if something's unclear, or if you hit a different issue on your own setup.


r/nextjs • • 1d ago

Is anyone else feeling like "keeping Next.js patched" has become its own job?

46 Upvotes

Not complaining about the Next.js team, I know they're doing a lot. But I feel like I'm upgrading every other day lately because of some security fix or another, and it's starting to eat into actual dev time.

Is this just how it is now, or have I been unlucky? How do you guys keep up without it taking over your week?

Should we just blame LLM and move on?


r/nextjs • • 1d ago

Moving a site to Next.js: what each redirect option sends (307 vs 308) and how Google reads it

5 Upvotes

If you're moving an existing site to next.js, the redirect layer decides whether google carries the old urls over. the status codes aren't the ones most seo checklists talk about, so here's what each option sends

  • redirect() in a server component or route handler: 307
  • permanentRedirect(): 308
  • redirects in next.config with permanent: true: 308, with permanent: false: 307
  • NextResponse.redirect in proxy: whatever status you pass

How google reads them: its redirect docs list 301 and 308 together as permanent, both signal that the target should become the canonical url. 302, 303 and 307 are temporary, and google is told to keep showing the source url

The trap in a migration is the first line. a moved page handled with redirect() works for every visitor and looks fine in a browser, but it's a 307, so for google the old url is still the one to show

Scale: the next.js docs note that vercel caps next.config redirects at 1,024. past that they suggest a redirect map in a key-value store read from proxy, with a bloom filter in front so you don't do a lookup on every request. vercel also has bulk redirects (csv or json files) meant for large migrations

for those who've moved a few thousand urls: bulk redirects or the proxy + bloom filter route, and why?


r/nextjs • • 2d ago

_next/image 504 gateway timeout when deploying to production nginx server

3 Upvotes

context: upgrading to nextjs 16.4.6, i need to add {unoptimized: true} in next.config.images inside images object. anyone come across this matter?


r/nextjs • • 3d ago

Are your non-technical clients suddenly asking for GitHub access because they want to code with AI?

44 Upvotes

I've had several clients this month asking for access to their GitHub repositories because they want to make changes and do development themselves.

I build with Next.js and Sanity, and these are people with little to no coding experience.
I've never really experienced this before, but suddenly it seems like clients believe AI can help them take over development.

I'm not against it, but even getting them set up with the repo, local environment and everything else takes time.

How are you guys handling this? Do you charge for onboarding and setup, give them access, or simply let them figure it out themselves?


r/nextjs • • 2d ago

I built an ad exchange where indie devs trade ad space instead of buying it

1 Upvotes

r/nextjs • • 4d ago

Question about the Workers free plan

Thumbnail
reddit.com
3 Upvotes

r/nextjs • • 4d ago

Domain driven design

3 Upvotes

Hi all!

I'm building an app with next.js and payload.

This application is growing and I would go for DDD.

Any suggestions on project structure?

I'm eager to read any wise advice.


r/nextjs • • 4d ago

Weekly Showoff Weekly Showoff Thread! Share what you've created with Next.js or for the community in this thread only!

4 Upvotes

Whether you've completed a small side project, launched a major application or built something else for the community. Share it here with us.


r/nextjs • • 5d ago

Tomorrow is Black Friday and I don't trust our ISR pages. What are you checking on a headless store this week?

5 Upvotes

my stack is next.js app router on vercel, storefront api for products and cart.

last year our sale prices went live at midnight but the PDPs were static, so for like 40 min the page showed $89 and the cart showed $59. some people were happy about it lol but most thought the site was broken and leave

this year I moved to on demand revalidation, revalidateTag off the products/update webhook. it worked fine in testing but testing isn't midnight on black friday. if one of those webhooks is late or just never shows up that page stays wrong until something else touches it

I do have a dotcom monitor check running add to cart and checkout every 5 min but it's one test product and it doesn't look at the price on the page, so it wouldn't have caught last year's problem either

plan right now is to setup a script that starts at 12:05 and runs every 10 min. it pulls the 15ish sale PDPs, compares the html price to the storefront api and if they don't match it calls revalidateTag and slacks me. is that overkill? the only other option i can think of is purging everything at midnight and taking the cold starts, which during the busiest hour of the year seems worse

what else should I be looking at? feels like I'm missing something obvious


r/nextjs • • 5d ago

Contentful

2 Upvotes

Are there any good resources to use for learning contentful.


r/nextjs • • 6d ago

How do you decide between SSR, SSG, ISR and CSR in real-world Next.js projects?

Post image
11 Upvotes

I've been exploring different rendering strategies in Next.js, and one thing I've noticed is that choosing the right approach depends heavily on the type of application.

For example:

  • SSG seems ideal for blogs and documentation.
  • SSR makes sense for personalized and frequently changing content.
  • ISR is useful for content-heavy websites where rebuilding everything isn't practical.
  • CSR works well for interactive dashboards and application interfaces.

But in real-world applications, these approaches can overlap.

I'm curious about how other developers approach this.

  1. Do you usually combine multiple rendering strategies in one application?
  2. How do you decide when a page should use server-side data fetching?
  3. Have you experienced performance issues from choosing the wrong rendering strategy?

Interested in hearing practical experiences rather than just theoretical comparisons.


r/nextjs • • 7d ago

How do you decide when a query deserves its own endpoint?

34 Upvotes

In a Next.js app with Supabase I can fetch data in a Server Component, use a Server Action for a mutation or introduce a Route Handler when I need an endpoint. I keep changing my mind about the boundaries. What rule has held up for you as an app grows?


r/nextjs • • 7d ago

Our cart badge went 1, 2, 1 on one tap: TanStack Query keeps a mutation pending through onSuccess

0 Upvotes

We've been reworking the cart of a client's Next.js 16 food-ordering storefront, as design concepts on a staging branch. None of it is in production. Before the rework the add button waited for the server. With Slow 4G emulation that basket POST took 580-1220 ms, though the API itself answers an add in 10-18 ms. After the first add the page then fetched the whole basket again.

On the branch every basket write is a TanStack Query mutation. They all share one mutation scope, so they run one after another and an older answer can't land on top of a newer one. Each answer goes into the cache with setQueryData before the basket id cookie changes, and with a 10-second staleTime the query on the new key takes that basket as fresh. No second GET.

The cart badge adds pieces sent and not yet answered, which it reads with useMutationState filtered to status: "pending". Added lines and every total still come from the server's answer. Piece counts are optimistic; money never is.

The add buttons now react in their onSubmit, as soon as the request goes out. In one variant that took the visible response to a tap from 587-626 ms to 5-28 ms. That was a dev build on localhost, as is the trace below. We haven't measured a production build.

Then we put a DOM MutationObserver on the badge and did a first add to an empty cart on Slow 4G:

""  -> "1"   at 36 ms
"1" -> "2"   at 834 ms
"2" -> "1"   at 865 ms

By 834 ms the answer was in the cache and the new line was counted. The add was still pending, though. TanStack keeps a mutation pending until its onSuccess and onSettled have run, so for those 31 ms the same piece was counted twice: once in the cached lines, once as a pending add.

The fix is a marker per add, kept in the mutation context:

onMutate: () => ({ answered: false }),
onSuccess: (basket, _variants, context) => {
  if (context) context.answered = true;
  qc.setQueryData(basketKey(basket.encoded_id), basket);
  setBasketId(basket.encoded_id);
},

The badge skips answered adds. It reads the flag at render, not inside useMutationState's select, because that select only re-runs on mutation cache events and flipping a field on the context object isn't one. What re-renders the badge is the setQueryData call, through the basket query.

The trace above is from before the fix. We haven't taken a new one, and no test covers it yet.

If your badge sums cached lines and pending mutations, watch it during a first add on a throttled network and see whether it ever reads 2.


r/nextjs • • 8d ago

Server Actions vs Route Handlers in the Next.js App Router: how do you decide which to use for mutations?

15 Upvotes

I use Server Actions for mutations from my own UI (forms, buttons) and Route Handlers for webhooks, third-party calls or a possible mobile app later. I re-check auth inside every action instead of relying only on middleware.

Does this split hold up in production for you, and have Server Actions caused problems beyond simple forms?


r/nextjs • • 8d ago Bravo

What is the best headless CMS for Vercel and NextJS projects optimized for SEO and AI Visiblity?

31 Upvotes

'm building a new marketing site and blog on Next.js, hosted on Vercel, and I'm stuck picking a headless CMS. I need editors to control meta titles, descriptions, canonicals and OG images per page, manage schema like FAQ and Article without touching code, and publish quickly with ISR or on-demand revalidation.

I've looked at Sanity, Contentful, Payload, Storyblok and Hygraph. Sanity looks flexible but needs a lot of setup, Contentful gets expensive fast, and Payload is interesting since it runs inside Next.js, but I'm not sure how well it works for a non-technical content team.

The part I can't figure out is AI visibility. Does the CMS choice actually affect whether ChatGPT, Perplexity or Google's AI Overviews cite your content, or is it all about the writing, schema and server rendering? If you run Next.js on Vercel in production, which CMS did you pick and would you choose it again if SEO and AI search traffic were your main goals?


r/nextjs • • 9d ago

Anyone moved from Firebase to Supabase on a Next js app?

20 Upvotes

Anyone switched from Firebase to Supabase on a Next.js app?

I'm pretty much done with Firebase and Supabase keeps coming up as the replacement. I'd rather hear from people who've actually used it with Next than read another comparison blog post

How does auth work with server components and middleware? Was moving the data over painful? And if you looked at Supabase and went with something else, what did you pick


r/nextjs • • 9d ago

Agentic features in Next.js: where the agent should live and how events reach the browser

0 Upvotes

Adding an agent to a Next.js app raises a few architecture questions that "call the LLM from a route handler" doesn't answer once the agent does real work:

1. Keep the agent as its own TypeScript service. Agent runs can be long, call several tools and wait on a human. That doesn't fit request-scoped handlers with execution time limits. A separate agent service (e.g. built with Mastra) that your app talks to keeps runs alive independently of any single request.

2. Stream events, not just text. The browser needs more than tokens: run started, tool call started and finished, state changed, waiting for approval, run finished or errored. A typed event stream (this is what the AG-UI protocol standardises) lets your components react to each event instead of parsing prose.

3. Sync state both ways. If the agent updates data the page shows, send state snapshots and small deltas rather than re-fetching everything. The user and the agent should never disagree about what's on screen.

4. Make cancellation travel end to end. Closing a stream in the browser isn't the same as stopping a run. Cancellation should reach the agent service, and the UI should show a definite "stopped" state.

5. Put guardrails at the boundary. Validate tool arguments against a schema, time out slow steps, and require explicit approval before anything consequential. Your app is the last place a human can say no.

How are you structuring this today: agents inside route handlers, or as a separate service?

(This comes from a hands-on workshop Rainer Hahnekamp and Murat Sari, co-maintainers of CopilotKit's Angular integration, are running on Saturday, using CopilotKit, AG-UI and Mastra.)


r/nextjs • • 10d ago

Solo technical founder running a startup, looking for an optimal tech setup

Thumbnail reddit.com
0 Upvotes

r/nextjs • • 10d ago

Solo technical founder running a startup, looking for an optimal tech setup

Thumbnail reddit.com
0 Upvotes