Skip to content

Commit f138c20

Browse files
fix: cannot update states of options-api (#395)
1 parent 3fb3229 commit f138c20

File tree

15 files changed

+153
-20
lines changed

15 files changed

+153
-20
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"stub:applet": "turbo stub --filter=./packages/applet",
3232
"stub:vite": "turbo stub --filter=./packages/vite",
3333
"stub:devtools-api": "turbo stub --filter=./packages/devtools-api...",
34+
"build:applet": "turbo build --filter=./packages/applet...",
3435
"build:shared": "turbo build --filter=./packages/shared...",
3536
"build:core": "turbo build --filter=./packages/core...",
3637
"build:devtools-kit": "turbo build --filter=./packages/devtools-kit...",
@@ -62,6 +63,7 @@
6263
"play:multi-app": "turbo dev --filter=./packages/playground/multi-app",
6364
"play:webpack": "turbo dev --filter=./packages/playground/webpack",
6465
"play:termui": "turbo dev --filter=./packages/playground/termui",
66+
"play:options-api": "turbo dev --filter=./packages/playground/options-api",
6567
"docs": "pnpm -C docs run docs:dev",
6668
"docs:build": "pnpm -C docs run docs:build",
6769
"zip": "tsx ./scripts/extension-zip.ts",

packages/applet/src/components/state/StateFieldViewer.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function submit() {
137137
path: normalizedPath.value,
138138
inspectorId: state.value.inspectorId,
139139
type: data.stateType!,
140-
nodeId,
140+
nodeId: nodeId.value,
141141
state: {
142142
newKey: null!,
143143
type: editingType.value,
@@ -164,7 +164,7 @@ function submitDrafting() {
164164
path: [...normalizedPath.value, draftingNewProp.value.key],
165165
inspectorId: state.value.inspectorId,
166166
type: data.stateType!,
167-
nodeId,
167+
nodeId: nodeId.value,
168168
state: {
169169
newKey: draftingNewProp.value.key,
170170
type: typeof toSubmit(draftingNewProp.value.value),

packages/applet/src/composables/state-editor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { InjectionKey, Ref } from 'vue'
2-
import { inject, provide, ref } from 'vue'
2+
import { computed, inject, provide, ref } from 'vue'
33

44
interface StateEditorContext {
55
nodeId: string
@@ -40,7 +40,7 @@ export function useStateEditor() {
4040
editing.value = !editing.value
4141
},
4242
editingType,
43-
nodeId: state.value.nodeId,
43+
nodeId: computed(() => state.value.nodeId),
4444
}
4545
}
4646

packages/devtools-kit/src/core/component/state/editor.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,13 @@ export async function editComponentState(payload: InspectorStateEditorPayload, s
160160
let target: Record<string, unknown> | undefined
161161

162162
// TODO: props
163-
if (instance.devtoolsRawSetupState && Object.keys(instance.devtoolsRawSetupState).includes(path[0])) {
164-
// Setup
163+
164+
// 1. check if is setup
165+
if (instance.devtoolsRawSetupState && Object.keys(instance.devtoolsRawSetupState).includes(path[0]))
165166
target = instance.devtoolsRawSetupState
166-
}
167+
// 2. check if is options
168+
if (instance.data && Object.keys(instance.data).includes(path[0]))
169+
target = instance.data
167170

168171
if (target && targetPath) {
169172
if (state.type === 'object' && type === 'reactive') {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vue DevTools Basic Playground</title>
8+
</head>
9+
<style>
10+
html {
11+
color-scheme: dark;
12+
}
13+
</style>
14+
<body>
15+
<div id="app"></div>
16+
<script type="module" src="/src/main.ts"></script>
17+
</body>
18+
</html>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "playground-options-api",
3+
"type": "module",
4+
"version": "7.2.1",
5+
"private": true,
6+
"scripts": {
7+
"dev": "vite"
8+
},
9+
"dependencies": {
10+
"vue": "^3.4.27"
11+
},
12+
"devDependencies": {
13+
"@vitejs/plugin-vue": "^5.0.4",
14+
"vite-plugin-vue-devtools": "workspace:*"
15+
}
16+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup lang="ts">
2+
import Options from './Options.vue'
3+
import Setup from './Setup.vue'
4+
</script>
5+
6+
<template>
7+
<div>
8+
<Options />
9+
<Setup />
10+
</div>
11+
</template>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script lang="ts">
2+
export default {
3+
data() {
4+
return {
5+
name: 'Vue',
6+
}
7+
},
8+
}
9+
</script>
10+
11+
<template>
12+
<div>
13+
Options: {{ name }}
14+
</div>
15+
</template>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup lang="ts">
2+
import { ref } from 'vue'
3+
4+
const name = ref('Vue')
5+
</script>
6+
7+
<template>
8+
<div>
9+
Setup: {{ name }}
10+
</div>
11+
</template>

0 commit comments

Comments
 (0)