Nested replies: a topic bookmark on a fully read topic 404s and leaves the topic with an empty bookmark list

AI-generated summary

CrookedGrandma reported a bug in Discourse version 2026.10.0-latest where clicking a topic-level bookmark on a fully read, nested-view topic results in a 404 error, an empty reply stream, and an incorrect “Bookmark” button state. The issue occurs when navigating to the bookmark via the user menu without a page reload.

The root cause is twofold: first, UserTopicBookmarkSerializer#bookmarkable_url generates a link to last_read_post_number + 1, which does not exist for fully read topics. The nested route attempts to fetch this non-existent post context (/n/slug/818/context/2.json), triggering a 404. Second, in routes/topic/from-params.js, if the nested view is already initialized, the post stream refresh is skipped. The subsequent 404 error sets _loading_error, causing setupController to return early and leave the topic controller with a stale store record where bookmarks is empty. This leads the UI to incorrectly offer creating a new bookmark, which the server rejects.

CrookedGrandma disclosed that the bug reproduction and report were generated by an AI agent. pmusaraj acknowledged the report and tagged markvanlan, who subsequently confirmed that a fix has been merged. The suggested fixes mentioned in the initial report included having the context endpoint fall back to the nearest existing post, resetting topic state on loading errors, or limiting the bookmarkable_url to highest_post_number.

Version 2026.10.0-latest (a51251632c), nested_replies_enabled, default sort old. The route code involved looks the same on current main.

Steps

  1. Bookmark a topic (topic-level bookmark) that uses the nested view, and read it to the end.
  2. Open that topic normally, then go to a topic list such as /latest, without reloading the page.
  3. Open the user menu, go to the Bookmarks tab and click the bookmark.

Expected: the topic opens and the bookmark button shows “Edit bookmark”.
Actual: no replies are shown, the button shows “Bookmark”, and clicking it shows “Sorry, an error has occurred.” With a fresh page load instead of step 2, the button is right but the topic still shows no replies.

What happens

  • UserTopicBookmarkSerializer#bookmarkable_url links to last_read_post_number + 1. For a fully read topic that post doesn’t exist. Example: /t/slug/818/2 when highest_post_number is 1. The flat view jumps to the nearest post, but the nested route requests /n/slug/818/context/2.json, which returns 404.
  • In routes/topic/from-params.js, if topic.is_nested_view is already set, postStream.refresh is skipped. The 404 from the nested load then sets _loading_error and setupController returns early, so the topic controller keeps the store record exactly as it was.
  • That record’s bookmarks is []. A topic list load runs Topic.munge with list JSON, which has bookmarked but no bookmarks, and munge sets bookmarks = e.bookmarks || [] on the cached record. The button reads bookmarks, so it offers to create a new topic bookmark. Presumably the server rejects that because one already exists.

This is the same failure path as Link to nested topic in my suggested topics doesn't work, whose fix covered suggested-topic links only.

Possible fixes: let the context endpoint or the route fall back to the nearest existing post, as the flat view does, and/or don’t keep the previous topic state when _loading_error is set. Limiting bookmarkable_url to highest_post_number would also remove this trigger.

5 likes

Just for transparency: this bug was found by my colleague and I, but tracing the exact reproduction steps and reporting the issue was done by an AI agent. Apologies if any standards were not followed correctly.

3 likes

Thanks for the report (and disclosure). One for you, @markvanlan.

2 likes

I’ve just merged a fix

2 likes