fix(bridge): fixed reactivity on csr of useState reactive payload (#2134)

This commit is contained in:
Matteo Rigoni 2021-11-24 16:44:02 +01:00 committed by GitHub
parent 4efd72d5d4
commit ae80e5bdc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
import { getCurrentInstance, onBeforeUnmount, isRef, watch, reactive, toRef, isReactive, Ref } from '@vue/composition-api'
import { getCurrentInstance, onBeforeUnmount, isRef, watch, reactive, toRef, isReactive, Ref, set } from '@vue/composition-api'
import type { CombinedVueInstance } from 'vue/types/vue'
import type { MetaInfo } from 'vue-meta'
import type VueRouter from 'vue-router'
@ -57,6 +57,12 @@ export const useState = <T>(key: string, init?: (() => T)): Ref<T> => {
if (!isReactive(nuxtApp.payload.useState)) {
nuxtApp.payload.useState = reactive(nuxtApp.payload.useState)
}
// see @vuejs/composition-api reactivity tracking on a reactive object with set
if (!(key in nuxtApp.payload.useState)) {
set(nuxtApp.payload.useState, key, undefined)
}
const state = toRef(nuxtApp.payload.useState, key)
if (state.value === undefined && init) {
state.value = init()