|
1 | 1 | import { nextTick, App, ComponentPublicInstance, VNode } from 'vue'
|
2 |
| -import { EMPTY_OBJ as VUE_UNWRITABLE_PLACEHOLDER_OBJECT } from '@vue/shared' |
3 | 2 | import * as reactivity from '@vue/reactivity'
|
4 | 3 |
|
5 | 4 | import { config } from './config'
|
@@ -249,29 +248,27 @@ export class VueWrapper<
|
249 | 248 | }
|
250 | 249 |
|
251 | 250 | setData(data: Record<string, unknown>): Promise<void> {
|
252 |
| - // setupState is always defined, |
253 |
| - // Even when using the object api without defining a setup() function |
254 |
| - // Check if the setupState actually originates from <script setup> |
| 251 | + /* |
| 252 | + Depending on how the component was defined, data can live in different places |
| 253 | + Vue sets some default placeholder in all the locations however, so we cannot just check |
| 254 | + if the data object exists or not. |
| 255 | + When using <script setup>, data lives in the setupState object, which is then marked with __isScriptSetup |
| 256 | + When using the setup() function, data lives in the setupState object, but is not marked with __isScriptSetup |
| 257 | + When using the object api, data lives in the data object, proxied through $data, HOWEVER |
| 258 | + the setupState object will also exist, and be frozen. |
| 259 | + */ |
255 | 260 | // @ts-ignore
|
256 | 261 | if (this.componentVM.$.setupState.__isScriptSetup) {
|
257 |
| - // result from <script setup> |
| 262 | + // data from <script setup> |
258 | 263 | // @ts-ignore
|
259 | 264 | mergeDeep(this.componentVM.$.setupState, data)
|
260 |
| - } else if ( |
261 | 265 | // @ts-ignore
|
262 |
| - this.componentVM.$.setupState != null && |
263 |
| - // Vue always defined the setupState property |
264 |
| - // However, it uses a shared readonly singleton if the component doesn't define a setup() |
265 |
| - // Check this and don't use it. |
266 |
| - // @ts-ignore |
267 |
| - this.componentVM.$.setupState !== VUE_UNWRITABLE_PLACEHOLDER_OBJECT |
268 |
| - ) { |
269 |
| - // is the return value of the setup() function when using the object api, |
270 |
| - // i.e. defineComponent({ setup() {} }) |
| 266 | + } else if (!Object.isFrozen(this.componentVM.$.setupState)) { |
| 267 | + // data from setup() function when using the object api |
271 | 268 | // @ts-ignore
|
272 | 269 | mergeDeep(reactivity.proxyRefs(this.componentVM.$.setupState), data)
|
273 | 270 | } else {
|
274 |
| - // is the data object when using the object api |
| 271 | + // data when using data: {...} in the object api |
275 | 272 | mergeDeep(this.componentVM.$data, data)
|
276 | 273 | }
|
277 | 274 | return nextTick()
|
|
0 commit comments