Skip to content

Commit

Permalink
FIX: cannot read property of undefined (#119)
Browse files Browse the repository at this point in the history
When upgrading this component to use the Glimmer topic list, we
converted @discourseComputed into value transformers but there's a bit
of magic with @discourseComputed when it comes to handling `.` and
`null` / `undefined` values.

This ensures the same behaviour and prevents the JS error from happening
when creating a new topic from the topic list.

Meta - https://meta.discourse.org/t/349416
  • Loading branch information
ZogStriP authored Jan 30, 2025
1 parent bcb5092 commit dd7baa7
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ export default apiInitializer("1.39.0", (api) => {
value: additionalClasses,
context: { topic },
}) => {
const whosOnline = api.container.lookup("service:whos-online");
const lastPosterId = topic.lastPoster.id;
const lastPosterUserId = topic.lastPosterUser.id;
if (topic) {
const whosOnline = api.container.lookup("service:whos-online");
const { lastPoster, lastPosterUser } = topic;

if (whosOnline.isUserOnline(lastPosterId || lastPosterUserId)) {
additionalClasses.push("last-poster-online");
if (whosOnline.isUserOnline(lastPoster?.id || lastPosterUser?.id)) {
additionalClasses.push("last-poster-online");
}
}

return additionalClasses;
Expand Down

0 comments on commit dd7baa7

Please sign in to comment.