Skip to content

Commit 34d103e

Browse files
committed
fix(web): avoid mutating array in locale sorting
- Use spread operator to create copy before sorting
1 parent 4f49edf commit 34d103e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/web/src/middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ function localeFromAcceptLanguage(header: string | null) {
6666
q: q ? Number.parseFloat(q) : 1,
6767
}
6868
})
69-
.sort((a, b) => b.q - a.q)
69+
const sorted = [...items].sort((a, b) => b.q - a.q)
7070

71-
const locale = items
71+
const locale = sorted
7272
.map((item) => item.lang)
7373
.filter((lang) => lang && lang !== "*")
7474
.map((lang) => matchLocale(lang))

0 commit comments

Comments
 (0)