flarum / flarum/issue-archive

CommentPost#view: Uncaught TypeError: post.likes(...).some is not a function

Open
#271 4 comments 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Bug Report

**Current Behavior**
I clicked https://discuss.flarum.org/d/15120 from the discussion list and the error appeared.

**Steps to Reproduce**
Cannot reproduce on a new session, only in the same tab without refreshing.

**Expected Behavior**
No error

**Screenshots**
![image](https://user-images.githubusercontent.com/6401250/44479240-0517d100-a60e-11e8-8283-df55de4ef0b8.png)

**Environment**
- Flarum version: dev-master (not sure exactly, I saw it was updated recently)
- Website URL: https://discuss.flarum.org

**Possible Solution**
Make sure post.likes() is an array before acting on it, or default to an array somehow (doesn't look like relationships let you choose a default).

**Additional Context**
Stack trace:
```js
Uncaught TypeError: post.likes(...).some is not a function
at CommentPost. (forum-def494fc.js:2378)
at CommentPost.object.(anonymous function) (https://discuss.flarum.org/assets/forum-def494fc.js:2167:65)
at CommentPost.object.(anonymous function) [as actionItems] (https://discuss.flarum.org/assets/forum-def494fc.js:2167:29)
at forum-def494fc.js:2098
at CommentPost.view (forum-def494fc.js:2098)
at CommentPost.render (forum-def494fc.js:1989)
at Object.view (forum-def494fc.js:1991)
at checkView (forum-def494fc.js:233)
at markViews (forum-def494fc.js:240)
at buildObject (forum-def494fc.js:244)
```

Points to the following:
```js
var isLiked = app.session.user && post.likes().some(function(user) {
return user === app.session.user
});
```

Here's the output received from `/api/posts?filter%5Bdiscussion%5D=15120&page%5Bnear%5D=35`, though I doubt it will be useful at all: https://paste.redevs.org/paste/4

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.