Skip to content

Commit f38d685

Browse files
committed
warn v-repeat filters that do not return Arrays
1 parent 4c3a995 commit f38d685

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/directives/repeat.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ module.exports = {
202202
*/
203203

204204
update: function (data) {
205+
if (process.env.NODE_ENV !== 'production' && !_.isArray(data)) {
206+
_.warn(
207+
'v-repeat pre-converts Objects into Arrays, and ' +
208+
'v-repeat filters should always return Arrays.'
209+
)
210+
}
205211
if (this.componentId) {
206212
var state = this.componentState
207213
if (state === UNRESOLVED) {

test/unit/specs/directives/repeat_spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,22 @@ if (_.inBrowser) {
802802
})
803803
})
804804

805+
it('warn filters that return non-Array values', function () {
806+
new Vue({
807+
el: el,
808+
template: '<div v-repeat="items | test"></div>',
809+
data: {
810+
items: []
811+
},
812+
filters: {
813+
test: function (val) {
814+
return {}
815+
}
816+
}
817+
})
818+
expect(hasWarned(_, 'should always return Arrays')).toBe(true)
819+
})
820+
805821
})
806822
}
807823

0 commit comments

Comments
 (0)