Skip to content

fix(platform-web): accept null in parseLocales for a missing Accept-Language header - #244

Merged
dangreen merged 1 commit into
mainfrom
fix/parse-locales-null
Sep 8, 2026
Merged

dangreen merged 1 commit into
mainfrom
fix/parse-locales-null

Conversation

@dangreen

@dangreen dangreen commented Sep 8, 2026

Copy link
Copy Markdown
Member

Why

Headers.get('accept-language') returns null when the request has no Accept-Language header. parseLocales(acceptLanguage = '') only defaulted undefined and then read acceptLanguage.length, so the example from the docs, parseLocales(request.headers.get('accept-language')), threw TypeError: Cannot read properties of null (reading 'length') on the first request without the header (curl, bots, health checks). Under strict TypeScript the example did not even type-check, since string | null is not assignable to string | undefined.

The built-in SSR renderer was not affected: it passes headers?.acceptLanguage, which is typed string | undefined.

What

  • parseLocales now takes acceptLanguage?: string | null and normalizes it with acceptLanguage ||= '', so null behaves like undefined and '': { language: 'en', languages: ['en'] }.
  • eslint/no-param-reassign is turned off for the package in oxlint.config.ts, the same way agera does it. A local const would have cost 4 B of gzip and pushed the package over its 3.4 kB size limit; the reassignment keeps it at 3399 B.
  • New test: should fallback to english when header is null.

Checks

  • oxlint, tsc --noEmit, vitest run (58 tests) in packages/platform-web pass.
  • size-limit: 3399 B gzip (limit 3400 B), 3027 B brotli (limit 3.05 kB).

…ept-Language` header

`Headers.get('accept-language')` returns `null` when the request carries no such header, while `parseLocales` only defaulted `undefined` and then read `.length`, so the documented `parseLocales(request.headers.get('accept-language'))` threw on the first request without the header. The parameter is now `string | null | undefined`, and both missing shapes fall back to `en` like an empty header does.
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.32%. Comparing base (13a2eb3) to head (3b0973e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #244      +/-   ##
==========================================
+ Coverage   83.28%   83.32%   +0.03%     
==========================================
  Files          98       98              
  Lines        2554     2554              
  Branches      549      549              
==========================================
+ Hits         2127     2128       +1     
  Misses        314      314              
+ Partials      113      112       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dangreen
dangreen merged commit 1e29516 into main Sep 8, 2026
10 checks passed
@dangreen
dangreen deleted the fix/parse-locales-null branch September 8, 2026 14:34
@github-actions github-actions Bot mentioned this pull request Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant