Skip to content

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

Update browser extension item addedit back navigation flow (#1804)

Leendert de Borstce0db8641fd2
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 ea117679f..20cc7aa5b 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
@@ -1,7 +1,7 @@
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';
+import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';
import Modal from '@/entrypoints/popup/components/Dialogs/Modal';
import AddFieldMenu, { type OptionalSection } from '@/entrypoints/popup/components/Forms/AddFieldMenu';
@@ -71,6 +71,7 @@ const ItemAddEdit: React.FC = () => {
const { t } = useTranslation();
const { id } = useParams();
const [searchParams] = useSearchParams();
+ const location = useLocation();
const navigate = useNavigate();
const dbContext = useDb();
const isEditMode = id !== undefined && id.length > 0;
@@ -746,12 +747,12 @@ const ItemAddEdit: React.FC = () => {
void clearPersistedValues();
/*
- * Navigate back after save:
- * - Edit mode: use navigate(-1) to return to the existing details page in history.
- * This avoids creating duplicate history entries.
- * - Create mode: navigate to the new item's details page, replacing the add page.
+ * Navigate after save:
+ * - Edit mode and came from details: navigate(-1) so back from details goes to list (no duplicate details).
+ * - Edit mode and did not come from details: go to details with replace so we still land on details.
+ * - Create mode: go to new item details with replace.
*/
- if (isEditMode) {
+ if (isEditMode && (location.state as { fromDetails?: boolean } | null)?.fromDetails) {
navigate(-1);
} else {
navigate(`/items/${updatedItem.Id}`, { replace: true });
@@ -760,7 +761,7 @@ const ItemAddEdit: React.FC = () => {
console.error('Error saving item:', err);
setIsSaving(false);
}
- }, [item, isSaving, fieldValues, applicableSystemFields, customFields, dbContext, isEditMode, executeVaultMutationAsync, navigate, originalAttachmentIds, attachments, originalTotpCodeIds, totpCodes, passkeyIdsMarkedForDeletion, webApi, clearPersistedValues]);
+ }, [item, isSaving, fieldValues, applicableSystemFields, customFields, dbContext, isEditMode, executeVaultMutationAsync, navigate, location.state, originalAttachmentIds, attachments, originalTotpCodeIds, totpCodes, passkeyIdsMarkedForDeletion, webApi, clearPersistedValues]);
/**
* Handle delete action.
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemDetails.tsx b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemDetails.tsx
index 32fc8e97b..1bc7a8e52 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemDetails.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemDetails.tsx
@@ -43,9 +43,10 @@ const ItemDetails: React.FC = (): React.ReactElement => {
/**
* Navigate to the edit page for this item.
+ * Pass fromDetails so save can use navigate(-1) and avoid duplicate details in history.
*/
const handleEdit = useCallback((): void => {
- navigate(`/items/${id}/edit`);
+ navigate(`/items/${id}/edit`, { state: { fromDetails: true } });
}, [id, navigate]);
useEffect(() => {