Introducing a new way to review your PRs.

Read the announcement

generaltranslation / gt

Full-stack localization for every framework

View on GitHub

22 documents · Updated Nov 23, 2026

docs / nextjs-integration

Next.js integration

gt-next adds automatic internationalization to Next.js applications. It connects locale-aware request handling with translated server output and client state so the App Router and Pages Router can use the same translation model. The integration also provides locale-aware links, dictionary loading, and a Next.js build wrapper that joins application settings with translation settings. See Application framework integrations, React integration, and Alternative framework integrations for related system views.

Integration model

Next.js entry points

The integration selects an API surface for the place where code runs. App Router Server Components use gt-next/server for request data and server translation helpers. Shared components and hooks use gt-next when they must work across server and browser boundaries. Pages Router data functions use the server exports from the main package. Worker runtimes use the server surface before the browser surface, while the React Server Components condition keeps its server-only surface first. The client surface keeps server-only helpers unavailable instead of allowing them to run with incomplete request data. packages/…/package.json• L72-114 packages/…/index.server.ts• L13-71 packages/…/index.client.ts• L19-100 packages/…/index.rsc.ts• L1-19

The package export contract keeps these runtime and type surfaces aligned. React Server Components receive RSC-specific types. Worker and browser conditions still select the server runtime when both conditions are active. The react-server condition takes priority over those runtime conditions. The shared surfaces also expose matching href-localization helpers for navigation that does not render a Link. packages/…/index.server.ts• L38-71 packages/…/index.client.ts• L78-100 packages/…/index.rsc.ts• L32-41 packages/…/server.ts• L16-29

The normal setup wraps next.config with withGTConfig and places GTProvider near the application root. The provider resolves the request locale, region, and i18n state on the server, loads the translation and dictionary data for that locale, and passes these values to the client boundary as provider props. This makes server-rendered content and later client updates use the same locale state. packages/…/config.ts• L149-204 packages/…/GTProvider.tsx• L9-44

Server initialization reads GT_PROJECT_ID and GT_API_KEY from the environment. In development, GT_API_KEY also acts as the hot-reload key and may be exposed to client code by the build wrapper. Production does not read or serialize a development key. The package no longer reads GT_DEV_API_KEY; legacy NEXT_PUBLIC_GT_PROJECT_ID and NEXT_PUBLIC_GT_DEV_API_KEY names remain supported as fallbacks. packages/…/runtimeCredentials.ts• L1-19 packages/…/shared.ts• L12-68 packages/…/config.test.ts• L554-704 packages/…/CHANGELOG.md• L61-65

References: packages/…/package.json• L72-114 packages/…/index.server.ts• L13-71 packages/…/index.client.ts• L19-100 packages/…/index.rsc.ts• L1-19 packages/…/server.ts• L10-29 packages/…/GTProvider.tsx• L9-44 packages/…/runtimeCredentials.ts• L1-19 packages/…/shared.ts• L12-68 packages/…/config.test.ts• L554-704 packages/…/CHANGELOG.md• L61-65

Request lifecycle

The request lifecycle turns Next.js request signals into one locale and one i18n-enabled state. Middleware can set the locale header and cookies before the route runs. Server APIs then read that request context, and the provider uses it to load the data needed by the rendered tree.

The main path is:

flowchart LR
    A[Next.js request] --> B[Locale middleware]
    B --> C[Locale header and cookies]
    C --> D[Server request context]
    D --> E[Server APIs or GTProvider]
    E --> F[Translated server output]
    E --> G[Client locale and data state]
    G --> H[Router refresh or browser navigation]

The client provider refreshes Server Components after a locale change when the installed Next.js version supports locale refresh. Older supported versions use a full browser reload. If locale routing applies and the target is the default locale while the current URL still carries a non-default locale prefix or spelling, it performs a browser navigation because a refresh alone cannot remove that path locale. An unprefixed default-locale path can use a Server Component refresh instead. packages/…/client-boundary.tsx• L39-113 packages/…/constants.ts• L13-15

In server-rendered applications, the provider treats locale, region, and i18n condition props from the server as the rendered state. Condition setters write cookies and request a refresh or reload, while hooks keep the current server snapshot until the new response arrives. Provider-free single-page applications retain their cookie-backed behavior. packages/…/CHANGELOG.md• L230

References: packages/…/initGT.server.ts• L19-64 packages/…/initGT.client.ts• L6-27 packages/…/getRequestConditions.ts• L1-12 packages/…/client-boundary.tsx• L39-113 packages/…/constants.ts• L13-15 packages/…/CHANGELOG.md• L230

