<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Nando Husni — Web Dev Notes]]></title><description><![CDATA[Nando Husni — Web Dev Notes]]></description><link>https://nandohusni.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 24 Nov 2026 13:15:17 GMT</lastBuildDate><atom:link href="https://nandohusni.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Next.js 16 renamed middleware.ts to proxy.ts: the errors you'll hit and how to fix them]]></title><description><![CDATA[Next.js 16 deprecates middleware.ts for proxy.ts: the codemod, the build errors you'll hit and what changes at runtime, tested on 16.4.6.]]></description><link>https://nandohusni.hashnode.dev/next-js-16-renamed-middleware-ts-to-proxy-ts-the-errors-you-ll-hit-and-how-to-fix-them</link><guid isPermaLink="true">https://nandohusni.hashnode.dev/next-js-16-renamed-middleware-ts-to-proxy-ts-the-errors-you-ll-hit-and-how-to-fix-them</guid><category><![CDATA[Next.js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Nando Septian Husni]]></dc:creator><pubDate>Tue, 24 Nov 2026 12:28:00 GMT</pubDate><content:encoded><![CDATA[<p>If you upgrade to Next.js 16 and still have a <code>middleware.ts</code>, the build prints this:</p>
<pre><code class="language-text">⚠ The "middleware" file convention is deprecated. Please use "proxy" instead.

  To migrate automatically, run:
  npx @next/codemod@canary middleware-to-proxy .

  Learn more: https://nextjs.org/docs/messages/middleware-to-proxy
</code></pre>
<p>It still builds, so it's easy to ignore. But the rename is more than a new file name: the runtime changes too, and a few common setups break in ways the warning doesn't mention.</p>
<p>I tested every step below on a fresh <code>create-next-app</code> project with <strong>Next.js 16.4.6 and React 19.3.0</strong>, using <code>next build</code> and <code>next start</code>, plus curl and Playwright to check the responses. All errors are copied from real builds.</p>
<h2>1. What changed in Next.js 16</h2>
<p>From the <a href="https://nextjs.org/docs/app/api-reference/file-conventions/proxy">proxy.js docs</a> and the <a href="https://nextjs.org/docs/app/guides/upgrading/version-16">version 16 upgrade guide</a>:</p>
<ul>
<li>The file is now <code>proxy.ts</code> (or <code>.js</code>), in the same place as before: the project root, or <code>src/</code> if you use it.</li>
<li>The function is exported as <code>proxy</code> (named) or as a default export.</li>
<li>Proxy always runs on the <strong>Node.js runtime</strong>. The <code>runtime</code> config option is not allowed.</li>
<li>Config flags with "middleware" in the name are renamed, for example <code>skipMiddlewareUrlNormalize</code> becomes <code>skipProxyUrlNormalize</code>.</li>
</ul>
<p>The reason given in the docs: "middleware" was often confused with Express.js middleware, and the Next.js team wants this feature used as a last resort. "Proxy" describes what it is: a layer in front of your app that runs before routes render.</p>
<h2>2. Migrate with the codemod</h2>
<p>Commit your work first, then run:</p>
<pre><code class="language-bash">npx @next/codemod@canary middleware-to-proxy .
</code></pre>
<p>On my test project it renamed <code>middleware.ts</code> to <code>proxy.ts</code> and renamed the function. Nothing else changed:</p>
<pre><code class="language-ts">// proxy.ts
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function proxy(request: NextRequest) {
  if (!request.cookies.has("session")) {
    return NextResponse.redirect(new URL("/login", request.url));
  }
}

export const config = {
  matcher: "/dashboard/:path*",
};
</code></pre>
<p>After <code>next build</code> and <code>next start</code>, the behavior was the same as before the rename:</p>
<pre><code class="language-text">no cookie:   307 -&gt; http://localhost:3100/login
with cookie: 200
</code></pre>
<h2>3. Two build errors when you rename by hand</h2>
<p>If you only run <code>mv middleware.ts proxy.ts</code> and keep <code>export function middleware</code>, the build fails:</p>
<pre><code class="language-text">./proxy.ts
Error: Proxy is missing expected function export name
This function is what Next.js runs for every request handled by this proxy (previously called middleware).
</code></pre>
<p>Rename the function to <code>proxy</code>. A default export also works: <code>export default function middleware()</code> in <code>proxy.ts</code> built without errors in my test, but the upgrade guide recommends naming it <code>proxy</code> anyway.</p>
<p>The second error comes from copying the file instead of moving it, or from a merge that brings the old file back:</p>
<pre><code class="language-text">Error: Both middleware file "./middleware.ts" and proxy file "./proxy.ts" are detected. Please use "./proxy.ts" only.
</code></pre>
<p>Delete <code>middleware.ts</code>. You can't keep both.</p>
<h2>4. Delete the <code>runtime</code> option</h2>
<p>Many middleware files have <code>runtime: "edge"</code> or <code>runtime: "nodejs"</code> in their config. Both fail in <code>proxy.ts</code>.</p>
<p>With <code>runtime: "edge"</code>:</p>
<pre><code class="language-text">Error: Next.js can't recognize the exported `config` field in route. Proxy does not support Edge runtime.
</code></pre>
<p>With <code>runtime: "nodejs"</code>:</p>
<pre><code class="language-text">Error: Route segment config is not allowed in Proxy file at "./proxy.ts". Proxy always runs on Node.js runtime.
</code></pre>
<p>Keep only <code>matcher</code> in the config. If you need the Edge runtime, the upgrade guide says to keep using <code>middleware.ts</code> for now, since the Edge runtime is not supported in proxy.</p>
<h2>5. Node.js APIs work now (a staging password example)</h2>
<p>Because proxy runs on Node.js, you can import Node modules without any config. Here is a small password gate for a staging site using <code>timingSafeEqual</code> from <code>node:crypto</code>:</p>
<pre><code class="language-ts">// proxy.ts
import { timingSafeEqual } from "node:crypto";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

function safeEqual(a: string, b: string) {
  const ab = Buffer.from(a);
  const bb = Buffer.from(b);
  return ab.length === bb.length &amp;&amp; timingSafeEqual(ab, bb);
}

export function proxy(request: NextRequest) {
  const expected =
    "Basic " + Buffer.from(process.env.STAGING_AUTH ?? "").toString("base64");
  const given = request.headers.get("authorization") ?? "";

  if (!process.env.STAGING_AUTH || safeEqual(given, expected)) {
    return NextResponse.next();
  }

  return new NextResponse("Authentication required", {
    status: 401,
    headers: { "WWW-Authenticate": 'Basic realm="staging"' },
  });
}

