Experience
Projects
My Stack
Case studies
Contact me
Open my CV

·6 min read

I tried ISR for Movix, and the language cookie said no

In late April 2026 I decided that Movix's popular watch pages should come from a cache, not be rendered on every visit. Incremental static regeneration is built for that, the change looked small, and on the morning of 28 April I committed it with a message that was a typo, "IRS MADE". The next day I started taking it apart, and by that evening most of it was gone. The reason is a single cookie, and I think the way I got there is more useful than the result.

Project
Movix
Date
Apr 2026
Stack
Next.js, TypeScript
Commit
1b6f6a4, 8d16cd4, 42101ae, c238c10, 53284af

What broke

The watch pages are the ones that matter for search engines and for repeat visitors. They fetch a title's data on the server, emit metadata and structured data, and render the page. Rendering them on every request is correct and, at this scale, probably fine, but it felt wasteful for pages that change rarely, so I wanted them cached for a few minutes and regenerated in the background.

The first commit did the obvious things. 1b6f6a4 (Apr 2026) set a revalidate window of 300 seconds on the catch-all page, tagged each server fetch with names such as movies and the title's own id so an admin action could invalidate them, and added cache headers to some metadata routes. It worked in the sense that the build accepted it. It did not work in the sense that mattered. I had also added a log line that prints on every render, to see whether pages were really being cached, and the cookie reads described below kept the route dynamic.

What the code showed

The site keeps the visitor's language in a cookie named language. The root layout reads it to set the lang attribute on the page, and the page reads it to choose a dictionary and the language of the server-rendered content:

tsx
export const revalidate = 300; // one cached copy for everyone

// ...and in the same route, a value that differs per visitor
const lang = (await cookies()).get("language")?.value ?? "ka";

Those two lines cannot live together. A cached page is one document served to every visitor until it expires. A cookie is a value that differs by visitor. When a route reads cookies, Next.js has to render it per request, and when a route is also asked to be static, it raises a dynamic server usage error in its build and in its logs. The framework was not being difficult. It was telling me that I had asked for a single document and also for a document that depends on who is asking.

I took three attempts at this in a row, and they show how a fix can get further from the cause.

The fix

  1. 01

    Apr 28, morning

    ISR added with a 300 second window and fetch tags

  2. 02

    Apr 28, later

    Route restructured and cookie read removed, 8d16cd4

  3. 03

    Apr 29, evening

    That restructure reverted, 42101ae

  4. 04

    Apr 29, minutes later

    Cookie reads wrapped in try and catch, c238c10

  5. 05

    Apr 29, under three minutes after

    force-dynamic chosen, 53284af

Figure 1. Three attempts and a decision, over two days.

Attempt one, remove the cookie. 8d16cd4 (Apr 2026), titled "ISR working again", renamed the optional catch-all route to a required one, dropped the cookie read from the page and from the metadata function, hard-wired the default language there, and raised the window to an hour. Its own comment says the client would override the language afterwards. That is the compromise, and it is a real one: the server-rendered HTML would always be in the default language, and a visitor who chose another would get that HTML first and then a change on the client. For a site whose audience is Georgian but which supports other languages, that is a worse page for the visitors and for the crawler who sees only the first version.

The next evening I reverted it in 42101ae. The revert has no message of its own, so I am reading my own intent from the code: I did not want server-rendered content that was wrong for part of the audience.

Attempt two, hide the error. c238c10 (Apr 2026) kept the original route and wrapped each cookie read in a try and catch, with the default language as the fallback. The commit message says it fixes the dynamic server usage error, and it did, in the narrowest sense: the error stopped appearing.

That is exactly the problem. The error was the framework's mechanism for noticing that a route cannot be static. Swallowing it did not make the route static. It made the failure silent, and in the cases where a page is built or cached without a request, it would fall back to the default language and then serve that cached copy to everyone. Nothing would say so. I stopped there, after less time than it took to write the message.

Attempt three, say what is true. 53284af (Apr 2026), under three minutes after the try and catch, replaced the revalidate setting with a single line:

tsx
export const dynamic = "force-dynamic"; // rendered per request, on purpose

It also deleted the function that had pre-generated the newest and most popular titles, which was by far the largest part of the original change. The route now says what it does. It is rendered per request, the cookie works as it always did, and the code no longer asks for a cache that the design cannot honour.

The trade is deliberate and I would defend it. Every watch page is rendered per request, which is fine for one server and a bounded catalog. The fetch calls inside the route keep their own revalidate options, so upstream responses can still be reused, though I did not measure how much that saves.

What I would do differently

I would have read the design constraint before writing the feature. The conflict was visible in the code on day one: a cookie read in the layout and in the page, next to a request for a static page. Ten minutes of tracing where language was read would have saved a restructure, a revert and a workaround.

I would also treat "make the error go away" as a warning sign. A catch block around a framework call is a decision to ignore the framework's judgment, and I should make that decision on purpose, not at the end of a long evening.

And if the load grows, I would not push ISR through the cookie. The honest fix is to move the language into the URL, so that /ka/... and /en/... are two different pages that can each be cached. That also gives search engines a stable address per language. It is a bigger change, and one I would only make with traffic that justified it.

Where this fits

This is a story about choosing the simple option and recording why, in a project where I am the only person who will ever have to operate it. The rest of the site's decisions, from token-gated video to catalog ingestion and search, are in the full Movix case study.

The full project story covers the video server, the catalog, search and the other incidents I handled after launch.

Read the full case study

#nextjs#isr#caching#performance

Keep reading

Have a project in mind?