Middleware and routing

Middleware behavior

createNextMiddleware creates the Next.js middleware that detects a locale and applies the configured URL policy. It can continue the request, rewrite it to the shared route used by Next.js, or redirect the browser to the public localized route. It also returns the selected locale in a response header and persists routing state in cookies. The routing tables are prepared once when the middleware is created, so each request can use the same locale and path model. packages/…/createNextMiddleware.ts• L29-79 packages/…/createMiddlewareRouting.ts• L28-37

Middleware settings have one clear precedence order. Options passed to createNextMiddleware win over settings forwarded by withGTConfig, which win over the built-in defaults. Malformed configuration passed through the build environment is ignored after an error is reported. packages/…/resolveMiddlewareConfig.ts• L8-41 packages/…/defaultMiddlewareConfig.ts• L3-35 packages/…/middleware.edge.test.ts• L443-571

Locale selection gives the URL and an explicit locale choice priority over passive browser hints. A locale reset cookie is an explicit choice, so it can override the locale in the current pathname. With smart routing enabled, an unprefixed path that is known to be a default-locale alias selects the default locale before the saved cookie or browser hint. Without that alias, the middleware checks these sources in order:

  • A valid locale in the pathname.
  • A locale path configured as the default-locale path.
  • The saved locale cookie.
  • The referrer locale cookie.
  • The Accept-Language header, unless browser locale detection is disabled.
  • The configured default locale.

Smart routing is enabled by default. When it is disabled and default-locale prefixes are not shown, an unprefixed URL from a returning visitor selects the default locale instead of the saved locale. A first visit without a locale cookie still uses browser-language negotiation. An explicit reset cookie can select another locale. packages/…/utils.ts• L212-320 packages/…/createNextMiddleware.ts• L63-80 packages/…/middleware.edge.test.ts• L601-965 packages/…/CHANGELOG.md• L278-280

The middleware can limit its work with pathRegex. The Next.js matcher should still exclude assets and other routes that must not enter the locale flow. The same unprefixed-path rule applies to links and href helpers, so a path outside pathRegex stays unlocalized. packages/…/utils.ts• L212-312 packages/…/createNextMiddleware.ts• L94-105 packages/…/localize-utils.ts• L58-71 packages/…/withGTConfigProps.ts• L64-66

Middleware responses preserve the request's base path and trailing-slash style when they redirect or rewrite. They also preserve the query string and keep generated destinations on the request origin. This keeps the public URL stable while the request moves to the shared Next.js route. packages/…/utils.ts• L37-101 packages/…/pathname.ts• L17-33 packages/…/urlPreservation.edge.test.ts• L17-33

References: packages/…/createNextMiddleware.ts• L29-79 packages/…/createNextMiddleware.ts• L94-105 packages/…/createMiddlewareRouting.ts• L28-193 packages/…/resolveMiddlewareConfig.ts• L8-41 packages/…/defaultMiddlewareConfig.ts• L3-35 packages/…/utils.ts• L24-101 packages/…/utils.ts• L212-320 packages/…/localize-utils.ts• L58-71 packages/…/withGTConfigProps.ts• L47-66 packages/…/middleware.edge.test.ts• L443-597 packages/…/urlPreservation.edge.test.ts• L17-33

Routing modes

The integration supports both locale-prefixed and default-locale-unprefixed URLs. localeRouting controls whether middleware changes paths at all. prefixDefaultLocale controls whether the default locale appears in the URL. enableSmartRouting controls whether an unprefixed returning-visitor URL follows the saved locale or uses the default locale. pathConfig maps shared Next.js route paths to public aliases, while routeOverrides and localeRoutes control locale-specific internal routes and path availability. These options can be set in withGTConfig or passed to createNextMiddleware, with direct middleware options taking precedence. packages/…/types.ts• L11-34 packages/…/resolveMiddlewareConfig.ts• L24-41 packages/…/withGTConfigProps.ts• L47-66

With routing enabled, middleware keeps the public path and the internal Next.js route aligned. A localized public path can rewrite to a shared route. A missing or incorrect locale prefix can redirect to the canonical URL. A locale route list can send an unavailable page to the default locale instead of serving a page that does not exist for the selected locale. With routing disabled, the request still carries locale state, but middleware does not change the pathname. packages/…/createNextMiddleware.ts• L170-245 packages/…/createNextMiddleware.ts• L297-407 packages/…/localeRoutes.edge.test.ts• L36-94