export const config = {
  matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
};
</code></pre>
<p>I built without <code>STAGING_AUTH</code>, then started the server with <code>STAGING_AUTH="team:s3cret" npx next start</code>. The proxy read the variable at request time:</p>
<pre><code class="language-text">no auth:          401
wrong pass:       401
right pass:       200
css without auth: 200
</code></pre>
<p>When <code>STAGING_AUTH</code> is not set, the site stays open, so local development isn't blocked. Basic auth sends the password with every request, so use it only over HTTPS and only as a staging gate, not as your app's login.</p>
<p>For comparison, I put the same code in <code>middleware.ts</code> (function renamed back to <code>middleware</code>, no runtime option). The build passed with this warning:</p>
<pre><code class="language-text">Warning: A Node.js module is loaded ('node:crypto' at line 1) which is not supported in the Edge Runtime.
</code></pre>
<p>At runtime, every request returned <strong>500</strong>, and the server log showed:</p>
<pre><code class="language-text">Error: Failed to load external module node:crypto: TypeError: Native module not found: node:crypto
</code></pre>
<p>So if your old middleware avoided Node APIs because of the Edge runtime, the rename to proxy lets you drop those workarounds.</p>
<h2>6. Keep the proxy away from your CSS</h2>
<p>This one isn't new in Next.js 16, but it's the bug I see most in auth redirects. Without a <code>matcher</code>, proxy runs on every request, including <code>/_next/static</code> files. This version redirects everything to <code>/login</code>:</p>
<pre><code class="language-ts">// proxy.ts (broken: no matcher)
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function proxy(request: NextRequest) {
  const { pathname } = request.nextUrl;
  if (pathname !== "/login" &amp;&amp; !request.cookies.has("session")) {
    return NextResponse.redirect(new URL("/login", request.url));
  }
}
</code></pre>
<p>The login page loads, but its stylesheet request gets redirected too. Playwright on <code>/login</code>:</p>
<pre><code class="language-text">CSS responses: [ '307 /_next/static/chunks/0-ziarbb9nbg_.css', '200 /login' ]
h1 computed: { fontSize: '32px', color: 'rgb(0, 0, 0)' }
</code></pre>
<p>The <code>h1</code> has <code>text-4xl text-blue-600</code>, but it rendered in the browser's default 32px black because the CSS never arrived. The fix is a negative matcher, as the docs recommend:</p>
<pre><code class="language-ts">export const config = {
  matcher: ["/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|webp)$).*)"],
};
</code></pre>
<p>After rebuilding:</p>
<pre><code class="language-text">CSS responses: [ '200 /_next/static/chunks/0-ziarbb9nbg_.css' ]
h1 computed: { fontSize: '36px', color: 'lab(44.0605 29.0279 -86.0352)' }
</code></pre>
<p><code>/dashboard</code> still redirected to <code>/login</code>, and <code>/next.svg</code> and <code>/favicon.ico</code> returned 200.</p>
<p>One more point from the docs: Server Functions are POST requests to the route where they are used, so a matcher that skips a path also skips the Server Functions on it. Check auth inside each Server Function as well, not only in proxy.</p>
<h2>7. Static export ignores proxy.ts</h2>
<p>Proxy is not supported with <code>output: "export"</code>. The build doesn't fail, though. With <code>proxy.ts</code> in place, it finished and printed:</p>
<pre><code class="language-text">⚠ Statically exporting a Next.js application via `next export` disables API routes and middleware.
</code></pre>
<p>The <code>out/</code> folder contained <code>dashboard.html</code> and no proxy code. On GitHub Pages, Cloudflare Pages or any static host, that "protected" page is public. If you deploy a static export, move redirects and headers to your host's config (for example <code>_redirects</code> and <code>_headers</code> on Cloudflare Pages) and don't rely on proxy for anything.</p>
<h2>8. Rename the config flags too</h2>
<p>Old flag names don't break the build, but they print a warning. With <code>skipMiddlewareUrlNormalize: true</code> in <code>next.config.ts</code>:</p>
<pre><code class="language-text">⚠ `skipMiddlewareUrlNormalize` is deprecated. Please use `skipProxyUrlNormalize` instead in next.config.ts.
</code></pre>
<p>Search your config for "middleware" and rename what you find.</p>
<h2>Wrapping up</h2>
<p>The short checklist:</p>
<ol>
<li>Run <code>npx @next/codemod@canary middleware-to-proxy .</code> (or rename the file and the function yourself).</li>
<li>Delete the old <code>middleware.ts</code>.</li>
<li>Remove <code>runtime</code> from the config. If you need Edge, stay on <code>middleware.ts</code> for now.</li>
<li>Add a matcher that skips <code>_next/static</code>, <code>_next/image</code> and public files.</li>
<li>If you use static export, remember proxy doesn't run there.</li>
<li>Rename <code>skipMiddlewareUrlNormalize</code> and similar flags.</li>
</ol>
<p>What did your middleware do that you're now moving to proxy: auth, redirects, i18n, or something else?</p>
<p><em>I keep checks like these as free, MIT-licensed agent skills for Next.js launches:</em> <code>npx skills add nandot12/nextjs-launch-skills</code> · <a href="https://github.com/nandot12/nextjs-launch-skills">GitHub</a></p>
]]></content:encoded></item><item><title><![CDATA[A Black Friday checklist for your Next.js landing page (tested on Next.js 16)]]></title><description><![CDATA[Seven checks before sharing a deal link: discount codes in checkout URLs, UTM tags, cache headers, share images, placeholder links and the banner.]]></description><link>https://nandohusni.hashnode.dev/a-black-friday-checklist-for-your-next-js-landing-page-tested-on-next-js-16</link><guid isPermaLink="true">https://nandohusni.hashnode.dev/a-black-friday-checklist-for-your-next-js-landing-page-tested-on-next-js-16</guid><category><![CDATA[Next.js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[React]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Nando Septian Husni]]></dc:creator><pubDate>Sat, 21 Nov 2026 12:51:47 GMT</pubDate><content:encoded><![CDATA[<p>Black Friday traffic comes in short bursts. Someone shares your link in a newsletter, a deals list or a group chat, a few hundred people click within an hour, and most of them have never seen your site before. They decide fast, so small problems cost more that week than any other.</p>
<p>I went through my own Next.js landing page before adding a Black Friday code and wrote down what I checked. Every code sample below was built and tested in a static-export project on Next.js 16.4.6 and React 19.3.</p>
<h2>1. Put the discount code in the link</h2>
<p>Every extra step at checkout loses buyers, and "copy this code, then paste it at checkout" is two steps. The common hosted checkouts can pre-fill the code from the URL:</p>
<table>
<thead>
<tr>
<th>Checkout</th>
<th>Link with the code applied</th>
</tr>
</thead>
<tbody><tr>
<td>Gumroad</td>
<td><code>https://you.gumroad.com/l/product/CODE</code></td>
</tr>
<tr>
<td>Lemon Squeezy</td>
<td><code>https://store.lemonsqueezy.com/checkout/buy/VARIANT_ID?checkout[discount_code]=CODE</code></td>
</tr>
<tr>
<td>Stripe Payment Links</td>
<td><code>https://buy.stripe.com/...?prefilled_promo_code=CODE</code></td>
</tr>
</tbody></table>
<p>One Stripe catch, from <a href="https://docs.stripe.com/payment-links/promotions">their docs</a>: by default, Payment Links create guest customers for one-time payments, so a promotion code limited to first-time orders won't work as expected. Try your exact code in test mode before you share the link.</p>
<p>Keep the code and the end date in one file, so the banner and every buy button agree:</p>
<pre><code class="language-ts">// src/config/deal.ts
export const deal = {
  code: "BF40",
  label: "40% off until Dec 1",
  endsAt: "2026-12-02T00:00:00Z", // first moment the deal is over
};

