Skip to content

Commit 2e27cd3

Browse files
committed
refactor(nuxt): use isEqual from ohash/utils
1 parent f709e57 commit 2e27cd3

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ export default createConfigForNuxt({
203203
'perfect-debounce',
204204
'radix3',
205205
'ohash',
206+
'ohash/utils',
206207
'pathe',
207208
'uncrypto',
208209
// internal deps

packages/nuxt/src/app/composables/cookie.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { parse, serialize } from 'cookie-es'
55
import { deleteCookie, getCookie, getRequestHeader, setCookie } from 'h3'
66
import type { H3Event } from 'h3'
77
import destr from 'destr'
8-
import { hash } from 'ohash'
8+
import { isEqual } from 'ohash/utils'
99
import { klona } from 'klona'
1010
import { useNuxtApp } from '../nuxt'
1111
import { useRequestEvent } from './ssr'
@@ -75,7 +75,7 @@ export function useCookie<T = string | null | undefined> (name: string, _opts?:
7575
// or running in an iframe: see https://github.com/nuxt/nuxt/issues/26338
7676
}
7777
const callback = () => {
78-
if (opts.readonly || hash(cookie.value) === hash(cookies[name])) { return }
78+
if (opts.readonly || isEqual(cookie.value, cookies[name])) { return }
7979
writeClientCookie(name, cookie.value, opts as CookieSerializeOptions)
8080

8181
cookies[name] = klona(cookie.value)
@@ -136,11 +136,11 @@ export function useCookie<T = string | null | undefined> (name: string, _opts?:
136136
} else if (import.meta.server) {
137137
const nuxtApp = useNuxtApp()
138138
const writeFinalCookieValue = () => {
139-
if (opts.readonly || hash(cookie.value) === hash(cookies[name])) { return }
139+
if (opts.readonly || isEqual(cookie.value, cookies[name])) { return }
140140
nuxtApp._cookies ||= {}
141141
if (name in nuxtApp._cookies) {
142142
// do not append a second `set-cookie` header
143-
if (hash(cookie.value) === hash(nuxtApp._cookies[name])) { return }
143+
if (isEqual(cookie.value, nuxtApp._cookies[name])) { return }
144144
// warn in dev mode
145145
if (import.meta.dev) {
146146
console.warn(`[nuxt] cookie \`${name}\` was previously set to \`${opts.encode(nuxtApp._cookies[name] as any)}\` and is being overridden to \`${opts.encode(cookie.value as any)}\`. This may cause unexpected issues.`)

0 commit comments

Comments
 (0)