Configured locale identities remain stable across routes and aliases. The locale spelling used by the application can differ from the service spelling, while route keys and public aliases keep the configured identity. Equivalent locale forms can resolve to the configured route without changing the value passed to application loaders. packages/…/createMiddlewareRouting.ts• L53-72 packages/…/createMiddlewareRouting.ts• L98-176 packages/…/localeSpelling.edge.test.ts• L30-106 packages/…/CHANGELOG.md• L296-304

References: packages/…/types.ts• L11-34 packages/…/defaultMiddlewareConfig.ts• L3-11 packages/…/resolveMiddlewareConfig.ts• L24-41 packages/…/createMiddlewareRouting.ts• L53-176 packages/…/createNextMiddleware.ts• L170-245 packages/…/createNextMiddleware.ts• L297-407 packages/…/withGTConfigProps.ts• L47-66 packages/…/localeRoutes.edge.test.ts• L36-94 packages/…/localeSpelling.edge.test.ts• L30-106 packages/…/CHANGELOG.md• L278-306

Path matching

Path matching turns shared and localized route patterns into a route map for middleware. It supports static segments, dynamic segments such as [id], catch-all segments, and optional catch-all segments. Static paths take priority over dynamic paths, while the matcher compares localized and shared candidates without treating the locale prefix as part of route specificity. This lets configured locale aliases keep their route spelling while still resolving to one shared page identity. packages/…/createPathMatcher.ts• L14-32 packages/…/matchPath.ts• L131-200

Path normalization compares encoded path segments in a stable form and preserves malformed escapes instead of rejecting the request. Route targets keep the source request's trailing-slash style. This lets localized paths with parameters map to the same shared route without changing unrelated URL spelling. packages/…/pathname.ts• L1-33 packages/…/utils.ts• L113-174 packages/…/urlPreservation.edge.test.ts• L35-155

The matcher treats static text in dynamic routes as literal text. It supports catch-all and index dynamic routes by segment, preserves encoded parameter values, and avoids confusing encoded bracket text with dynamic route syntax. packages/…/CHANGELOG.md• L331-343 packages/…/pathConfig.edge.test.ts• L453-497

References: packages/…/createPathMatcher.ts• L5-13 packages/…/createPathMatcher.ts• L34-139 packages/…/matchPath.ts• L14-113 packages/…/matchPath.ts• L131-200 packages/…/pathname.ts• L1-33 packages/…/pathConfig.edge.test.ts• L453-497 packages/…/urlPreservation.edge.test.ts• L35-155 packages/…/CHANGELOG.md• L331-343

Pages Router locale routing

The Pages Router uses Next.js internationalized routing as its primary source when context.locale is present. Configure the Next.js i18n settings with the supported locales and default locale, then wrap data functions with the matching gt-next helpers. The integration preserves a supported configured spelling such as a locale alias. An unsupported Next.js locale falls back to the configured GT default and warns. If Next.js does not provide a locale, the integration retains a request-based header, cookie, and browser-language fallback for compatibility. The build wrapper warns when the explicit GT config file and Next.js routing settings differ. For this comparison, GT's default locale counts as supported even when it is omitted from the GT locale list; locale order and duplicate entries do not create a mismatch. packages/…/parseLocale.ts• L22-50 packages/…/pagesRouter.test.ts• L78-245 packages/…/config.ts• L105-149 packages/…/config.test.ts• L316-412

References: packages/…/parseLocale.ts• L22-109 packages/…/pagesRouter.test.ts• L78-245 packages/…/config.ts• L105-149 packages/…/config.test.ts• L316-412

App Router locale routing

The App Router can use a dynamic [locale] segment when the locale belongs in the route tree. The root layout provides GTProvider and can set document language from getLocale. Middleware keeps that segment and any localized public path in sync with the request locale. tests/…/layout.tsx• L11-23 tests/…/proxy.ts• L1-6

References: packages/…/createNextMiddleware.ts• L170-407 packages/…/createPathMatcher.ts• L105-139 tests/…/layout.tsx• L11-23 tests/…/proxy.ts• L1-6

Server and client APIs

Server request APIs

The gt-next/server interface exposes request-scoped locale and region data as async functions. It also exposes useLocale and useRegion for Server Components that read those promises through React. Route Handlers and metadata or image handlers can call registerLocale first when the locale is supplied by a route parameter rather than the normal request context. packages/…/server.ts• L1-24 packages/…/getLocale.ts• L5-18 packages/…/getRegion.ts• L5-18 packages/…/registerLocale.ts• L5-12

