Skip to content

Commit b3baab5

Browse files
author
Guillaume Chau
committed
feat(perf): limit size of arrays sent to devtools
1 parent 561a892 commit b3baab5

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

src/devtools/components/DataField.vue

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
class="children"
173173
>
174174
<data-field
175-
v-for="subField in limitedSubFields"
175+
v-for="subField in formattedSubFields"
176176
:key="subField.key"
177177
:field="subField"
178178
:parent-field="field"
@@ -185,10 +185,11 @@
185185
:is-state-field="isStateField"
186186
/>
187187
<span
188-
v-if="formattedSubFields.length > limit"
188+
v-if="subFieldCount > limit"
189+
v-tooltip="'Show more'"
189190
:style="{ marginLeft: depthMargin + 'px' }"
190191
class="more"
191-
@click="limit += 10"
192+
@click="showMoreSubfields()"
192193
>
193194
...
194195
</span>
@@ -273,7 +274,7 @@ export default {
273274
data () {
274275
return {
275276
contextMenuOpen: false,
276-
limit: Array.isArray(this.field.value) ? 10 : Infinity,
277+
limit: 20,
277278
expanded: this.depth === 0 && this.field.key !== '$route' && (subFieldCount(this.field.value) < 5)
278279
}
279280
},
@@ -309,7 +310,7 @@ export default {
309310
} else {
310311
return 'string'
311312
}
312-
} else if (Array.isArray(value)) {
313+
} else if (Array.isArray(value) || (value && value._isArray)) {
313314
return 'array'
314315
} else if (isPlainObject(value)) {
315316
return 'plain-object'
@@ -367,7 +368,7 @@ export default {
367368
}
368369
},
369370
370-
formattedSubFields () {
371+
rawValue () {
371372
let value = this.field.value
372373
373374
// CustomValue API
@@ -378,8 +379,17 @@ export default {
378379
value = value._custom.value
379380
}
380381
382+
if (value && value._isArray) {
383+
value = value.items
384+
}
385+
return { value, inherit }
386+
},
387+
388+
formattedSubFields () {
389+
let { value, inherit } = this.rawValue
390+
381391
if (Array.isArray(value)) {
382-
value = value.map((item, i) => ({
392+
return value.slice(0, this.limit).map((item, i) => ({
383393
key: i,
384394
value: item,
385395
...inherit
@@ -394,11 +404,13 @@ export default {
394404
value = sortByKey(value)
395405
}
396406
}
397-
return value
407+
408+
return value.slice(0, this.limit)
398409
},
399410
400-
limitedSubFields () {
401-
return this.formattedSubFields.slice(0, this.limit)
411+
subFieldCount () {
412+
const { value } = this.rawValue
413+
return subFieldCount(value)
402414
},
403415
404416
valueTooltip () {
@@ -505,6 +517,10 @@ export default {
505517
this.$_contextMenuTimer = setTimeout(() => {
506518
this.contextMenuOpen = false
507519
}, 4000)
520+
},
521+
522+
showMoreSubfields () {
523+
this.limit += 20
508524
}
509525
}
510526
}

src/util.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const SPECIAL_TOKENS = {
6060
}
6161

6262
export const MAX_STRING_SIZE = 10000
63+
export const MAX_ARRAY_SIZE = 5000
6364

6465
export function specialTokenToString (value) {
6566
if (value === null) {
@@ -120,6 +121,14 @@ export function stringify (data) {
120121
function replacer (key, val) {
121122
const type = typeof val
122123
if (Array.isArray(val)) {
124+
const l = val.length
125+
if (l > MAX_ARRAY_SIZE) {
126+
return {
127+
_isArray: true,
128+
length: l,
129+
items: val.slice(0, MAX_ARRAY_SIZE)
130+
}
131+
}
123132
return val
124133
} else if (typeof val === 'string') {
125134
if (val.length > MAX_STRING_SIZE) {

0 commit comments

Comments
 (0)