Skip to content

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

Tweak browser extension AddEdit save UX

Leendert de Borst25b1c199197b
diff --git a/apps/browser-extension/src/entrypoints/popup/components/HeaderButton.tsx b/apps/browser-extension/src/entrypoints/popup/components/HeaderButton.tsx
index 97a71d6e4..d5c2a7982 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/HeaderButton.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/HeaderButton.tsx
@@ -8,6 +8,8 @@ type HeaderButtonProps = {
iconType: HeaderIconType;
variant?: 'default' | 'primary' | 'danger';
id?: string;
+ disabled?: boolean;
+ isLoading?: boolean;
};
/**
@@ -18,7 +20,9 @@ const HeaderButton: React.FC<HeaderButtonProps> = ({
title,
iconType,
variant = 'default',
- id
+ id,
+ disabled = false,
+ isLoading = false
}) => {
const colorClasses = {
default: 'text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700',
@@ -26,14 +30,24 @@ const HeaderButton: React.FC<HeaderButtonProps> = ({
danger: 'text-red-500 hover:text-red-600 hover:bg-red-100 dark:hover:bg-red-900/20'
};
+ const isDisabled = disabled || isLoading;
+
return (
<button
id={id}
onClick={onClick}
- className={`p-2 rounded-lg ${colorClasses[variant]}`}
+ disabled={isDisabled}
+ className={`p-2 rounded-lg ${colorClasses[variant]} ${isDisabled ? 'opacity-50 cursor-not-allowed' : ''}`}
title={title}
>
- <HeaderIcon type={iconType} />
+ {isLoading ? (
+ <svg className="animate-spin h-5 w-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
+ <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
+ <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
+ </svg>
+ ) : (
+ <HeaderIcon type={iconType} />
+ )}
</button>
);
};
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
index 35148aa73..e754e2a70 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
@@ -1,4 +1,5 @@
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
+import { flushSync } from 'react-dom';
import { useTranslation } from 'react-i18next';
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
@@ -88,6 +89,7 @@ const ItemAddEdit: React.FC = () => {
// Component state
const [localLoading, setLocalLoading] = useState(true);
+ const [isSaving, setIsSaving] = useState(false);
const [showDeleteModal, setShowDeleteModal] = useState(false);
const [item, setItem] = useState<Item | null>(null);
@@ -625,10 +627,24 @@ const ItemAddEdit: React.FC = () => {
* Handle form submission.
*/
const handleSave = useCallback(async () => {
- if (!item) {
+ if (!item || isSaving) {
return;
}
+ /*
+ * Use flushSync to force React to render the loading state immediately.
+ * This ensures the spinner shows before the blocking vault export begins.
+ */
+ flushSync(() => {
+ setIsSaving(true);
+ });
+
+ /*
+ * Additional yield to event loop to ensure DOM has updated.
+ * This is critical for showing the loading animation before heavy synchronous work.
+ */
+ await new Promise(resolve => setTimeout(resolve, 10));
+
try {
// Build the fields array from fieldValues
const fields: ItemField[] = [];
@@ -679,15 +695,21 @@ const ItemAddEdit: React.FC = () => {
UpdatedAt: new Date().toISOString()
};
- // Fetch and attach favicon from URL if needed (handles deduplication internally)
- if (dbContext?.sqliteClient) {
- setLocalLoading(true);
+ /*
+ * Fetch and attach favicon from URL if needed (handles deduplication internally).
+ * Only call if we have a URL value to avoid unnecessary processing.
+ */
+ const urlValue = fieldValues['login.url'];
+ if (dbContext?.sqliteClient && urlValue) {
updatedItem = await FaviconService.fetchAndAttachFavicon(
updatedItem,
- fieldValues['login.url'],
+ urlValue,
dbContext.sqliteClient,
webApi
);
+ } else if (!urlValue) {
+ // Explicitly clear logo if no URL (Note items, etc.)
+ updatedItem.Logo = undefined;
}
// Save to database and sync vault
@@ -700,8 +722,6 @@ const ItemAddEdit: React.FC = () => {
* Sync happens in background, status shown via header indicator.
*/
await executeVaultMutationAsync(async () => {
- setLocalLoading(false);
-
if (isEditMode) {
await dbContext.sqliteClient!.items.update(
updatedItem,
@@ -738,8 +758,9 @@ const ItemAddEdit: React.FC = () => {
}
} catch (err) {
console.error('Error saving item:', err);
+ setIsSaving(false);
}
- }, [item, fieldValues, applicableSystemFields, customFields, dbContext, isEditMode, executeVaultMutationAsync, navigate, originalAttachmentIds, attachments, originalTotpCodeIds, totpCodes, passkeyIdsMarkedForDeletion, webApi, clearPersistedValues]);
+ }, [item, isSaving, fieldValues, applicableSystemFields, customFields, dbContext, isEditMode, executeVaultMutationAsync, navigate, originalAttachmentIds, attachments, originalTotpCodeIds, totpCodes, passkeyIdsMarkedForDeletion, webApi, clearPersistedValues]);
/**
* Handle delete action.
@@ -977,13 +998,16 @@ const ItemAddEdit: React.FC = () => {
title={t('items.deleteItemTitle')}
iconType={HeaderIconType.DELETE}
variant="danger"
+ disabled={isSaving}
/>
)}
<HeaderButton
id="save-credential"
onClick={handleSave}
- title={t('items.saveItem')}
+ title={isSaving ? t('common.saving') : t('items.saveItem')}
iconType={HeaderIconType.SAVE}
+ isLoading={isSaving}
+ disabled={isSaving}
/>
</div>
);
@@ -991,7 +1015,7 @@ const ItemAddEdit: React.FC = () => {
setHeaderButtons(headerButtonsJSX);
return (): void => setHeaderButtons(null);
- }, [setHeaderButtons, isEditMode, t, handleSave]);
+ }, [setHeaderButtons, isEditMode, t, handleSave, isSaving]);
/**
* Render a field input based on field type.