type Provider = "gumroad" | "lemonsqueezy" | "stripe";

/** Adds the discount code to a checkout link while the deal is on. */
export function checkoutUrl(base: string, provider: Provider, now = new Date()) {
  if (now &gt;= new Date(deal.endsAt)) return base;
  if (provider === "gumroad") {
    const url = new URL(base);
    url.pathname = `${url.pathname.replace(/\/$/, "")}/${deal.code}`;
    return url.toString();
  }
  const param = provider === "stripe" ? "prefilled_promo_code" : "checkout[discount_code]";
  return `${base}${base.includes("?") ? "&amp;" : "?"}${param}=${deal.code}`;
}
</code></pre>
<p>A buy button then uses <code>checkoutUrl("https://you.gumroad.com/l/product", "gumroad")</code>. After the end date the same call returns the plain link (with one catch for static exports, covered in #7).</p>
<h2>2. Tag every link you share</h2>
<p>In a deal week you share the same page in many places. Links opened from email apps and chat apps often arrive without a referrer, so your analytics count them as direct visits. UTM tags fix that:</p>
<pre><code class="language-text">https://your-site.com/?utm_source=newsletter&amp;utm_medium=email&amp;utm_campaign=bf2026
https://your-site.com/?utm_source=x&amp;utm_medium=social&amp;utm_campaign=bf2026
https://your-site.com/?utm_source=deals-list&amp;utm_medium=referral&amp;utm_campaign=bf2026
</code></pre>
<p>Plausible, Umami and GA4 group visits by these tags. Keep the values short, lowercase and consistent.</p>
<p>The sale itself happens on the checkout's domain, where your analytics can't see it. Send an event when someone clicks a buy button, then compare those clicks with the sales in your checkout dashboard.</p>
<h2>3. Let browsers cache your build files</h2>
<p>Next.js puts a content hash in every file name under <code>/_next/static/</code>, so the file at a given URL never changes. Static hosts don't know that. By default, Cloudflare Pages sends <code>Cache-Control: public, max-age=0, must-revalidate</code> (<a href="https://developers.cloudflare.com/pages/configuration/serving-pages/">docs</a>), which makes the browser ask the server about every file on every visit. I checked my own demo site while writing this, and its hashed CSS file came back with exactly that header.</p>
<p>Cloudflare Pages and Netlify read a <code>_headers</code> file from the output folder. Put it in <code>public/</code> and the static export copies it into <code>out/</code>:</p>
<pre><code class="language-text"># public/_headers
/_next/static/*
  Cache-Control: public, max-age=31536000, immutable
</code></pre>
<p>Leave HTML pages on the default, so a new deploy (including the one that removes your banner) shows up right away. First visits don't get faster, but people who come back to compare before buying, which is common in a deal week, skip a round trip for every file. GitHub Pages doesn't support custom headers.</p>
<p>After you deploy, check one file:</p>
<pre><code class="language-bash">curl -sI https://your-site.pages.dev/_next/static/chunks/&lt;file&gt;.css | grep -i cache-control
</code></pre>
<h2>4. Check the share card on the live URL</h2>
<p>Most deal traffic comes from a shared link, so the preview card is the first thing people see. In a static export, a generated <code>app/opengraph-image.tsx</code> is written as <code>out/opengraph-image</code>, with no file extension, and static hosts then serve it without a <code>Content-Type</code>. I ran into this on Cloudflare Pages and <a href="https://dev.to/nandot12/4-nextjs-16-traps-that-break-static-exports-og-images-and-blog-routes-3104">wrote it up here</a>.</p>
<p>The simplest fix is to open the generated image in your browser, save it, and commit it as <code>app/opengraph-image.png</code>. Static files keep their extension. Then check the live URL:</p>
<pre><code class="language-bash">curl -sI https://your-site.pages.dev/opengraph-image.png | grep -i content-type
</code></pre>
<p>Before you post, paste the URL into a draft on each platform you plan to use and look at the preview.</p>
<h2>5. Preload the hero image (Next.js 16 changed the prop)</h2>
<p>If the hero image is the largest thing above the fold, it's your Largest Contentful Paint. Next.js 16 deprecated <code>priority</code>. The <a href="https://nextjs.org/docs/app/api-reference/components/image">Image docs</a> say to use <code>preload</code> for the same behavior, or <code>loading="eager"</code> if you only need to turn off lazy loading:</p>
<pre><code class="language-tsx">&lt;Image
  src="/hero.png"
  alt="Dashboard showing this week's signups"
  width={1200}
  height={800}
  sizes="(min-width: 1024px) 50vw, 100vw"
  preload
/&gt;
</code></pre>
<p>Use <code>preload</code> on one image, the hero, not on every image.</p>
<p>Then measure the production build, not <code>next dev</code>:</p>
<pre><code class="language-bash">npx next build &amp;&amp; npx serve out
npx lighthouse http://localhost:3000 --only-categories=performance --view
</code></pre>
<p>Lighthouse emulates a mid-range phone by default, which is closer to someone tapping your link in a chat app than your laptop is.</p>
<h2>6. Crawl for placeholder links</h2>
<p>Templates ship with <code>href="#"</code> links and example email addresses, and you stop seeing them after looking at your own page for a while. This is a crawl of my landing page template's demo:</p>
<pre><code class="language-text">$ node link-check.mjs http://localhost:4321
link-check: 1 page(s) crawled, 18 internal link target(s), 2 external link(s)
WARNING  [placeholder] Placeholder email mailto:hello@driftly.example.com   (on /)
WARNING  [placeholder] 13 placeholder link(s) with href="#" — point them somewhere real or remove them   (on /)
0 error(s), 2 warning(s)
</code></pre>
<p>On a demo, that's expected. On your real launch page, each of those is a click that goes nowhere. If you don't have a crawler, a grep on the export finds the same things:</p>
<pre><code class="language-bash">grep -rhoE 'href="#"|[a-z0-9.-]*example\.(com|org|net)' out --include=*.html | sort | uniq -c
</code></pre>
<pre><code class="language-text">      4 driftly.example.com
     13 href="#"
</code></pre>
<h2>7. Make the banner end on time</h2>
<p>In a static export, server code runs once, at build time. So this check is frozen into the HTML:</p>
<pre><code class="language-tsx">const dealIsOn = new Date() &lt; new Date(deal.endsAt);
</code></pre>
<p>If nobody deploys after the deal ends, the banner stays up and keeps advertising a code that no longer works. The <code>checkoutUrl</code> links from #1 keep the code for the same reason.</p>
<p>I use two fixes together. First, the banner hides itself in the browser once the end date has passed:</p>
<pre><code class="language-tsx">// src/components/deal-banner.tsx
"use client";

import { useSyncExternalStore } from "react";
import { deal } from "@/config/deal";

const endsAt = Date.parse(deal.endsAt);
const subscribe = () =&gt; () =&gt; {};

export function DealBanner() {
  // Server snapshot: shown in the prerendered HTML.
  // Client snapshot: hidden in the browser once the deal is over.
  const live = useSyncExternalStore(subscribe, () =&gt; Date.now() &lt; endsAt, () =&gt; true);
  if (!live) return null;

  return (
    &lt;div role="region" aria-label="Black Friday offer" className="bg-black px-4 py-2 text-center text-sm text-white"&gt;
      {deal.label} with code &lt;strong&gt;{deal.code}&lt;/strong&gt;
    &lt;/div&gt;
  );
}
</code></pre>
<pre><code class="language-tsx">// in your page
{dealIsOn &amp;&amp; &lt;DealBanner /&gt;}
</code></pre>
<p><code>useSyncExternalStore</code> takes a separate snapshot for the server render. The prerendered HTML includes the banner, so nothing shifts while the deal runs, and the browser removes it after <code>endsAt</code> without a hydration error. I tested it with Playwright's clock set before and after the end date: shown, then gone, and no console errors either time.</p>
<p>Second, deploy again the day after the deal so the banner and the codes in the links leave the HTML too. Put that deploy on your calendar now, and give the code the same end date in your checkout dashboard.</p>
<h2>The short version</h2>
<ul>
<li>Discount code pre-filled in every buy link, tested in test mode</li>
<li>UTM tags on every link you share, and a click event on the buy button</li>
<li><code>_headers</code> with a one-year cache for <code>/_next/static/*</code></li>
<li>Share image served with an image <code>Content-Type</code> on the live URL</li>
<li>Hero image uses <code>preload</code>, measured on the production build</li>
<li>No <code>href="#"</code> or <code>example.com</code> left</li>
<li>Banner hides itself after the end date, and a redeploy is on the calendar</li>
</ul>
<h2>My own deal</h2>
<p>Disclosure: this checklist comes from two things I sell, and both are 40% off with code <code>BF40</code> until Dec 1, 2026:</p>
<ul>
<li><strong>Next.js Launch Skills</strong>: 13 agent skills for Claude Code, Cursor and Codex that run most of these checks (SEO, share images, cache headers, Lighthouse, a link crawl) and fix what they find. $9.99 → $5.99. <a href="https://nandohusni.gumroad.com/l/nextjs-launch-skills/BF40?referrer=https://hashnode.com">Open with the code applied</a></li>
<li><strong>Liftoff</strong>: a Next.js 16 and Tailwind CSS landing page kit for SaaS products, with a guide to ship it in a day. $29 → $17.40. <a href="https://nandohusni.gumroad.com/l/hnxqmi/BF40?referrer=https://hashnode.com">Open with the code applied</a></li>
</ul>
<p>There's also a free, MIT-licensed edition with the pre-launch checklist and link crawler, OG images with a preview checker, and dark mode: <code>npx skills add nandot12/nextjs-launch-skills</code> · <a href="https://github.com/nandot12/nextjs-launch-skills">GitHub</a></p>
<p>What's on your pre-deal checklist that I missed?</p>
]]></content:encoded></item><item><title><![CDATA[4 Next.js 16 traps that break static exports, OG images and blog routes]]></title><description><![CDATA[Tested in a fresh Next.js 16.4 app: static export vs Cache Components, OG images with no Content-Type, dynamicParams errors, lost share images.]]></description><link>https://nandohusni.hashnode.dev/4-next-js-16-traps-that-break-static-exports-og-images-and-blog-routes</link><guid isPermaLink="true">https://nandohusni.hashnode.dev/4-next-js-16-traps-that-break-static-exports-og-images-and-blog-routes</guid><category><![CDATA[Next.js]]></category><category><![CDATA[React]]></category><category><![CDATA[webdev]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Nando Septian Husni]]></dc:creator><pubDate>Thu, 19 Nov 2026 09:41:06 GMT</pubDate><content:encoded><![CDATA[<p>I recently tested a set of Next.js templates (landing page, SEO files, OG images, an MDX blog) in a <strong>fresh</strong> <code>create-next-app</code> <strong>project on Next.js 16.4.6</strong>, twice: once as a static export and once as a server build with Cache Components.</p>
<p>Everything compiled in my head. Four things broke in practice, and none of them is obvious from the docs. Here they are, with the exact errors and the fixes that worked.</p>
<h2>1. Static export and Cache Components don't mix</h2>
<p>New projects from <code>create-next-app</code> 16.4 start with this config:</p>
<pre><code class="language-ts">const nextConfig: NextConfig = {
  cacheComponents: true,
  partialPrefetching: true,
};
</code></pre>
<p>Add <code>output: "export"</code> for a static site (Cloudflare Pages, GitHub Pages, Netlify), plus an <code>opengraph-image.tsx</code> or <code>sitemap.ts</code>, and the build stops:</p>
<pre><code class="language-text">Error: export const dynamic = "force-static"/export const revalidate not configured
on route "/opengraph-image" with "output: export".
</code></pre>
<p>The obvious fix makes it worse:</p>
<pre><code class="language-text">Error: Route segment config "dynamic" is not compatible with
`nextConfig.cacheComponents`. Please remove it.
</code></pre>
<p>And if you replace every generated file with a static one, you hit the real wall:</p>
<pre><code class="language-text">Error: Invariant: PPR cannot be enabled in export mode
</code></pre>
<p><strong>Fix:</strong> a static export needs Cache Components off. Remove both flags, then mark every metadata route and route handler as static:</p>
<pre><code class="language-ts">// next.config.ts
const nextConfig: NextConfig = {
  output: "export",
  images: { unoptimized: true },
};
</code></pre>
<pre><code class="language-ts">// app/sitemap.ts, app/robots.ts, app/opengraph-image.tsx, app/icon.tsx, app/rss.xml/route.ts
export const dynamic = "force-static";
</code></pre>
<p>If your code uses <code>"use cache"</code> or <code>connection()</code>, it needs Cache Components, so that route needs a server deployment instead.</p>
<h2>2. Generated OG images lose their file type on static hosts</h2>
<p>After fixing #1, the build passes and <code>out/</code> contains your share image. Look closely at the name:</p>
<pre><code class="language-text">out/opengraph-image
</code></pre>
<p>No extension. Static hosts pick the <code>Content-Type</code> from the extension, so this file is served without one. I checked it on Cloudflare Pages: the response has no <code>Content-Type</code> header at all. Some link-preview crawlers reject that, and your carefully designed share card never shows up.</p>
<p><strong>Fix:</strong> for the site-wide image, open <code>/opengraph-image</code> in your running site, save it, and commit it as a static file:</p>
<pre><code class="language-text">app/opengraph-image.png   →   exported as out/opengraph-image.png
</code></pre>
<p>Static metadata files keep their extension, so the host sends <code>image/png</code>. For per-page images that must stay generated (blog posts), set the type in your host's headers file. Cloudflare Pages and Netlify read <code>public/_headers</code>:</p>
<pre><code class="language-text">/blog/:slug/opengraph-image
  Content-Type: image/png
</code></pre>
<p>Then verify on the live URL:</p>
<pre><code class="language-bash">curl -sI https://your-site.pages.dev/opengraph-image.png | grep -i content-type
</code></pre>
<h2>3. <code>dynamicParams = false</code> is rejected by Cache Components</h2>
<p>The MDX guide's pattern for a blog with dynamic imports ends with:</p>
<pre><code class="language-ts">export const dynamicParams = false;
</code></pre>
<p>With Cache Components on, the build fails:</p>
<pre><code class="language-text">Error: Route segment config "dynamicParams" is not compatible with
`nextConfig.cacheComponents`. Please remove it.
</code></pre>
<p><strong>Fix:</strong> drop the export and handle unknown slugs yourself:</p>
<pre><code class="language-tsx">import { notFound } from "next/navigation";

export default async function PostPage({ params }: { params: Promise&lt;{ slug: string }&gt; }) {
  const { slug } = await params;
  const post = await getPost(slug); // returns null for unknown slugs
  if (!post) notFound();
  // ...
}
</code></pre>
<p>Two details I only learned by testing:</p>
<ul>
<li><strong>Async file reads count as uncached data.</strong> My <code>getPost</code> listed the posts folder with <code>fs/promises</code>, and prerendering failed with "Next.js encountered uncached or runtime data during prerendering". Switching that one call to <code>readdirSync</code> fixed it. Wrapping the function in <code>"use cache"</code> is the other option.</li>
<li><strong>Unknown slugs return 200, not 404.</strong> With Partial Prerendering, the static shell streams before <code>notFound()</code> runs. Next.js renders the not-found page and adds <code>&lt;meta name="robots" content="noindex"&gt;</code>, so search engines still drop it, but the status code is 200. In a static export it's a real 404.</li>
</ul>
<h2>4. A page's own <code>openGraph</code> silently drops your share image</h2>
<p>You add <code>app/opengraph-image.tsx</code> at the root and every page gets a nice preview. Then you give blog posts their own metadata:</p>
<pre><code class="language-ts">export async function generateMetadata({ params }) {
  // ...
  return {
    title: post.title,
    openGraph: { type: "article", title: post.title, publishedTime: post.date },
  };
}
</code></pre>
<p>Now the posts have <strong>no</strong> <code>og:image</code> <strong>at all</strong>. A child's <code>openGraph</code> object replaces the parent's, including the image that came from the root file. Nothing warns you; the link preview is just blank.</p>
<p><strong>Fix:</strong> add an image at the segment level, so every post gets its own:</p>
<pre><code class="language-text">app/blog/[slug]/opengraph-image.tsx
</code></pre>
<p>Export <code>generateStaticParams</code> from that file too, so the images are prerendered. Or set <code>openGraph.images</code> explicitly in <code>generateMetadata</code>.</p>
<p>To catch this before you ship, check the tags of a post in your built site:</p>
<pre><code class="language-bash">curl -s http://localhost:3000/blog/my-post | grep -o '&lt;meta property="og:image"[^&gt;]*&gt;'
</code></pre>
<h2>How I check for these now</h2>
<p>Most of these only showed up in a production build or on the live host, not while clicking around in <code>next dev</code>. So I wrote small zero-dependency Node scripts that check the built site (SEO tags, share images and their content type, the <code>out/</code> folder before upload, broken links) and wrapped them, together with the fixes above, into agent skills for Claude Code, Cursor and Codex.</p>
<ul>
<li>The <strong>free edition</strong> (pre-launch checklist with a link crawler, OG images with a preview checker, flash-free dark mode) is MIT-licensed on GitHub: <code>npx skills add nandot12/nextjs-launch-skills</code> · <a href="https://github.com/nandot12/nextjs-launch-skills">github.com/nandot12/nextjs-launch-skills</a></li>
<li>The <strong>full pack</strong> adds 10 more skills: SEO, landing page, copywriting, email capture, checkout, analytics, MDX blog, static deploy, accessibility and performance audits. <a href="https://nandohusni.gumroad.com/l/nextjs-launch-skills?referrer=https://hashnode.com">Next.js Launch Skills</a></li>
</ul>
<p>Have you hit other Next.js 16 traps in production builds? Tell me in the comments and I'll test them.</p>
]]></content:encoded></item><item><title><![CDATA[Fix: “Next.js encountered the unstable value new Date()” in Next.js 16]]></title><description><![CDATA[Why Next.js 16 fails the build on new Date() or Math.random(), and four fixes: use cache, connection(), useEffect, performance.now().]]></description><link>https://nandohusni.hashnode.dev/fix-next-js-encountered-the-unstable-value-new-date-in-next-js-16</link><guid isPermaLink="true">https://nandohusni.hashnode.dev/fix-next-js-encountered-the-unstable-value-new-date-in-next-js-16</guid><category><![CDATA[Next.js]]></category><category><![CDATA[React]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Nando Septian Husni]]></dc:creator><pubDate>Thu, 19 Nov 2026 06:43:07 GMT</pubDate><content:encoded><![CDATA[<p>I upgraded a landing page to Next.js 16 and the production build failed on the most innocent line in the whole project, the copyright year in the footer:</p>
<pre><code class="language-tsx">&lt;p&gt;© {new Date().getFullYear()} Driftly&lt;/p&gt;
</code></pre>
<p><code>next build</code> stopped with this:</p>
<pre><code class="language-text">Error: Route "/": Next.js encountered the unstable value `new Date()` while prerendering.

This value can change between renders, so it must be either prerendered or computed later.

Ways to fix this:
  - [dynamic] Render at request time by adding a dynamic data access (e.g. `await connection()`) before this call
  - [cache] Prerender and cache the value with `"use cache"`
  - [client] Render the value on the client with `"use client"`
  - [measure] If the value is for telemetry, use a timing API such as `performance.now()`
</code></pre>
<p>Here's why it happens and how to pick the right fix.</p>
<h2>Why Next.js 16 complains</h2>
<p>The error only shows up when <strong>Cache Components</strong> is turned on. Check your <code>next.config.ts</code>:</p>
<pre><code class="language-ts">const nextConfig: NextConfig = {
  cacheComponents: true,
};
</code></pre>
<p>My project was created with <code>create-next-app</code>, and it already had this option enabled.</p>
<p>With Cache Components, Next.js prerenders as much of each page as it can into static HTML at build time. A value like <code>new Date()</code> is different every time it runs, so Next.js can't tell whether you meant "the time when the site was built" or "the time when the visitor opened the page". Instead of guessing, it stops the build and asks you to decide.</p>
<p>The same rule applies to:</p>
<ul>
<li><code>new Date()</code> and <code>Date.now()</code></li>
<li><code>Math.random()</code></li>
<li><code>crypto.randomUUID()</code></li>
</ul>
<p><code>performance.now()</code> is the exception. Next.js treats it as a timing tool for telemetry and doesn't guard it.</p>
<h2>Fix 1: Cache the value with "use cache"</h2>
<p>Use this when the value only needs to be <strong>fresh enough</strong>, not computed for every visitor. A copyright year is the perfect example.</p>
<p>Move the value into an async function marked with <code>"use cache"</code>:</p>
<pre><code class="language-tsx">// components/year.tsx
async function getYear() {
  "use cache";
  return new Date().getFullYear();
}

export async function Year() {
  return &lt;&gt;{await getYear()}&lt;/&gt;;
}
</code></pre>
<pre><code class="language-tsx">// components/footer.tsx
import { Year } from "./year";

export function Footer() {
  return &lt;p&gt;© &lt;Year /&gt; Driftly&lt;/p&gt;;
}
</code></pre>
<p>The year is computed during prerendering and cached, so the page stays fully static. The cached value is refreshed when the cache revalidates or when you redeploy.</p>
<h2>Fix 2: Compute it on every request with connection()</h2>
<p>Use this when every visitor really needs a <strong>new</strong> value, like a request ID or a "rendered at" timestamp.</p>
<p>Call <code>connection()</code> before reading the value. This tells Next.js to wait for a real request. Wrap the component in <code>&lt;Suspense&gt;</code> so the rest of the page can still be prerendered:</p>
<pre><code class="language-tsx">import { connection } from "next/server";
import { Suspense } from "react";

async function RenderedAt() {
  await connection();
  return &lt;p&gt;Rendered at {new Date().toISOString()}&lt;/p&gt;;
}

export default function Page() {
  return (
    &lt;Suspense fallback={&lt;p&gt;Loading…&lt;/p&gt;}&gt;
      &lt;RenderedAt /&gt;
    &lt;/Suspense&gt;
  );
}
</code></pre>
<p>The trade-off: this part of the page is now rendered on the server for every request. In the <code>next build</code> output, the route changes from <code>○ (Static)</code> to <code>◐ (Partial Prerender)</code>: static HTML with the dynamic part streamed in.</p>
<h2>Fix 3: Move it to the client (and watch for the second error)</h2>
<p>My first instinct was to make the footer year a Client Component:</p>
<pre><code class="language-tsx">"use client";

export function Year() {
  return &lt;&gt;{new Date().getFullYear()}&lt;/&gt;;
}
</code></pre>
<p>That produced a <strong>different</strong> error:</p>
<pre><code class="language-text">Error: Route "/": Next.js encountered the unstable value `new Date()` in a Client Component.

This value would be evaluated during the prerender, instead of recomputed on each visit.
</code></pre>
<p>With Cache Components, Client Components are prerendered too. <code>"use client"</code> alone doesn't move the work to the browser. The error message suggests two ways out:</p>
<p><strong>Read the value in an effect</strong>, so it only runs in the browser:</p>
<pre><code class="language-tsx">"use client";

import { useEffect, useState } from "react";

export function LocalTime() {
  const [time, setTime] = useState&lt;string | null&gt;(null);

  useEffect(() =&gt; {
    setTime(new Date().toLocaleTimeString());
  }, []);

  return &lt;span&gt;{time ?? "…"}&lt;/span&gt;;
}
</code></pre>
<p><strong>Or wrap the Client Component in</strong> <code>&lt;Suspense&gt;</code> so Next.js can stream it in instead of baking it into the static HTML.</p>
<p>Use this fix for values that depend on the visitor's browser, such as their local time zone.</p>
<h2>Fix 4: For telemetry, use performance.now()</h2>
<p>If you only need a duration for logging, <code>performance.now()</code> is allowed:</p>
<pre><code class="language-ts">const start = performance.now();
await doWork();
console.log(`doWork took ${performance.now() - start}ms`);
</code></pre>
<p>Don't render this value in the UI. It's meant for measurements.</p>
<h2>Which fix should you use?</h2>
<table>
<thead>
<tr>
<th>What you need</th>
<th>Fix</th>
</tr>
</thead>
<tbody><tr>
<td>A value that's fine to compute once (copyright year, build date)</td>
<td><code>"use cache"</code></td>
</tr>
<tr>
<td>A fresh value for every request (request ID, server timestamp)</td>
<td><code>await connection()</code> + <code>&lt;Suspense&gt;</code></td>
</tr>
<tr>
<td>A value from the visitor's browser (local time, time zone)</td>
<td><code>useEffect</code> in a Client Component</td>
</tr>
<tr>
<td>A duration for logs or metrics</td>
<td><code>performance.now()</code></td>
</tr>
</tbody></table>
<h2>One more gotcha: static export</h2>
<p>If you deploy with <code>output: "export"</code> (a fully static site with no server), you can't render anything per request, so Fix 2 is not an option. For the static demo of my landing page, the simplest working setup was turning <code>cacheComponents</code> off for that build. Note that <code>partialPrefetching</code> requires <code>cacheComponents</code>, so it has to go too.</p>
<h2>Wrapping up</h2>
<p>The error looks scary, but it's Next.js asking a fair question: should this value be computed <strong>once</strong>, <strong>per request</strong>, or <strong>in the browser</strong>? Answer that, and the fix is a few lines.</p>
<p>The official docs go deeper: <a href="https://nextjs.org/docs/messages/blocking-prerender-current-time">blocking-prerender-current-time</a> and <a href="https://nextjs.org/docs/messages/blocking-prerender-current-time-client">the Client Component version</a>.</p>
<p>I ran into this while building <strong>Liftoff</strong>, a Next.js 16 + Tailwind CSS 4 landing page kit, which uses the <code>"use cache"</code> footer year from Fix 1.</p>
<ul>
<li><strong>Liftoff Lite</strong> is free (MIT): navbar, hero, features, footer and dark mode. <a href="https://nandohusni.gumroad.com/l/gblgky?referrer=https://hashnode.com">Get Liftoff Lite</a></li>
<li><strong>Liftoff</strong> is the full kit with pricing, FAQ, testimonials, email capture and a 22-page launch guide. <a href="https://liftoff-kit.pages.dev">Live demo</a> · <a href="https://nandohusni.gumroad.com/l/hnxqmi?referrer=https://hashnode.com">Get Liftoff</a></li>
</ul>
<p>Have you hit this error with something other than dates? Let me know in the comments.</p>
]]></content:encoded></item><item><title><![CDATA[How to Build a SaaS Landing Page with Next.js 16 and Tailwind CSS 4]]></title><description><![CDATA[One config file, theme tokens, no-flash dark mode and SEO by default: four patterns for a fast Next.js 16 SaaS landing page.]]></description><link>https://nandohusni.hashnode.dev/how-to-build-a-saas-landing-page-with-next-js-16-and-tailwind-css-4</link><guid isPermaLink="true">https://nandohusni.hashnode.dev/how-to-build-a-saas-landing-page-with-next-js-16-and-tailwind-css-4</guid><category><![CDATA[Next.js]]></category><category><![CDATA[Tailwind CSS]]></category><category><![CDATA[React]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Nando Septian Husni]]></dc:creator><pubDate>Wed, 18 Nov 2026 14:19:21 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6afdb257cc53e9a18959c7fa/7edfde4c-7bc1-4130-8684-04fcdce9bc0b.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A landing page has one job: turn a visitor into a signup. In this guide we'll build the foundations of a fast, good-looking SaaS landing page with <strong>Next.js 16 (App Router)</strong> and <strong>Tailwind CSS 4</strong>, using four patterns that save hours on every project:</p>
<ol>
<li>Keep all content in <strong>one config file</strong></li>
<li>Drive colors from <strong>CSS variable theme tokens</strong></li>
<li>Add <strong>dark mode without the flash</strong></li>
<li>Ship <strong>SEO and structured data</strong> by default</li>
</ol>
<p>Let's go.</p>
<h2>1. Set up the project</h2>
<pre><code class="language-bash">npx create-next-app@latest my-landing --ts --tailwind --app --src-dir
cd my-landing
npm run dev
</code></pre>
<p>Next.js 16 uses the App Router and Turbopack by default, and Tailwind CSS 4 is configured with a single <code>@import "tailwindcss";</code> line in <code>globals.css</code>. No <code>tailwind.config.js</code> is needed.</p>
<h2>2. Put every word in one config file</h2>
<p>The biggest time sink on landing pages is hunting for text across a dozen components. Instead, keep all copy in one typed object:</p>
<pre><code class="language-ts">// src/config/site.ts
export const site = {
  name: "Driftly",
  tagline: "Product analytics that answers questions, not just charts.",
  url: "https://driftly.example.com",
};

export const hero = {
  title: { before: "Know why users stay.", highlight: "Ship what they need." },
  subtitle: "Driftly connects to your product in five minutes and tells you what is working.",
  primaryCta: { label: "Start free trial", href: "#get-started" },
};

export const faq = {
  items: [
    { q: "How long does setup take?", a: "Most teams send their first events within five minutes." },
    { q: "Can I cancel anytime?", a: "Yes. Plans are month-to-month with no lock-in." },
  ],
};
</code></pre>
<p>Components just import what they need:</p>
<pre><code class="language-tsx">import { hero } from "@/config/site";

export function Hero() {
  return (
    &lt;section className="py-24 text-center"&gt;
      &lt;h1 className="text-5xl font-semibold tracking-tight text-balance"&gt;
        {hero.title.before} &lt;span className="text-brand"&gt;{hero.title.highlight}&lt;/span&gt;
      &lt;/h1&gt;
      &lt;p className="mx-auto mt-6 max-w-2xl text-lg text-muted"&gt;{hero.subtitle}&lt;/p&gt;
      &lt;a href={hero.primaryCta.href} className="mt-8 inline-flex rounded-full bg-brand px-6 py-3 text-brand-fg"&gt;
        {hero.primaryCta.label}
      &lt;/a&gt;
    &lt;/section&gt;
  );
}
</code></pre>
<p>Now rewriting your page, or reusing the template for a new product, means editing one file.</p>
<h2>3. Theme tokens: change your brand color in one place</h2>
<p>Tailwind CSS 4 lets you map CSS variables straight into utility classes with <code>@theme inline</code>. Define your palette once for light mode and once for dark mode:</p>
<pre><code class="language-css">/* src/app/globals.css */
@import "tailwindcss";
@custom-variant dark (&amp;:where(.dark, .dark *));

:root {
  --bg: #ffffff;
  --fg: #0b1020;
  --muted: #5b6478;
  --brand: #5b5bf6;
  --brand-fg: #ffffff;
}
.dark {
  --bg: #07090f;
  --fg: #eef1f8;
  --muted: #98a1b6;
  --brand: #7c7cff;
  --brand-fg: #0b0b1a;
}

@theme inline {
  --color-bg: var(--bg);
  --color-fg: var(--fg);
  --color-muted: var(--muted);
  --color-brand: var(--brand);
  --color-brand-fg: var(--brand-fg);
}
</code></pre>
<p>Now <code>bg-brand</code>, <code>text-muted</code> and <code>bg-bg</code> work everywhere, and they switch automatically in dark mode. Rebranding is a two-line change.</p>
<h2>4. Dark mode without the flash</h2>
<p>If you read the user's theme in a React effect, the page renders light first and then flips to dark. Users see a white flash. The fix is a tiny inline script that runs <strong>before the first paint</strong>:</p>
<pre><code class="language-tsx">// src/app/layout.tsx
const themeScript = `(function(){try{
  var t = localStorage.getItem('theme');
  var d = t ? t === 'dark' : matchMedia('(prefers-color-scheme: dark)').matches;
  document.documentElement.classList.toggle('dark', d);
}catch(e){}})();`;

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    &lt;html lang="en" suppressHydrationWarning&gt;
      &lt;head&gt;
        &lt;script dangerouslySetInnerHTML={{ __html: themeScript }} /&gt;
      &lt;/head&gt;
      &lt;body&gt;{children}&lt;/body&gt;
    &lt;/html&gt;
  );
}
</code></pre>
<p>The toggle button only needs to flip the class and save the choice:</p>
<pre><code class="language-tsx">"use client";
export function ThemeToggle() {
  return (
    &lt;button
      aria-label="Toggle dark mode"
      onClick={() =&gt; {
        const dark = document.documentElement.classList.toggle("dark");
        try { localStorage.setItem("theme", dark ? "dark" : "light"); } catch {}
      }}
    &gt;
      🌓
    &lt;/button&gt;
  );
}
</code></pre>
<p><code>suppressHydrationWarning</code> on <code>&lt;html&gt;</code> stops React from complaining that the server-rendered class differs from the client.</p>
<h2>5. A FAQ accordion with zero JavaScript</h2>
<p>You don't need a component library for an accordion. Native <code>&lt;details&gt;</code> is accessible and keyboard-friendly out of the box:</p>
<pre><code class="language-tsx">{faq.items.map((item) =&gt; (
  &lt;details key={item.q} className="group border-b border-border py-5"&gt;
    &lt;summary className="flex cursor-pointer justify-between font-medium"&gt;
      {item.q}
      &lt;span className="transition-transform group-open:rotate-45"&gt;+&lt;/span&gt;
    &lt;/summary&gt;
    &lt;p className="mt-3 text-muted"&gt;{item.a}&lt;/p&gt;
  &lt;/details&gt;
))}
</code></pre>
<p>Add <code>details &gt; summary { list-style: none; }</code> to your CSS to hide the default marker.</p>
<h2>6. SEO and structured data by default</h2>
<p>The App Router gives you metadata, sitemaps and social images as plain files.</p>
<p><strong>Metadata</strong> from your config:</p>
<pre><code class="language-tsx">export const metadata: Metadata = {
  metadataBase: new URL(site.url),
  title: `${site.name} — ${site.tagline}`,
  description: site.description,
  openGraph: { type: "website", url: site.url, siteName: site.name },
  twitter: { card: "summary_large_image" },
};
</code></pre>
<p><strong>Sitemap</strong> in <code>src/app/sitemap.ts</code>:</p>
<pre><code class="language-ts">import type { MetadataRoute } from "next";
import { site } from "@/config/site";

