Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(settings): hide Browser notifications search result where the row does not render (#9867)

Bohan Jiangb6fc06820ad0
diff --git a/packages/views/settings/components/browser-notification-setting.tsx b/packages/views/settings/components/browser-notification-setting.tsx
index a9f1ce4b36..e7b3132011 100644
--- a/packages/views/settings/components/browser-notification-setting.tsx
+++ b/packages/views/settings/components/browser-notification-setting.tsx
@@ -12,6 +12,15 @@ import { isDesktopShell } from "../../platform";
import { useT } from "../../i18n";
import { SettingsCard, SettingsRow } from "./settings-layout";
+/**
+ * Whether the browser-permission row exists on this platform: web only, and
+ * only where the Notification API is present. The settings search index reads
+ * this too, so search never offers a row the page will not render.
+ */
+export function browserNotificationSettingAvailable(): boolean {
+ return !isDesktopShell() && isWebNotificationSupported();
+}
+
/**
* Web-only control for the browser permission that native notification banners
* require. Desktop delivers banners through the OS via Electron (no browser
@@ -34,7 +43,7 @@ export function BrowserNotificationSetting() {
}, []);
// Pre-mount, on desktop, or where the API is missing → nothing to manage.
- if (!mounted || isDesktopShell() || !isWebNotificationSupported()) return null;
+ if (!mounted || !browserNotificationSettingAvailable()) return null;
const handleEnable = async () => {
setPermission(await requestWebNotificationPermission());
diff --git a/packages/views/settings/components/settings-page.test.tsx b/packages/views/settings/components/settings-page.test.tsx
index 754d231fc4..5fbd8f19c0 100644
--- a/packages/views/settings/components/settings-page.test.tsx
+++ b/packages/views/settings/components/settings-page.test.tsx
@@ -1,5 +1,5 @@
import { fireEvent, screen, within } from "@testing-library/react";
-import { beforeEach, describe, expect, it, vi } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { SidebarProvider, useSidebar } from "@multica/ui/components/ui/sidebar";
import { configStore } from "@multica/core/config";
@@ -465,3 +465,64 @@ describe("SettingsPage search", () => {
expect(screen.getByText("No matching settings")).toBeInTheDocument();
});
});
+
+describe("SettingsPage search for the browser notifications row", () => {
+ // The row only renders on web with the Notification API, so search must
+ // follow the same rule or a result opens the page and finds nothing.
+ class FakeNotification {
+ static permission: NotificationPermission = "default";
+ }
+
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ });
+
+ function search(value: string) {
+ fireEvent.change(screen.getByRole("searchbox", { name: "Search settings" }), {
+ target: { value },
+ });
+ }
+
+ it("offers it on web when the Notification API exists", () => {
+ vi.stubGlobal("Notification", FakeNotification);
+ renderWithI18n(<SettingsPage />);
+ search("browser");
+ const results = screen.getByRole("listbox", { name: "Search settings" });
+ const option = within(results).getByRole("option", { name: /Browser notifications/ });
+ fireEvent.click(option);
+ expect(push).toHaveBeenCalledWith(
+ "/acme/settings?tab=notifications&section=browser",
+ );
+ });
+
+ it.each(["browser", "notifi"])("leaves it out on desktop when searching %s", (query) => {
+ // Electron exposes Notification too; the desktop shell alone rules it out.
+ vi.stubGlobal("Notification", FakeNotification);
+ vi.stubGlobal("desktopAPI", { pickDirectory: vi.fn() });
+ renderWithI18n(<SettingsPage />);
+ search(query);
+ expect(
+ screen.queryByRole("option", { name: /Browser notifications/ }),
+ ).not.toBeInTheDocument();
+ });
+
+ it("leaves it out where the Notification API is missing", () => {
+ vi.stubGlobal("Notification", undefined);
+ renderWithI18n(<SettingsPage />);
+ search("browser");
+ expect(
+ screen.queryByRole("option", { name: /Browser notifications/ }),
+ ).not.toBeInTheDocument();
+ });
+
+ it("keeps the other notification results on desktop", () => {
+ vi.stubGlobal("Notification", FakeNotification);
+ vi.stubGlobal("desktopAPI", { pickDirectory: vi.fn() });
+ renderWithI18n(<SettingsPage />);
+ search("notifi");
+ const results = screen.getByRole("listbox", { name: "Search settings" });
+ expect(
+ within(results).getByRole("option", { name: /Send a system notification/ }),
+ ).toBeInTheDocument();
+ });
+});
diff --git a/packages/views/settings/components/use-settings-search-index.ts b/packages/views/settings/components/use-settings-search-index.ts
index ec0720db64..98b0d05a06 100644
--- a/packages/views/settings/components/use-settings-search-index.ts
+++ b/packages/views/settings/components/use-settings-search-index.ts
@@ -5,6 +5,7 @@ import { NOTIFICATION_ROUTE_KINDS } from "@multica/core/notification-preferences
import { useT } from "../../i18n";
import type { SettingsSearchEntry } from "./settings-search";
import { CHANNEL_INTEGRATIONS } from "./settings-navigation";
+import { browserNotificationSettingAvailable } from "./browser-notification-setting";
export interface SettingsSearchPage {
value: string;
@@ -17,7 +18,8 @@ export type SettingsSearchIndexEntry = SettingsSearchEntry;
* The searchable settings for the pages currently in the navigation. Anchors
* here must match the `anchor` props on the corresponding `SettingsSection` /
* `SettingsRow`; entries for hidden pages (feature flags, desktop-only) are
- * dropped so a result never lands on a page the user cannot open.
+ * dropped so a result never lands on a page the user cannot open, and rows
+ * that only render on some platforms are indexed under the same condition.
*/
export function useSettingsSearchIndex(
pages: readonly SettingsSearchPage[],
@@ -98,11 +100,16 @@ export function useSettingsSearchIndex(
anchor: "system",
title: t(($) => $.notifications.system.label),
},
- {
- tab: "notifications",
- anchor: "browser",
- title: t(($) => $.notifications.browser.label),
- },
+ // Web-only row: absent on desktop and without the Notification API.
+ ...(browserNotificationSettingAvailable()
+ ? [
+ {
+ tab: "notifications",
+ anchor: "browser",
+ title: t(($) => $.notifications.browser.label),
+ },
+ ]
+ : []),
{
tab: "tokens",
title: t(($) => $.page.tabs.tokens),