Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Refactor expanded mode check to be called from React (#661)

Leendert de Borst93ac1315087b
diff --git a/browser-extension/src/entrypoints/popup/index.html b/browser-extension/src/entrypoints/popup/index.html
index eb856c019..6799776dc 100644
--- a/browser-extension/src/entrypoints/popup/index.html
+++ b/browser-extension/src/entrypoints/popup/index.html
@@ -6,14 +6,6 @@
<title>AliasVault</title>
<link href="~/assets/tailwind.css" rel="stylesheet" />
<meta name="manifest.type" content="browser_action" />
- <script>
- // Check if expanded=true is in the URL, which means the popup was opened in expanded mode with unlimited width.
- // If not, set the width to 350px to force the default popup to a fixed width.
- const urlParams = new URLSearchParams(window.location.search);
- if (!urlParams.get('expanded')) {
- document.documentElement.classList.add('max-w-[350px]');
- }
- </script>
</head>
<body class="bg-white dark:bg-gray-900">
<div id="root"></div>
diff --git a/browser-extension/src/entrypoints/popup/main.tsx b/browser-extension/src/entrypoints/popup/main.tsx
index 2e103ecbf..cb4550028 100644
--- a/browser-extension/src/entrypoints/popup/main.tsx
+++ b/browser-extension/src/entrypoints/popup/main.tsx
@@ -4,6 +4,10 @@ import { AuthProvider } from './context/AuthContext';
import { WebApiProvider } from './context/WebApiContext';
import { DbProvider } from './context/DbContext';
import { LoadingProvider } from './context/LoadingContext';
+import { setupExpandedMode } from '../../utils/ExpandedMode';
+
+// Run before React initializes to ensure the popup is always a fixed width except for when explicitly expanded.
+setupExpandedMode();
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(
diff --git a/browser-extension/src/utils/ExpandedMode.ts b/browser-extension/src/utils/ExpandedMode.ts
new file mode 100644
index 000000000..e5d7d1dd5
--- /dev/null
+++ b/browser-extension/src/utils/ExpandedMode.ts
@@ -0,0 +1,20 @@
+/**
+ * Setup the expanded mode.
+ */
+export function setupExpandedMode() : void {
+ /**
+ * This runs once when imported and checks if the popup was opened in expanded mode with unlimited width.
+ * If not, it sets the width to 350px to force the default popup to a fixed width.
+ * This is used to ensure the popup is always a fixed width, even if some content like email preview
+ * is too wide to fit in the default width. Some browsers like Firefox and Safari will then try to
+ * expand the popup to the width of the content, which can cause the popup to become too wide and bad UX.
+ *
+ * You can test this by opening the popup and then clicking on the email preview. If the popup width does
+ * not change, it works. Then if you expand/popout the extension, the content of the page should adjust
+ * to the new width of the resizable popup.
+ */
+ const urlParams = new URLSearchParams(window.location.search);
+ if (!urlParams.get('expanded')) {
+ document.documentElement.classList.add('max-w-[350px]');
+ }
+}