The same server interface provides href localization and translation access. getLocalizeHref returns a function for server-generated navigation, while getTranslations, getMessages, and getGT provide dictionary or server translation access. tx and Tx translate content at request time when the application needs a value that is not known at build time. packages/…/server.ts• L16-29 packages/…/getLocalizeHref.ts• L6-38 packages/…/tx.ts• L15-57

References: packages/…/server.ts• L10-29 packages/…/getLocale.ts• L5-18 packages/…/getRegion.ts• L5-18 packages/…/registerLocale.ts• L5-12 packages/…/getLocalizeHref.ts• L6-56

Server translation APIs

The server translation APIs separate build-time content from runtime content. T renders translatable JSX, while getGT, getMessages, and getTranslations provide server-side string or dictionary access. tx and Tx translate content at request time when the application needs a value that is not known at build time. Each API uses the current request locale unless the API accepts an explicit locale. Route parameters can be checked with the locale validation helpers when an invalid locale must be rejected or reported instead of silently accepted. packages/…/T.tsx• L19-43 packages/…/strings.ts• L10-48 packages/…/tx.ts• L15-57 packages/…/_Tx.tsx• L6-39 packages/…/localeValidation.ts• L4-47

References: packages/…/server.ts• L19-29 packages/…/T.tsx• L19-43 packages/…/strings.ts• L10-48 packages/…/tx.ts• L15-57 packages/…/_Tx.tsx• L6-39 packages/…/localeValidation.ts• L19-47 packages/…/buildtime.test.ts• L38-191

Client APIs

Client components use the shared gt-next surface for locale state, translation hooks, selectors, and formatting components. They receive the current locale, region, i18n state, translation snapshot, and dictionary snapshot from GTProvider, so a client locale change can update the browser without loading server-only modules. useLocalizeHref uses the same routing policy as gt-next/link for router.push, button URLs, and other client navigation. packages/…/index.client.ts• L45-100 packages/…/useLocalizeHref.ts• L5-46 packages/…/GTProvider.tsx• L18-44

The client initializer uses the client-safe React cache rather than the Next.js server cache, and it does not expire entries because the browser receives data from the server and has no server loader to renew it. The shared initialization keeps the first configured Next.js cache and React i18n config for the process. Later initialization attempts do not replace an existing cache. packages/…/initGT.client.ts• L6-27 packages/…/initGT.test.ts• L117-136

References: packages/…/index.client.ts• L45-100 packages/…/useLocalizeHref.ts• L5-46 packages/…/initGT.client.ts• L6-27 packages/…/initGT.test.ts• L117-136 packages/…/GTProvider.tsx• L18-44

React Server Component APIs

The RSC surface is server-only and is selected by the react-server package condition. It provides Server Component versions of translation and formatting components plus request hooks. It also provides useLocalizeHref for server-rendered controls that need a localized destination. Client-only controls such as LocaleSelector and RegionSelector cross into the browser through a client boundary. Pages Router helpers are present only as error-producing placeholders on this surface, which prevents accidental use of the wrong routing model. packages/…/index.rsc.ts• L1-46 packages/…/getLocalizeHref.ts• L41-56 packages/…/RelativeTime.tsx• L1-16 packages/…/client-boundary.tsx• L1-13 packages/…/createErrors.ts• L80-99

The index.types entry supports editor and type-checking use without serving as a runtime entry. If application code executes that entry instead of importing a runtime surface, it receives a clear error. Its type declarations expose the Pages Router helpers and the shared translation, locale, formatting, and href-localization API in one type surface. packages/…/index.types.ts• L1-14 packages/…/index.types.ts• L358-475 packages/…/createErrors.ts• L74-92

References: packages/…/index.rsc.ts• L1-119 packages/…/getLocalizeHref.ts• L41-56 packages/…/RelativeTime.tsx• L1-16 packages/…/client-boundary.tsx• L1-13 packages/…/createErrors.ts• L74-99 packages/…/index.types.ts• L1-14 packages/…/index.types.ts• L358-475 packages/…/rscComponentWrappers.test.tsx• L61-165

Translation and dictionary data

Translation snapshots