export default function sitemap(): MetadataRoute.Sitemap {
  return [{ url: site.url, changeFrequency: "weekly", priority: 1 }];
}
</code></pre>
<p><strong>FAQ structured data</strong> so Google can show your answers in search results:</p>
<pre><code class="language-tsx">const faqJsonLd = {
  "@context": "https://schema.org",
  "@type": "FAQPage",
  mainEntity: faq.items.map((i) =&gt; ({
    "@type": "Question",
    name: i.q,
    acceptedAnswer: { "@type": "Answer", text: i.a },
  })),
};

&lt;script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(faqJsonLd) }} /&gt;
</code></pre>
<p>Finally, add <code>src/app/opengraph-image.tsx</code> with <code>ImageResponse</code> from <code>next/og</code> to generate a 1200×630 social preview from your site name and tagline. Every shared link then gets a proper card.</p>
<h2>7. One gotcha in Next.js 16: <code>new Date()</code> in server components</h2>
<p>If you enable <code>cacheComponents</code> in <code>next.config.ts</code> (it gives you fast, pre-rendered pages), this innocent footer line breaks the build:</p>
<pre><code class="language-tsx">&lt;p&gt;© {new Date().getFullYear()} Driftly&lt;/p&gt;
</code></pre>
<p>Next.js refuses values that change on every request during prerendering. Wrap the value in a cached function instead:</p>
<pre><code class="language-tsx">async function getYear() {
  "use cache";
  return new Date().getFullYear();
}

export async function Year() {
  return &lt;&gt;{await getYear()}&lt;/&gt;;
}
</code></pre>
<h2>Wrapping up</h2>
<p>With one config file, theme tokens, a no-flash dark mode and SEO baked in, you have a landing page foundation you can reuse for every product you launch.</p>
<p>If you'd rather not build all of this from scratch:</p>
<ul>
<li><strong>Liftoff Lite</strong> (free, MIT): navbar, hero, features, footer and dark mode, using every pattern from this article. <a href="https://nandohusni.gumroad.com/l/gblgky?referrer=https://hashnode.com">Get Liftoff Lite</a></li>
<li><strong>Liftoff</strong> (full kit): adds pricing with a monthly/yearly toggle, FAQ, testimonials, logo cloud, bento showcase, stats, email capture, generated social images and a 22-page Ship-in-a-Day launch guide. <a href="https://liftoff-kit.pages.dev">Live demo</a> · <a href="https://nandohusni.gumroad.com/l/hnxqmi?referrer=https://hashnode.com">Get Liftoff</a></li>
</ul>
<p>Happy shipping! 🚀</p>
]]></content:encoded></item></channel></rss>