# 错误：reaction 和 reaction-received 无法加载下一页

**URL:** https://meta.discourse.org/t/bug-reaction-and-reaction-received-fail-to-load-the-next-page/390385
**Category:** Bug
**Tags:** reactions
**Created:** [2025 年12 月 4 日 08:21 UTC](https://meta.discourse.org/t/bug-reaction-and-reaction-received-fail-to-load-the-next-page/390385 "2025-12-04T08:21:37Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### 作者： ![small-lovely-cat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/small-lovely-cat/32/553546_2.png) [@small-lovely-cat](https://meta.discourse.org/u/small-lovely-cat)
#### 发布日期： [2025 年12 月 4 日 08:21 UTC](https://meta.discourse.org/t/bug-reaction-and-reaction-received-fail-to-load-the-next-page/390385/1 "2025-12-04T08:21:37Z")

</div>

在 activity/notification 的 reaction/reaction-received 页面中存在一个错误。

当用户尝试向下滚动并加载下一页时，列表会重复添加相同的条目，导致重复。

该问题源于前端和后端之间存在不一致。前端中定义的 `id` 是 `post_id`，而后端要求的是 `reaction_id`。

一个草稿的拉取请求（PR）在这里，方便时请进行审查。

[https://github.com/discourse/discourse/pull/36451](https://github.com/discourse/discourse/pull/36451)

---

<div class="post-metadata">

### 作者： ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### 发布日期： [2025 年12 月 4 日 08:46 UTC](https://meta.discourse.org/t/bug-reaction-and-reaction-received-fail-to-load-the-next-page/390385/2 "2025-12-04T08:46:13Z")

</div>

感谢您的草稿拉取请求（PR），反应（reactions）的分页现在确实看起来不准确并且似乎有重复。

我不确定正确的修复方法是否是设置 `post_id`。看起来分页使用了 `before_reaction_user_id`（参见[此处](https://github.com/discourse/discourse/blob/8b29528420a081e9d01d49a0d907458633de68d9/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb#L74-L79)）。甚至可能删除第 27 行（PR 中的那一行）会有帮助，因为它很可能在上面扁平化的 `reaction` 中已经设置了。

---

<div class="post-metadata">

### 作者： ![small-lovely-cat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/small-lovely-cat/32/553546_2.png) [@small-lovely-cat](https://meta.discourse.org/u/small-lovely-cat)
#### 发布日期： [2025 年12 月 4 日 08:48 UTC](https://meta.discourse.org/t/bug-reaction-and-reaction-received-fail-to-load-the-next-page/390385/3 "2025-12-04T08:48:04Z")

</div>

感谢您的回复。  
我明天会检查一下，看看是否能解决这个问题。

---

<div class="post-metadata">

### 作者： ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### 发布日期： [2025 年12 月 4 日 09:07 UTC](https://meta.discourse.org/t/bug-reaction-and-reaction-received-fail-to-load-the-next-page/390385/4 "2025-12-04T09:07:39Z")

</div>

好的，谢谢！

为了清楚起见，我认为 `before_reaction_user_id` 应该是来自 `discourse_reactions_reaction_users` 的 ID——我认为这个变量名有点令人困惑。请随时在此处或在聊天中澄清任何问题。

---

<div class="post-metadata">

### 作者： ![small-lovely-cat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/small-lovely-cat/32/553546_2.png) [@small-lovely-cat](https://meta.discourse.org/u/small-lovely-cat)
#### 发布日期： [2025 年12 月 5 日 03:29 UTC](https://meta.discourse.org/t/bug-reaction-and-reaction-received-fail-to-load-the-next-page/390385/6 "2025-12-05T03:29:21Z")

</div>

我已经调查并找到了 rspec 失败的原因。  
原始的 spec 断言了一个带有属性 `expect(page).to have_css(\".user-stream-item [data-post-id='#{post_1.id}']\")` 的组件。

然而，在最近的提交中，`#{post_1.id}` 被更改为 `reaction_user_id`，这导致了不匹配，从而导致了失败。

* * *

最初的想法是更改 `id` 以满足 API 的需求，但我忽略了 `id` 也在 `PostList` 中用作 `post_id` 的事实，如下所示：

```js
<PostList
    @posts={{@model}}
    @fetchMorePosts={{@controller.loadMore}}
    @emptyText={{i18n "notifications.empty"}}
    @additionalItemClasses="user-stream-item"
    @showUserInfo={{false}}
    class="user-stream"
  >

```

并且其中使用的 `id` 在 `post.gjs` 组件中进行了映射

```js
data-post-id={{@post.id}}
data-topic-id={{@post.topicId}}
data-user-id={{@post.user_id}}

```

因此，原始的 `id` 行为不应被更改，因为这可能会导致 `postList` 中出现严重的失配，这直接导致了昨天 rspec 的失败。

* * *

作为一种变通方法，可能还有另一种解决此问题的方法：

在 `flattenForPostList` 时添加一个新的字段 `reaction_user_id: reaction.id`，然后将 `#getLastIdFrom(array)` 函数中的 `return array.length ? array[array.length - 1].id : null;` 更改为 `return array.length ? array[array.length - 1].reaction_user_id`。

* * *

简而言之；  
`reaction_id`、`post_id` 和现在的 `reaction_user_id` 是完全不同的，但 `postList` 组件需要的 `id` 必须是 `post_id`。而获取下一页所需的 `id` 应该是 `reaction_user_id`，这非常令人困惑。

@nat

---

<div class="post-metadata">

### 作者： ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### 发布日期： [2025 年12 月 5 日 10:32 UTC](https://meta.discourse.org/t/bug-reaction-and-reaction-received-fail-to-load-the-next-page/390385/7 "2025-12-05T10:32:45Z")

</div>

感谢 @small-lovely-cat 的调查和拉取请求 👍

我已向拉取请求添加了一个规范，并会将其合并。

---

<div class="post-metadata">

### 作者： ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### 发布日期： [2025 年12 月 6 日 07:00 UTC](https://meta.discourse.org/t/bug-reaction-and-reaction-received-fail-to-load-the-next-page/390385/8 "2025-12-06T07:00:38Z")

</div>

此主题已在 19 小时后自动关闭。不再允许回复。