GTProvider loads a translation snapshot for the active locale only when that locale requires translation. It always loads the dictionary snapshot, then sends both snapshots and the resolved locale, region, and i18n state to the client as provider state. Other locales can come from the remote translation service or a custom application loader. packages/…/GTProvider.tsx• L9-44 packages/…/shared.ts• L38-68 packages/…/resolveTranslationLoader.ts• L7-44

Pages Router data functions carry the locale and translation snapshot in page props. withGTServerSideProps does this for request-rendered pages. withGTStaticProps does it for generated pages and requires Next.js locale routing so generation runs for each locale. packages/…/withGTServerSideProps.ts• L11-49 packages/…/withGTStaticProps.ts• L19-59 packages/…/pagesRouter.test.ts• L248-531

References: packages/…/GTProvider.tsx• L9-44 packages/…/shared.ts• L38-68 packages/…/resolveTranslationLoader.ts• L7-44 packages/…/withGTServerSideProps.ts• L11-49 packages/…/withGTStaticProps.ts• L19-59 packages/…/pagesRouter.test.ts• L248-531

Dictionary loading

A dictionary is a structured set of keyed messages. The integration can bundle a source dictionary and can load locale dictionaries through a custom loadDictionary function. getTranslations and useTranslations provide server and client access to these keys, including nested objects and interpolation values. The provider supplies the loaded dictionary snapshot to client components. packages/…/getDictionary.ts• L3-27 packages/…/resolveDictionaryLoader.ts• L7-44 tests/…/client-demo.tsx• L7-25

The application chooses local translation and dictionary loading by naming loader paths in the GT configuration. The build wrapper resolves those paths and connects them to the server bundle. Its webpack path preserves these internal loader links when it processes the package's ESM output, while Turbopack keeps its separate build path. A loader that cannot be resolved is a build error, while a loader that does not export the expected function fails early in development. packages/…/config.ts• L386-475 packages/…/config.ts• L840-919 packages/…/createErrors.ts• L53-65 packages/…/config.test.ts• L763-821

References: packages/…/getDictionary.ts• L3-27 packages/…/resolveDictionaryLoader.ts• L7-44 packages/…/resolveTranslationLoader.ts• L7-44 packages/…/config.ts• L386-475 packages/…/config.ts• L840-919 packages/…/createErrors.ts• L53-65 packages/…/config.test.ts• L763-821

gt-next/link is a drop-in replacement for Next.js Link that localizes internal destinations. An omitted locale uses the current locale. A locale string targets that locale. locale={false} leaves the internal path unchanged. External URLs and paths outside pathRegex are never prefixed, while query strings and hash fragments remain part of the destination. The wrapper passes the localized destination to Next.js without forwarding the locale prop. packages/…/link.ts• L1-7 packages/…/Link.tsx• L9-21 packages/…/Link.tsx• L64-79 packages/…/localize-utils.ts• L58-71

Default-locale links follow the middleware policy. With prefixDefaultLocale: false, links for the current default locale stay unprefixed. An explicit default-locale target stays prefixed while smart routing is enabled, but becomes unprefixed when smart routing is disabled. These options must be set in withGTConfig, because Link reads the shared build configuration. packages/…/localize-utils.ts• L21-39 packages/…/Link.test.tsx• L106-160 packages/…/CHANGELOG.md• L133-136

useLocalizeHref applies the same policy to router.push, button URLs, and other navigation that does not render a link. Server Components use getLocalizeHref or the server version of useLocalizeHref; client components use the hook from gt-next or gt-next/link. The middleware still resolves aliases, route availability, redirects, and rewrites after the href is created. packages/…/useLocalizeHref.ts• L5-46 packages/…/getLocalizeHref.ts• L6-56 packages/…/createNextMiddleware.ts• L297-407 packages/…/Link.test.tsx• L221-270

Links and href helpers expect unlocalized internal paths. In development, an href that already starts with a configured locale produces one warning and is still prefixed. Pass locale={false} when the path must remain unchanged. packages/…/localize-utils.ts• L41-63 packages/…/link.ts• L3-10 packages/…/Link.test.tsx• L162-217

References: packages/…/link.ts• L1-7 packages/…/Link.tsx• L9-79 packages/…/localize-utils.ts• L7-83 packages/…/useLocalizeHref.ts• L5-46 packages/…/getLocalizeHref.ts• L6-56 packages/…/Link.test.tsx• L50-270 packages/…/link.ts• L3-10 packages/…/CHANGELOG.md• L119-136

Build plugin support

Next.js configuration wrapper

