Skip to content

Commit 39d978d

Browse files
committed
warn v-repeat filters that do not return Arrays
1 parent 3b9fb2d commit 39d978d

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
@@ -192,6 +192,12 @@ module.exports = {
192192
*/
193193

194194
update: function (data) {
195+
if (process.env.NODE_ENV !== 'production' && !_.isArray(data)) {
196+
_.warn(
197+
'v-repeat pre-converts Objects into Arrays, and ' +
198+
'v-repeat filters should always return Arrays.'
199+
)
200+
}
195201
if (this.componentId) {
196202
var state = this.componentState
197203
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)