Skip to content

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

Go

chore(lint): ban full-page navigation in shared code, point to openExternal (MUL-9001) (#10340)

Jiayuan Zhang2d38a4bc988e
diff --git a/packages/core/eslint.config.mjs b/packages/core/eslint.config.mjs
index 512b6828c0..c36fc041b1 100644
--- a/packages/core/eslint.config.mjs
+++ b/packages/core/eslint.config.mjs
@@ -1,5 +1,6 @@
import reactConfig from "@multica/eslint-config/react";
import { ICON_LIBRARY_IMPORT_PATTERNS } from "@multica/eslint-config/base";
+import { NO_FULL_PAGE_NAVIGATION } from "@multica/eslint-config/full-page-navigation";
// Package boundary (AGENTS.md): core is headless and runs unchanged in web,
// desktop and SSR. No UI libraries, no react-dom, no next/*, no Web Storage
@@ -77,6 +78,7 @@ export default [
ignores: TESTS,
rules: {
...boundaryRules(),
+ "no-restricted-syntax": ["error", NO_FULL_PAGE_NAVIGATION],
"no-restricted-imports": [
"error",
{
diff --git a/packages/core/realtime/use-realtime-sync.ts b/packages/core/realtime/use-realtime-sync.ts
index 4a944e0c50..da98d78719 100644
--- a/packages/core/realtime/use-realtime-sync.ts
+++ b/packages/core/realtime/use-realtime-sync.ts
@@ -1425,6 +1425,7 @@ export function useRealtimeSync(
hasOnboardedRef.current,
);
if (typeof window !== "undefined") {
+ // eslint-disable-next-line no-restricted-syntax -- in-app path, not an external URL; core has no router to hand it to
window.location.assign(target);
}
};
diff --git a/packages/eslint-config/full-page-navigation.js b/packages/eslint-config/full-page-navigation.js
new file mode 100644
index 0000000000..3e70066803
--- /dev/null
+++ b/packages/eslint-config/full-page-navigation.js
@@ -0,0 +1,25 @@
+// Shared web/desktop code must not replace the whole document. On Desktop the
+// main process's navigation guard cancels any document navigation that leaves
+// the renderer entry, without an error or a visible sign: MUL-8964's Composio
+// connect button sat on "Connecting…" because `window.location.href = url`
+// went nowhere. jsdom tests and the web app never notice.
+//
+// Covers `location.href = …` and `location = …` assignments and
+// `location.assign(…)` / `location.replace(…)`, on the bare global or through
+// `window`, `document`, `globalThis` or `self`.
+//
+// Exported for `no-restricted-syntax`, whose options flat config replaces
+// wholesale: a package that sets its own entries must list this one again.
+
+const GLOBAL = "/^(window|document|globalThis|self)$/";
+const LOCATION = `:matches(Identifier[name='location'], MemberExpression[object.name=${GLOBAL}][property.name='location'])`;
+
+export const NO_FULL_PAGE_NAVIGATION = {
+ selector: [
+ `AssignmentExpression > MemberExpression.left[property.name='href']:has(> ${LOCATION}.object)`,
+ `AssignmentExpression > MemberExpression.left[object.name=${GLOBAL}][property.name='location']`,
+ `CallExpression > MemberExpression.callee[property.name=/^(assign|replace)$/]:has(> ${LOCATION}.object)`,
+ ].join(", "),
+ message:
+ "Full-page navigation is silently blocked on Desktop once it leaves the app. Open an external URL with openExternal from packages/views/platform/open-external (`webTarget: \"same-tab\"` keeps the web tab); move within the app with the navigation adapter (useNavigation). A deliberate full-page navigation takes an inline disable that says why.",
+};
diff --git a/packages/eslint-config/full-page-navigation.test.js b/packages/eslint-config/full-page-navigation.test.js
new file mode 100644
index 0000000000..3fafd69b44
--- /dev/null
+++ b/packages/eslint-config/full-page-navigation.test.js
@@ -0,0 +1,60 @@
+import assert from "node:assert/strict";
+import { test } from "node:test";
+import { Linter } from "eslint";
+import tseslint from "typescript-eslint";
+import { NO_FULL_PAGE_NAVIGATION } from "./full-page-navigation.js";
+
+const linter = new Linter();
+
+function flagged(code) {
+ const messages = linter.verify(
+ code,
+ [
+ {
+ files: ["**/*.ts"],
+ languageOptions: { parser: tseslint.parser },
+ rules: { "no-restricted-syntax": ["error", NO_FULL_PAGE_NAVIGATION] },
+ },
+ ],
+ "fixture.ts",
+ );
+ const fatal = messages.find((m) => m.fatal);
+ if (fatal) throw new Error(`fixture failed to parse: ${fatal.message}`);
+ return messages.length > 0;
+}
+
+const FLAGGED = [
+ ["window.location.href assignment", 'window.location.href = "https://example.com";'],
+ ["bare location.href assignment", "location.href = url;"],
+ ["document.location.href assignment", "document.location.href = url;"],
+ ["globalThis.location.href assignment", "globalThis.location.href = url;"],
+ ["window.location assignment", "window.location = url;"],
+ ["window.location.assign", "window.location.assign(url);"],
+ ["window.location.replace", "window.location.replace(url);"],
+ ["bare location.assign", "location.assign(url);"],
+ ["self.location.replace", "self.location.replace(url);"],
+];
+
+const ALLOWED = [
+ ["reading location.href", "const here = window.location.href;"],
+ ["comparing location.href", 'if (location.href === "x") {}'],
+ ["location.reload", "window.location.reload();"],
+ ["window.open", 'window.open(url, "_blank", "noopener,noreferrer");'],
+ ["href on another object", "link.href = url;"],
+ ["assign on another object", "Object.assign(target, source);"],
+ ["replace on a string", 'path.replace("/", "");'],
+ ["location on a non-global", "props.location.href = url;"],
+ ["router replace", "navigation.replace(path);"],
+];
+
+for (const [name, code] of FLAGGED) {
+ test(`flags ${name}`, () => assert.equal(flagged(code), true));
+}
+
+for (const [name, code] of ALLOWED) {
+ test(`allows ${name}`, () => assert.equal(flagged(code), false));
+}
+
+test("message points to openExternal", () => {
+ assert.match(NO_FULL_PAGE_NAVIGATION.message, /openExternal/);
+});
diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json
index f71d0a5015..9b725eeff7 100644
--- a/packages/eslint-config/package.json
+++ b/packages/eslint-config/package.json
@@ -10,7 +10,8 @@
"./base": "./base.js",
"./react": "./react.js",
"./next": "./next.js",
- "./control-shape": "./control-shape.js"
+ "./control-shape": "./control-shape.js",
+ "./full-page-navigation": "./full-page-navigation.js"
},
"dependencies": {
"@eslint/js": "^9.28.0",
diff --git a/packages/views/auth/login-page.tsx b/packages/views/auth/login-page.tsx
index 7233cb42c3..f6d2b18a66 100644
--- a/packages/views/auth/login-page.tsx
+++ b/packages/views/auth/login-page.tsx
@@ -66,6 +66,7 @@ interface LoginPageProps {
export function redirectToCliCallback(url: string, token: string, state: string) {
const separator = url.includes("?") ? "&" : "?";
+ // eslint-disable-next-line no-restricted-syntax -- CLI login runs in the web app only; the token must reach the CLI's local listener in this tab
window.location.href = `${url}${separator}token=${encodeURIComponent(token)}&state=${encodeURIComponent(state)}`;
}
@@ -288,6 +289,7 @@ export function LoginPage({
prompt: "select_account",
});
if (google.state) params.set("state", google.state);
+ // eslint-disable-next-line no-restricted-syntax -- web OAuth redirect; Desktop passes onGoogleLogin and returns above
window.location.href = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;
};
diff --git a/packages/views/billing/billing-test-page.tsx b/packages/views/billing/billing-test-page.tsx
index 7a448de574..1ee802f02d 100644
--- a/packages/views/billing/billing-test-page.tsx
+++ b/packages/views/billing/billing-test-page.tsx
@@ -274,6 +274,7 @@ function BuyAndPortalSection() {
// browser back button returns the user to this page after
// Stripe redirects out. Stripe-hosted pages handle their own
// SPA-like behaviour from there.
+ // eslint-disable-next-line no-restricted-syntax -- web-only test page; Desktop has no route to it
window.location.href = url;
} catch (err) {
toast.error(
diff --git a/packages/views/eslint.config.mjs b/packages/views/eslint.config.mjs
index 53cf35290e..c40430258e 100644
--- a/packages/views/eslint.config.mjs
+++ b/packages/views/eslint.config.mjs
@@ -1,6 +1,7 @@
import reactConfig from "@multica/eslint-config/react";
import { ICON_LIBRARY_IMPORT_PATTERNS, REDUCED_MOTION_IMPORT } from "@multica/eslint-config/base";
import { NO_ROUND_CONTROLS } from "@multica/eslint-config/control-shape";
+import { NO_FULL_PAGE_NAVIGATION } from "@multica/eslint-config/full-page-navigation";
import i18next from "eslint-plugin-i18next";
import {
NO_UNTRANSLATED_ATTRIBUTES,
@@ -46,6 +47,7 @@ export default [
NO_UNTRANSLATED_ATTRIBUTES,
NO_UNTRANSLATED_TOAST,
NO_ROUND_CONTROLS,
+ NO_FULL_PAGE_NAVIGATION,
],
"no-restricted-imports": [
"error",
diff --git a/packages/views/platform/open-external.ts b/packages/views/platform/open-external.ts
index 9ef2340dcb..2d19e6c3b0 100644
--- a/packages/views/platform/open-external.ts
+++ b/packages/views/platform/open-external.ts
@@ -32,6 +32,7 @@ export function openExternal(
// same-tab option keeps Checkout/Portal reliable on web while Electron still
// hands the URL to the system browser above.
if (options?.webTarget === "same-tab") {
+ // eslint-disable-next-line no-restricted-syntax -- web-only branch; Desktop returned through desktopAPI above
window.location.assign(url);
return;
}