withGTConfig joins GT settings with the Next.js build configuration. It reads the GT config and credentials, validates locale and loader settings, and exposes the safe runtime settings needed by middleware and client code. It accepts object-based Next.js settings and sync or async config functions, so it can compose with other config plugins. packages/…/config.ts• L149-220 packages/…/config.ts• L225-359 packages/…/config.test.ts• L255-314

The wrapper accepts the middleware routing options as part of the build configuration. It sends those options to middleware through Next.js environment settings, while createNextMiddleware options still take precedence at request setup. In development, middleware warns when its direct routing values differ from the values that gt-next/link can read from withGTConfig. packages/…/withGTConfigProps.ts• L47-85 packages/…/config.ts• L643-779 packages/…/createNextMiddleware.ts• L23-57 packages/…/middleware.ts• L28-34

The wrapper keeps the application's own Next.js i18n configuration unchanged. When Next.js locale detection is enabled, it aligns GT's locale cookie with Next.js's NEXT_LOCALE cookie. It warns about mismatched locale values found in the explicit GT config file. The comparison includes GT's default locale and ignores only order and duplicate entries. packages/…/config.ts• L105-147 packages/…/config.ts• L249-337 packages/…/config.test.ts• L316-412 packages/…/CHANGELOG.md• L40-44

The wrapper connects configured dictionaries, loaders, and request functions to the server build through bundler aliases. It adds gt-next to transpiled packages and keeps the application's own webpack or Turbopack settings in the resulting config. This allows the same public API to work with local files without making those paths part of application code. packages/…/config.ts• L697-809 packages/…/config.test.ts• L1021-1181

The wrapper keeps the webpack rule narrow when it must process the package's ESM output for file aliases. It applies that rule only to the server build and only when an internal alias needs it. Turbopack uses its own alias settings instead. packages/…/config.test.ts• L1021-1181 packages/…/config.ts• L810-919

The configuration graph also runs in plain Node when Next.js loads next.config. Its compatibility layer supplies the Node require function and package distribution path in both CommonJS and ESM builds, without entering client bundles. Version checks use this boundary to read the installed Next.js and React versions and to locate the packaged compiler asset. ESM Next config files use this path without relying on an undefined require. packages/…/nodeCompat.ts• L1-21 packages/…/getStableNextVersionInfo.ts• L12-35 packages/…/CHANGELOG.md• L109-110

References: packages/…/config.ts• L105-147 packages/…/config.ts• L149-220 packages/…/config.ts• L225-359 packages/…/config.ts• L643-919 packages/…/withGTConfigProps.ts• L47-85 packages/…/createNextMiddleware.ts• L23-57 packages/…/middleware.ts• L15-34 packages/…/nodeCompat.ts• L1-21 packages/…/getStableNextVersionInfo.ts• L12-35 packages/…/config.test.ts• L255-412 packages/…/config.test.ts• L1021-1181 packages/…/CHANGELOG.md• L40-44

Translation compiler plugins

The build can use no compiler plugin, a Babel-based compiler, or the packaged SWC WebAssembly plugin. These plugins support build-time translation metadata and compiler checks. The SWC plugin is configured through Next.js compiler settings, while the Babel path is added to webpack when selected. gt-next installs @generaltranslation/compiler as a regular dependency, so the Babel compiler path does not need a separate compiler install. Full package builds include the SWC WebAssembly asset with the published package. packages/…/withGTConfigProps.ts• L12-38 packages/…/config.ts• L692-833 packages/…/package.json• L24-40 packages/…/CHANGELOG.md• L146-152 packages/…/CHANGELOG.md• L254-255

The wrapper checks the installed Next.js and React versions before enabling version-specific behavior. It handles the change from experimental to stable Turbopack settings and adds root parameter support only when the installed Next.js version supports the needed level. It also exposes whether locale refresh is supported, so the client boundary can choose refresh or reload behavior. SWC support starts at Next.js 16.1.0, Babel support requires React 17, root parameters become stable at Next.js 16.3.0, and stable Turbopack settings start at Next.js 15.3.0. The package peer range supports Next.js 13 and later but excludes the known 15.2.1 and 15.2.2 range. packages/…/getStableNextVersionInfo.ts• L75-126 packages/…/constants.ts• L1-15 packages/…/package.json• L6-9 packages/…/config.test.ts• L946-1019

