[PR #1069] [MERGED] refactor(i18n): dedupe NEXT_LOCALE cookie parsing #1067

Closed
opened 2026-05-06 13:11:49 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/1069
Author: @james-elicx
Created: 5/5/2026
Status: Merged
Merged: 5/5/2026
Merged by: @james-elicx

Base: mainHead: refactor/dedupe-locale-cookie-parsing


📝 Commits (1)

  • 229d38d refactor(i18n): dedupe NEXT_LOCALE cookie parsing

📊 Changes

1 file changed (+0 additions, -10 deletions)

View changed files

📝 packages/vinext/src/entries/pages-server-entry.ts (+0 -10)

📄 Description

Summary

  • Remove the dead parseCookieLocaleFromHeader helper from the Pages SSR entry template (packages/vinext/src/entries/pages-server-entry.ts). It duplicated the regex + decodeURIComponent pattern already exported from packages/vinext/src/server/pages-i18n.ts.
  • The duplicate had no callers in the generated server entry — locale resolution flows through resolvePagesI18nRequest, which already calls the canonical parseCookieLocaleFromHeader from pages-i18n.ts internally.
  • Follow-up to #1049 (which extracted a similar helper for param decoding).

Why deletion rather than import-and-call

I started by checking whether the entry should import { parseCookieLocaleFromHeader } from pages-i18n.ts. It turns out the local copy in the entry template is dead code: defined inside the SSR-entry template literal but never invoked. The single locale-resolution call site (_renderPage) already delegates to resolvePagesI18nRequest, so the cleanest dedupe is removal of the duplicate definition rather than a dangling import.

The two implementations were behaviorally equivalent (same regex /(?:^|;\s*)NEXT_LOCALE=([^;]*)/, same decodeURIComponent(match[1].trim()), same allow-list check against i18nConfig.locales). No behavior change.

Files changed

  • packages/vinext/src/entries/pages-server-entry.ts — remove dead parseCookieLocaleFromHeader (10 lines deleted).

Out-of-scope notes

Two adjacent helpers in the same template are also dead code: extractLocale and detectLocaleFromHeaders. Left untouched per "only fix what's in scope" — happy to clean them up in a separate PR.

Test plan

  • pnpm vp test run tests/pages-router.test.ts — 200/200 pass
  • pnpm fmt --write on touched file
  • CI green

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/1069 **Author:** [@james-elicx](https://github.com/james-elicx) **Created:** 5/5/2026 **Status:** ✅ Merged **Merged:** 5/5/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `refactor/dedupe-locale-cookie-parsing` --- ### 📝 Commits (1) - [`229d38d`](https://github.com/cloudflare/vinext/commit/229d38db98aeaa12976ad479bec9cd812a629904) refactor(i18n): dedupe NEXT_LOCALE cookie parsing ### 📊 Changes **1 file changed** (+0 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/pages-server-entry.ts` (+0 -10) </details> ### 📄 Description ## Summary - Remove the dead `parseCookieLocaleFromHeader` helper from the Pages SSR entry template (`packages/vinext/src/entries/pages-server-entry.ts`). It duplicated the regex + `decodeURIComponent` pattern already exported from `packages/vinext/src/server/pages-i18n.ts`. - The duplicate had no callers in the generated server entry — locale resolution flows through `resolvePagesI18nRequest`, which already calls the canonical `parseCookieLocaleFromHeader` from `pages-i18n.ts` internally. - Follow-up to #1049 (which extracted a similar helper for param decoding). ## Why deletion rather than import-and-call I started by checking whether the entry should `import { parseCookieLocaleFromHeader }` from `pages-i18n.ts`. It turns out the local copy in the entry template is dead code: defined inside the SSR-entry template literal but never invoked. The single locale-resolution call site (`_renderPage`) already delegates to `resolvePagesI18nRequest`, so the cleanest dedupe is removal of the duplicate definition rather than a dangling import. The two implementations were behaviorally equivalent (same regex `/(?:^|;\s*)NEXT_LOCALE=([^;]*)/`, same `decodeURIComponent(match[1].trim())`, same allow-list check against `i18nConfig.locales`). No behavior change. ## Files changed - `packages/vinext/src/entries/pages-server-entry.ts` — remove dead `parseCookieLocaleFromHeader` (10 lines deleted). ## Out-of-scope notes Two adjacent helpers in the same template are also dead code: `extractLocale` and `detectLocaleFromHeaders`. Left untouched per "only fix what's in scope" — happy to clean them up in a separate PR. ## Test plan - [x] `pnpm vp test run tests/pages-router.test.ts` — 200/200 pass - [x] `pnpm fmt --write` on touched file - [ ] CI green 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:11:49 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#1067
No description provided.