Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

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

Merged
merged 2 commits into from Nov 24, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/bridge/src/runtime/composables.ts
@@ -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'
Expand Down Expand Up @@ -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()
Expand Down