References: packages/…/withGTConfigProps.ts• L12-38 packages/…/config.ts• L348-375 packages/…/config.ts• L692-833 packages/…/constants.ts• L1-15 packages/…/getStableNextVersionInfo.ts• L75-126 packages/…/nodeCompat.ts• L1-21 packages/…/package.json• L6-9 packages/…/package.json• L24-40 packages/…/config.test.ts• L946-1019 packages/…/CHANGELOG.md• L109-152

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the package export conditions aligned with the server, worker, browser, and React Server Component APIs. A condition mismatch can send a server-only helper into the client bundle.
  • Keep middleware cookie and header names aligned with the request condition store and the client provider. A mismatch can make the URL locale and rendered locale disagree.
  • Keep middleware routing options in withGTConfig aligned with direct createNextMiddleware options. Links read the former, while requests may use the latter.
  • When changing smart routing, check first visits, returning visitors, explicit default-locale prefixes, reset cookies, default-locale aliases, and browser-language negotiation together. These inputs have different priority in the locale decision.
  • When changing locale routing or pathConfig, check both the public URL decision and the shared route rewrite. Links, middleware, and App Router segments must use the same route model.
  • When changing route matching, check static, dynamic, catch-all, localized, and default-locale paths together. A precedence change can select a different shared route without changing the public URL.
  • When changing path normalization or response targets, check encoded segments, malformed escapes, base paths, trailing slashes, query strings, and same-origin handling together. A mismatch can make redirects and rewrites disagree about route identity.
  • When changing client locale synchronization, check non-default locale prefixes, explicit prefixes that alias the default locale, unprefixed default paths, and older Next.js refresh behavior together.
  • When changing loader paths or aliases, check webpack and Turbopack paths together. Local dictionaries and translations must resolve in the server build without entering the client bundle.
  • When changing Pages Router data wrappers, keep the locale and translation snapshot fields aligned with the GTProvider props in _app and with Next.js's active locale choice.
  • When changing Next.js i18n mismatch checks, keep GT's implicit default locale and the order-independent, duplicate-free locale comparison aligned with the warning text.
  • When changing locale spellings or custom mappings, check route keys, aliases, cookies, fallbacks, and locale availability as one contract. Lookup spelling and public route spelling can differ.
  • When changing the package build or compiler asset, check both the SWC configuration path and the published package contents. The compiler setting is not useful if the WebAssembly asset is absent.
  • When changing initialization or credential handling, keep the server cache, client-safe cache, React i18n config, and serialized runtime parameters on their intended sides of the server/client boundary. Check GT_* names, the removed GT_DEV_API_KEY name, and legacy public names together.
  • When changing Next.js peer support or compiler versions, check the version gates, compiler fallback warnings, Turbopack path, regular compiler dependency, Node config boundary, and published package asset together.

Important failure modes

