Skip to content

FIX: preserve calendar view when navigating months - #167

Merged
angusmcleod merged 1 commit into
angusmcleod:mainfrom
elRicharde:fix/calendar-month-navigation
May 10, 2026
Merged

angusmcleod merged 1 commit into
angusmcleod:mainfrom
elRicharde:fix/calendar-month-navigation

Conversation

@elRicharde

Copy link
Copy Markdown
Contributor

Problem

After the category route fix in #166, navigating between months in the
calendar view incorrectly switches the view to the list template, even
when the user stays within a calendar-enabled category.

Steps to reproduce:

  1. Open a calendar-enabled category (e.g. /c/events/20)
  2. Verify calendar view is rendered
  3. Click the "next month" or "previous month" arrow
  4. URL changes to /c/events/20?start=...&end=... (note the missing /l/calendar)
  5. View flips to list - expected: calendar for the new month

The same issue affects the global calendar route (/calendar).

Root cause

transitionToMonth() in events-calendar.js called:

router.transitionTo({ queryParams: { start, end } });

Without an explicit route name, Ember resolved the transition to the
category's base route (discovery.category) instead of the calendar
filter route - the /l/calendar segment was dropped from the URL.

The afterModel hook in route:discovery.category (modified in #166
to prevent calendar template leaking into non-calendar categories) then
sees model.filterType !== "calendar" and executes:

} else if (this.templateName === "discovery/calendar") {
  this.templateName = "discovery/list";
}

resetting the template to list. Topics for the new month are loaded
correctly, but rendered in the wrong view.

This bug existed before #166 but was masked by the earlier template
leak - #166 correctly fixed that leak, which surfaced this pre-existing
issue in transitionToMonth.

Fix

Transition explicitly to the correct calendar route so the filter is
preserved in the URL:

  • discovery.calendarCategory with category_slug_path_with_id as
    positional parameter when a category context exists
  • discovery.calendar for the global calendar route (no dynamic segments)

The routes xxxCategory are dynamically generated by Discourse core's
app-route-map.js
from Site.currentProp("filters"), with a single *category_slug_path_with_id
glob segment in the format <slug>/<id>. This matches how Discourse core
itself transitions, e.g. in build-category-route.js:

this.router.replaceWith(
  "discovery.categoryNone",
  params.category_slug_path_with_id
);

The const category = this.get("category") lookup is hoisted to the top
of the function since it is now needed both for route selection and in
the existing .then() callback (minor deduplication).

Testing

Tested manually on Discourse Version: 2026.4.0-latest ( 480a052a10 )

  • ✅ Category calendar: next month stays in calendar view
  • ✅ Category calendar: previous month stays in calendar view
  • ✅ Category calendar: "Today" button returns to current month in calendar view
  • ✅ Global calendar (/calendar): month navigation stays in calendar view
  • ✅ Topics for the new month are loaded correctly
  • ✅ Navigating from calendar category to non-calendar category still
    correctly shows list view (regression check for Fix calendar view leaking to non-calendar categories during SPA navigation - Update discourse-events.js #166)

Related

transitionToMonth() used router.transitionTo({ queryParams })
without a route name, which resolved to the category's base route
instead of the calendar filter route. Combined with the templateName
reset in angusmcleod#166, this caused the view to flip to list on next/previous
month clicks.

Transition explicitly to discovery.calendarCategory (or
discovery.calendar for the global calendar route) to preserve
the calendar filter.
@elRicharde

Copy link
Copy Markdown
Contributor Author

Note: the Metadata check fails because the plugin version hasn't been bumped. I left this to the maintainer @angusmcleod as with my previous PR (#166) - happy to bump it myself if preferred.

All tested and ok from my side, let me know if there is something more to do here. Thanks and BR Richard

@elRicharde

Copy link
Copy Markdown
Contributor Author

@angusmcleod - can i support here anyhow to get this PR accepted and merged?
BR Richard

@elRicharde

Copy link
Copy Markdown
Contributor Author

Just wondering if this is the right place here @angusmcleod , but last time merge was quick and easy here..
Any update would be nice. Thx

@angusmcleod

Copy link
Copy Markdown
Owner

Thanks 👍

@angusmcleod
angusmcleod merged commit 3fa9447 into angusmcleod:main May 10, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants