Sidebar drops context on 1st report link, falls back to wrong/blank menu

Hi everyone,

I am facing a sidebar routing issue in Frappe Desk when using a custom Workspace Sidebar whose items are reports.

What I am trying to achieve

In my custom app (app name = my-app), I want separate navigation like this:

  • My Masters

  • My Reports

Each has its own:

  • Desktop Icon

  • Workspace Sidebar

  • custom module name

For example:

  • Desktop Icon: My Reports

  • Workspace Sidebar: My Reports

  • Report module: My Reports

I also created a separate Python/module directory for reports so the report files are stored in my own app/module.

Problem

When I click the My Reports desktop icon:

  • sometimes it opens the wrong sidebar, for example Stock

  • after browser refresh, the sidebar may disappear completely

Also, if I first open a custom workspace/sidebar correctly and then navigate to another report, the sidebar changes again.

What I observed

This happens specifically when the sidebar contains report links and the first link is a Report.

I inspected the Frappe code and found this flow:

1. Desktop Icon → Workspace Sidebar → first item is Report

In desktop.js, when a desktop icon is of type Workspace Sidebar, it takes the first link.

If the first link is a Report, it generates the report route directly, but it does not pass route_options.sidebar.

So the report opens, but the sidebar context is not preserved.

File:
frappe/desk/page/desktop/desktop.js

Relevant logic:

  • report branch generates route from report details

  • workspace / doctype branches can preserve sidebar context

  • report branch does not

2. Sidebar report items also ignore route_options

In sidebar_item.js, for link_type === "Report", route generation uses:

  • type

  • name

  • is_query_report

  • report_ref_doctype

but it does not use item.route_options, even if I set:

{
  "sidebar": "My Reports"
}

in my Workspace Sidebar Item.

File:
frappe/public/js/frappe/ui/sidebar/sidebar_item.js

3. On route change, sidebar is recalculated

In sidebar.js, on every router change:

  • if frappe.route_options.sidebar exists, that sidebar is loaded

  • otherwise Frappe recalculates the sidebar

File:
frappe/public/js/frappe/ui/sidebar/sidebar.js

4. Query report route does not reliably preserve module/sidebar context

For report routes like:

  • query-report/Lead Management Report

the resolver does not find the original sidebar name.

Then it falls back to router.meta.module.

But for query-report routes, this module context does not seem to reliably point to the report’s own custom module.

Because of that:

  • sometimes it picks a previously opened module sidebar like Stock

  • after full refresh, it may become blank because no sidebar candidate is found

Important detail

Even if the report’s module is set to My Reports, the report route still does not reliably load the My Reports sidebar.

So this seems different from just “assign proper module to report”.

My exact question

Is this expected behavior in Frappe?

Or is this a framework issue where:

  1. Workspace Sidebar desktop icon with Report first-link does not preserve sidebar context

  2. Workspace Sidebar Item report links ignore route_options

  3. query-report navigation recalculates sidebar without enough context and may fall back to wrong sidebar

Repro steps

  1. Create a custom Workspace Sidebar named My Reports

  2. Add only Report links in it

  3. Create a Desktop Icon of type Workspace Sidebar pointing to My Reports

  4. Click the desktop icon

  5. Observe:

    • wrong sidebar may appear

    • or after refresh, sidebar disappears

  6. Navigate between report links inside that sidebar

  7. Observe sidebar context is not stable

Expected behavior

If I open a desktop icon for a specific workspace sidebar, and then open reports from that sidebar, I expect the same sidebar context to remain active unless explicitly changed.

Actual behavior

The sidebar context is lost during report navigation and the framework may load:

  • another module sidebar

  • a stale previous sidebar

  • or no sidebar at all

Current workaround

The only stable workaround I found is to keep everything under one unified sidebar/workspace, for example one My App sidebar containing:

  • reports

  • masters

  • doctypes

  • workspace links

That works better because fallback still resolves to the same single sidebar.

But that does not support a clean “separate reports sidebar” design.

Question to maintainers / community

Is there any supported way to keep a dedicated sidebar active for report navigation without modifying Frappe core?

If not, would this be considered a framework bug / missing feature?


If helpful, I can also share the exact code branches I inspected in:

  • desktop.js

  • sidebar_item.js

  • sidebar.js

  • router.js