TriggerConsequenceGuard
withGTStaticProps runs without Next.js locale routingStatic generation cannot identify the locale for the pageConfigure the Pages Router i18n block before using the wrapper. packages/…/withGTStaticProps.ts• L31-34
Middleware and Next.js matcher cover different path setsSome requests use locale state without a matching route, or assets enter locale routingAlign createNextMiddleware options with the exported Next.js matcher. packages/…/createNextMiddleware.ts• L94-105
createNextMiddleware() sets a routing option that differs from withGTConfig()Links can generate URLs that middleware redirectsSet shared link-routing options in withGTConfig; use direct middleware options only when the difference is intentional. packages/…/createNextMiddleware.ts• L48-57
pathRegex is written for locale-prefixed pathsMiddleware and href helpers leave intended localized paths unprefixedWrite pathRegex for paths without the locale prefix. packages/…/withGTConfigProps.ts• L64-66 packages/…/CHANGELOG.md• L121-123
Smart routing is disabled without accounting for first visits and reset cookiesReturning visitors use the default locale while an explicit reset or first browser visit may need another localeCheck the smart-routing contract for unprefixed paths and explicit default-locale prefixes. packages/…/utils.ts• L253-313 packages/…/middleware.edge.test.ts• L630-813
Middleware receives a locale spelling that is not in the configured locale setThe request falls back to the configured default or redirects to its canonical spellingKeep configured locale keys and custom mappings aligned with the public route spellings. packages/…/createMiddlewareRouting.ts• L53-96 packages/…/localeSpelling.edge.test.ts• L109-307
Shared and localized route patterns overlap with an unexpected precedenceMiddleware can rewrite a URL to the wrong shared routeKeep route shapes distinct or confirm the matcher priority for static, dynamic, and catch-all segments. packages/…/matchPath.ts• L14-102
A configured custom loader path does not existThe Next.js build stops before it can load translations or dictionariesResolve and validate loader paths through withGTConfig. packages/…/config.ts• L421-431 packages/…/config.ts• L535-560 packages/…/createErrors.ts• L53-65
A custom loader file exports neither a default function nor the named loaderDevelopment fails when the loader is resolved; production logs the unresolved loader errorExport the function expected by the selected loader. packages/…/resolveDictionaryLoader.ts• L23-42 packages/…/resolveTranslationLoader.ts• L23-42
cacheComponents is enabled without custom loadTranslationsThe build stops because cached components need a fixed local translation sourceConfigure a custom translation loader before enabling cacheComponents. packages/…/config.ts• L563-573 packages/…/config.test.ts• L845-887
A server API is imported from a client or RSC-incompatible surfaceThe call throws instead of reading request stateUse gt-next/server for server request APIs and use the shared surface for client components. packages/…/index.client.ts• L19-43 packages/…/index.rsc.ts• L50-91
An href already includes a locale and is passed to Link or useLocalizeHrefThe locale can be prefixed twicePass an unlocalized path or use locale={false}. packages/…/link.ts• L3-10 packages/…/Link.test.tsx• L162-183
The published package lacks the SWC WebAssembly assetNext.js cannot use the packaged SWC compiler path even when the build setting is enabledRun the full package build and verify the asset is present in the published output. packages/…/package.json• L36-40
A supported Next.js version falls outside the declared peer rangeDependency resolution can fail or version-specific build behavior can be unsafeUse a Next.js version allowed by gt-next's peer range. packages/…/package.json• L6-9
The config graph runs in a browser bundleNode-only package lookup can break the client buildKeep nodeCompat imports inside the gt-next/config graph. packages/…/nodeCompat.ts• L5-12
Production relies on a development-only credential nameRuntime translation can lack its API key, or a development key can be handled as an unsafe client valueUse GT_PROJECT_ID and GT_API_KEY for runtime translation. Legacy public names are fallback inputs, GT_DEV_API_KEY is not read, and development credentials are not serialized in production. packages/…/runtimeCredentials.ts• L1-19 packages/…/config.test.ts• L615-669 packages/…/CHANGELOG.md• L61-65
An ESM Next config loads the config wrapper through an unavailable requirewithGTConfig cannot resolve the installed Next.js version and config loading failsUse the current Node compatibility path, which supports ESM config loading. packages/…/CHANGELOG.md• L109-110

Key files

FileWhy to read it
packages/…/README.mdThe package goal and shortest installation path.
packages/…/package.jsonThe public entry conditions, supported Next.js and React peer ranges, compiler dependency, and package build scripts.
packages/…/packageExports.test.tsThe package export, server-versus-browser selection, and published compiler asset contract.
packages/…/config.tsThe boundary between GT settings and the Next.js build.
packages/…/withGTConfigProps.tsThe shared build, middleware, credential, and compiler settings accepted by withGTConfig.
packages/…/runtimeCredentials.tsThe current and legacy environment names used for runtime credentials.
packages/…/shared.tsThe handoff from build-time configuration and environment credentials to runtime setup.
packages/…/createNextMiddleware.tsThe locale detection and redirect or rewrite flow.
packages/…/createMiddlewareRouting.tsThe prepared locale and route model used by middleware.
packages/…/resolveMiddlewareConfig.tsThe precedence rules for middleware options.
packages/…/defaultMiddlewareConfig.tsThe default routing policy and option split.
packages/…/createPathMatcher.tsThe route pattern model used to map dynamic and localized paths.
packages/…/matchPath.tsThe route selection rules for shared and localized paths.
packages/…/pathname.tsPath normalization and trailing-slash rules for middleware targets.
packages/…/GTProvider.tsxThe server-to-client handoff for locale, translations, dictionaries, and i18n state.
packages/…/client-boundary.tsxThe App Router bridge that keeps client locale state and server content aligned.
packages/…/server.tsThe server-only request, href, and translation API surface.
packages/…/index.rsc.tsThe App Router React Server Component surface.
packages/…/index.client.tsThe browser surface and server API safeguards.
packages/…/index.types.tsThe type-only API contract for Pages Router, translation, locale, formatting, and href helpers.
packages/…/RelativeTime.tsxThe request-aware RSC formatting example.
packages/…/createErrors.tsThe diagnostics for invalid runtime entry points, loaders, credentials, and compiler support.