fix(nuxt): better equality check for json cookies (#6352)

This commit is contained in:
Daniel Roe 2022-08-04 11:58:15 +01:00 committed by GitHub
parent d8cdd97f02
commit 4732d2ce3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ import { parse, serialize, CookieParseOptions, CookieSerializeOptions } from 'co
import { appendHeader } from 'h3'
import type { CompatibilityEvent } from 'h3'
import destr from 'destr'
import { isEqual } from 'ohash'
import { useRequestEvent } from './ssr'
import { wrapInRef } from './utils'
import { useNuxtApp } from '#app'
@ -34,7 +35,7 @@ export function useCookie <T=string> (name: string, _opts?: CookieOptions<T>): C
} else if (process.server) {
const nuxtApp = useNuxtApp()
const writeFinalCookieValue = () => {
if (cookie.value !== cookies[name]) {
if (!isEqual(cookie.value, cookies[name])) {
writeServerCookie(useRequestEvent(nuxtApp), name, cookie.value, opts)
}
}