From 6994dc2ce669edf44ffef77092e4dd835a9b7261 Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Wed, 28 Oct 2026 03:46:40 +0100 Subject: [PATCH] fix: send a Lite link without a language to the same page in the reader's language instead of a bare 404 --- lib/__tests__/lite-scripts.test.ts | 24 ++++++++++++++++- scripts/lite/lib.mjs | 42 +++++++++++++++++++++++++----- scripts/lite/postbuild.mjs | 2 +- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/lib/__tests__/lite-scripts.test.ts b/lib/__tests__/lite-scripts.test.ts index e879ebb6f..7eb8bf3e2 100644 --- a/lib/__tests__/lite-scripts.test.ts +++ b/lib/__tests__/lite-scripts.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; import { createHash } from 'node:crypto'; import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, existsSync } from 'node:fs'; import { tmpdir } from 'node:os'; @@ -208,6 +208,28 @@ describe('lite build helpers', () => { expect(LITE_PENDING_PATH_KEY).toBe(APP_LITE_PENDING_PATH_KEY); }); + it('sends a path without a locale to the same path in the reader locale', () => { + const html = buildNotFoundShim({ basePath: '/webmail', locales: ['de', 'en', 'zh-TW'], defaultLocale: 'en' }); + const script = html.match(/ diff --git a/scripts/lite/postbuild.mjs b/scripts/lite/postbuild.mjs index 744b95726..dbe423c25 100644 --- a/scripts/lite/postbuild.mjs +++ b/scripts/lite/postbuild.mjs @@ -78,7 +78,7 @@ function staticFiles({ config, basePath, locales, defaultLocale, version, commit "index.html": buildRootRedirect({ basePath, locales, defaultLocale }), // Replaces Next's default not-found page: only this shim replays deep links // on hosts without rewrite rules (see buildNotFoundShim). - "404.html": buildNotFoundShim({ basePath, locales }), + "404.html": buildNotFoundShim({ basePath, locales, defaultLocale }), "_redirects": buildRedirects({ basePath, locales }), "_headers": buildHeaders({ basePath, connectSrc }), "nginx.conf.example": buildNginxExample({ basePath, connectSrc }),