@dianzhong/create-harness-app 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/harness/full/.claude/agents/code-reviewer.md +1 -1
- package/templates/harness/full/.claude/agents/harness-reviewer.md +0 -2
- package/templates/harness/full/.claude/rules/skills-mcp.md +2 -3
- package/templates/harness/full/.claude/settings.json +1 -1
- package/templates/harness/full/docs/ai-harness.md +4 -6
- package/templates/harness/full/docs/harness-quick-reference.md +1 -1
- package/templates/harness/full/docs/review-checklist.md +1 -1
- package/templates/harness/full/scripts/verify-skills.mjs +6 -61
- package/templates/harness/full/scripts/verify-skills.test.mjs +1 -11
- package/templates/harness/full/.agents/skills/find-skills/SKILL.md +0 -143
- package/templates/harness/full/.agents/skills/vue-best-practices/LICENSE.md +0 -21
- package/templates/harness/full/.agents/skills/vue-best-practices/SKILL.md +0 -155
- package/templates/harness/full/.agents/skills/vue-best-practices/SYNC.md +0 -5
- package/templates/harness/full/.agents/skills/vue-best-practices/references/animation-class-based-technique.md +0 -258
- package/templates/harness/full/.agents/skills/vue-best-practices/references/animation-state-driven-technique.md +0 -287
- package/templates/harness/full/.agents/skills/vue-best-practices/references/component-async.md +0 -99
- package/templates/harness/full/.agents/skills/vue-best-practices/references/component-data-flow.md +0 -313
- package/templates/harness/full/.agents/skills/vue-best-practices/references/component-fallthrough-attrs.md +0 -179
- package/templates/harness/full/.agents/skills/vue-best-practices/references/component-keep-alive.md +0 -139
- package/templates/harness/full/.agents/skills/vue-best-practices/references/component-slots.md +0 -226
- package/templates/harness/full/.agents/skills/vue-best-practices/references/component-suspense.md +0 -231
- package/templates/harness/full/.agents/skills/vue-best-practices/references/component-teleport.md +0 -110
- package/templates/harness/full/.agents/skills/vue-best-practices/references/component-transition-group.md +0 -131
- package/templates/harness/full/.agents/skills/vue-best-practices/references/component-transition.md +0 -135
- package/templates/harness/full/.agents/skills/vue-best-practices/references/composables.md +0 -303
- package/templates/harness/full/.agents/skills/vue-best-practices/references/directives.md +0 -168
- package/templates/harness/full/.agents/skills/vue-best-practices/references/perf-avoid-component-abstraction-in-lists.md +0 -177
- package/templates/harness/full/.agents/skills/vue-best-practices/references/perf-v-once-v-memo-directives.md +0 -185
- package/templates/harness/full/.agents/skills/vue-best-practices/references/perf-virtualize-large-lists.md +0 -182
- package/templates/harness/full/.agents/skills/vue-best-practices/references/plugins.md +0 -178
- package/templates/harness/full/.agents/skills/vue-best-practices/references/reactivity.md +0 -371
- package/templates/harness/full/.agents/skills/vue-best-practices/references/render-functions.md +0 -227
- package/templates/harness/full/.agents/skills/vue-best-practices/references/sfc.md +0 -355
- package/templates/harness/full/.agents/skills/vue-best-practices/references/state-management.md +0 -138
- package/templates/harness/full/.agents/skills/vue-best-practices/references/updated-hook-performance.md +0 -193
- package/templates/harness/full/AGENTS.md +0 -3
- package/templates/harness/full/GEMINI.md +0 -3
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Avoid Expensive Operations in Updated Hook
|
|
3
|
-
impact: MEDIUM
|
|
4
|
-
impactDescription: Heavy computations in updated hook cause performance bottlenecks and potential infinite loops
|
|
5
|
-
type: capability
|
|
6
|
-
tags: [vue3, vue2, lifecycle, updated, performance, optimization, reactivity]
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# Avoid Expensive Operations in Updated Hook
|
|
10
|
-
|
|
11
|
-
**Impact: MEDIUM** - The `updated` hook runs after every reactive state change that causes a re-render. Placing expensive operations, API calls, or state mutations here can cause severe performance degradation, infinite loops, and dropped frames below the optimal 60fps threshold.
|
|
12
|
-
|
|
13
|
-
Use `updated`/`onUpdated` sparingly for post-DOM-update operations that cannot be handled by watchers or computed properties. For most reactive data handling, prefer watchers (`watch`/`watchEffect`) which provide more control over what triggers the callback.
|
|
14
|
-
|
|
15
|
-
## Task List
|
|
16
|
-
|
|
17
|
-
- Never perform API calls in updated hook
|
|
18
|
-
- Never mutate reactive state inside updated (causes infinite loops)
|
|
19
|
-
- Use conditional checks to verify updates are relevant before acting
|
|
20
|
-
- Prefer `watch` or `watchEffect` for reacting to specific data changes
|
|
21
|
-
- Use throttling/debouncing if updated operations are expensive
|
|
22
|
-
- Reserve updated for low-level DOM synchronization tasks
|
|
23
|
-
|
|
24
|
-
**BAD:**
|
|
25
|
-
|
|
26
|
-
```javascript
|
|
27
|
-
// BAD: API call in updated - fires on every re-render
|
|
28
|
-
export default {
|
|
29
|
-
data() {
|
|
30
|
-
return { items: [], lastUpdate: null }
|
|
31
|
-
},
|
|
32
|
-
updated() {
|
|
33
|
-
// This runs after every single state change!
|
|
34
|
-
fetch('/api/sync', {
|
|
35
|
-
method: 'POST',
|
|
36
|
-
body: JSON.stringify(this.items),
|
|
37
|
-
})
|
|
38
|
-
},
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
```javascript
|
|
43
|
-
// BAD: State mutation in updated - infinite loop
|
|
44
|
-
export default {
|
|
45
|
-
data() {
|
|
46
|
-
return { renderCount: 0 }
|
|
47
|
-
},
|
|
48
|
-
updated() {
|
|
49
|
-
// This causes another update, which triggers updated again!
|
|
50
|
-
this.renderCount++ // Infinite loop
|
|
51
|
-
},
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
```javascript
|
|
56
|
-
// BAD: Heavy computation on every update
|
|
57
|
-
export default {
|
|
58
|
-
updated() {
|
|
59
|
-
// Expensive operation runs on every keystroke, every state change
|
|
60
|
-
this.processedData = this.heavyComputation(this.rawData)
|
|
61
|
-
this.analytics = this.calculateMetrics(this.allData)
|
|
62
|
-
},
|
|
63
|
-
}
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
**GOOD:**
|
|
67
|
-
|
|
68
|
-
```javascript
|
|
69
|
-
import debounce from 'lodash-es/debounce'
|
|
70
|
-
|
|
71
|
-
// GOOD: Use watcher for specific data changes
|
|
72
|
-
export default {
|
|
73
|
-
data() {
|
|
74
|
-
return { items: [] }
|
|
75
|
-
},
|
|
76
|
-
watch: {
|
|
77
|
-
// Only fires when items actually changes
|
|
78
|
-
items: {
|
|
79
|
-
handler(newItems) {
|
|
80
|
-
this.syncToServer(newItems)
|
|
81
|
-
},
|
|
82
|
-
deep: true,
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
methods: {
|
|
86
|
-
syncToServer: debounce((items) => {
|
|
87
|
-
fetch('/api/sync', {
|
|
88
|
-
method: 'POST',
|
|
89
|
-
body: JSON.stringify(items),
|
|
90
|
-
})
|
|
91
|
-
}, 500),
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
```vue
|
|
97
|
-
<!-- GOOD: Composition API with targeted watchers -->
|
|
98
|
-
<script setup>
|
|
99
|
-
import { useDebounceFn } from '@vueuse/core'
|
|
100
|
-
import { onUpdated, ref, watch } from 'vue'
|
|
101
|
-
|
|
102
|
-
const items = ref([])
|
|
103
|
-
const scrollContainer = ref(null)
|
|
104
|
-
|
|
105
|
-
// Watch specific data - not all updates
|
|
106
|
-
watch(
|
|
107
|
-
items,
|
|
108
|
-
(newItems) => {
|
|
109
|
-
syncToServer(newItems)
|
|
110
|
-
},
|
|
111
|
-
{ deep: true },
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
const syncToServer = useDebounceFn((items) => {
|
|
115
|
-
fetch('/api/sync', { method: 'POST', body: JSON.stringify(items) })
|
|
116
|
-
}, 500)
|
|
117
|
-
|
|
118
|
-
// Only use onUpdated for DOM synchronization
|
|
119
|
-
onUpdated(() => {
|
|
120
|
-
// Scroll to bottom only if content changed height
|
|
121
|
-
if (scrollContainer.value) {
|
|
122
|
-
scrollContainer.value.scrollTop = scrollContainer.value.scrollHeight
|
|
123
|
-
}
|
|
124
|
-
})
|
|
125
|
-
</script>
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
```javascript
|
|
129
|
-
// GOOD: Conditional check in updated hook
|
|
130
|
-
export default {
|
|
131
|
-
data() {
|
|
132
|
-
return {
|
|
133
|
-
content: '',
|
|
134
|
-
lastSyncedContent: '',
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
updated() {
|
|
138
|
-
// Only act if specific condition is met
|
|
139
|
-
if (this.content !== this.lastSyncedContent) {
|
|
140
|
-
this.syncContent()
|
|
141
|
-
this.lastSyncedContent = this.content
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
methods: {
|
|
145
|
-
syncContent: debounce(() => {
|
|
146
|
-
// Sync logic
|
|
147
|
-
}, 300),
|
|
148
|
-
},
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## Valid Use Cases for Updated Hook
|
|
153
|
-
|
|
154
|
-
```javascript
|
|
155
|
-
// GOOD: Low-level DOM synchronization
|
|
156
|
-
export default {
|
|
157
|
-
updated() {
|
|
158
|
-
// Sync third-party library with Vue's DOM
|
|
159
|
-
this.thirdPartyWidget.refresh()
|
|
160
|
-
|
|
161
|
-
// Update scroll position after content change
|
|
162
|
-
this.$nextTick(() => {
|
|
163
|
-
this.maintainScrollPosition()
|
|
164
|
-
})
|
|
165
|
-
},
|
|
166
|
-
}
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
## Prefer Computed Properties for Derived Data
|
|
170
|
-
|
|
171
|
-
```javascript
|
|
172
|
-
// BAD: Calculating derived data in updated
|
|
173
|
-
export default {
|
|
174
|
-
data() {
|
|
175
|
-
return { numbers: [1, 2, 3, 4, 5] }
|
|
176
|
-
},
|
|
177
|
-
updated() {
|
|
178
|
-
this.sum = this.numbers.reduce((a, b) => a + b, 0) // Causes another update!
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// GOOD: Use computed property instead
|
|
183
|
-
export default {
|
|
184
|
-
data() {
|
|
185
|
-
return { numbers: [1, 2, 3, 4, 5] }
|
|
186
|
-
},
|
|
187
|
-
computed: {
|
|
188
|
-
sum() {
|
|
189
|
-
return this.numbers.reduce((a, b) => a + b, 0)
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
```
|