Skip to content

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

Update import flow to prevent UI reset and apply favicon reuse (#1583)

Leendert de Borst0e6d5bf0c0e2
diff --git a/apps/server/AliasVault.Client/Main/Pages/Items/Home.razor b/apps/server/AliasVault.Client/Main/Pages/Items/Home.razor
index 5ba0473be..12421fd5a 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Items/Home.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Items/Home.razor
@@ -905,6 +905,11 @@ else
await LoadItemsAsync();
}
+ /// <summary>
+ /// Tracks whether the IntersectionObserver is currently set up.
+ /// </summary>
+ private bool _isObserverSetup;
+
/// <inheritdoc />
protected override async Task OnAfterRenderAsync(bool firstRender)
{
@@ -913,14 +918,28 @@ else
if (firstRender)
{
await LoadItemsAsync();
-
- // Set up IntersectionObserver for infinite scroll (only if there are more items to load).
- // The sentinel element only exists when HasMoreItems is true.
_dotNetRef = DotNetObjectReference.Create(this);
- if (HasMoreItems)
+ }
+
+ // Set up or re-attach the IntersectionObserver after every render if there are more items.
+ // The sentinel element is only in the DOM when HasMoreItems is true, and it gets
+ // re-created on each render, so we need to re-attach the observer.
+ if (HasMoreItems && !IsLoading && !IsLoadingMore && _dotNetRef != null)
+ {
+ // Always tear down and re-setup to handle the new sentinel element reference
+ if (_isObserverSetup)
{
- await JsInteropService.SetupInfiniteScroll(_scrollSentinel, _dotNetRef);
+ await JsInteropService.TeardownInfiniteScroll(_scrollSentinel);
}
+
+ await JsInteropService.SetupInfiniteScroll(_scrollSentinel, _dotNetRef);
+ _isObserverSetup = true;
+ }
+ else if (!HasMoreItems && _isObserverSetup)
+ {
+ // No more items - clean up the observer
+ await JsInteropService.TeardownInfiniteScroll(_scrollSentinel);
+ _isObserverSetup = false;
}
}
@@ -929,7 +948,12 @@ else
{
if (_dotNetRef != null)
{
- await JsInteropService.TeardownInfiniteScroll(_scrollSentinel);
+ if (_isObserverSetup)
+ {
+ await JsInteropService.TeardownInfiniteScroll(_scrollSentinel);
+ _isObserverSetup = false;
+ }
+
_dotNetRef.Dispose();
_dotNetRef = null;
}
diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
index 5e67f3242..3eba76ec0 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
@@ -167,6 +167,20 @@
</div>
</div>
}
+ else if (IsSavingCredentials)
+ {
+ <div class="text-center">
+ <LoadingIndicator />
+ <p class="mt-4 text-gray-700 dark:text-gray-300">@string.Format(Localizer["SavingCredentials"], CredentialSaveProgress, TotalCredentialsToSave)</p>
+ </div>
+ }
+ else if (IsSyncingVault)
+ {
+ <div class="text-center">
+ <LoadingIndicator />
+ <p class="mt-4 text-gray-700 dark:text-gray-300">@Localizer["SyncingVault"]</p>
+ </div>
+ }
else
{
<LoadingIndicator />
@@ -263,6 +277,12 @@
private CancellationTokenSource? FaviconExtractionCancellation { get; set; }
private Dictionary<string, byte[]> ExtractedFavicons { get; set; } = new();
+ private bool IsSavingCredentials { get; set; }
+ private int CredentialSaveProgress { get; set; }
+ private int TotalCredentialsToSave { get; set; }
+ private bool IsSyncingVault { get; set; }
+ private Dictionary<string, Guid> ImportSessionLogoIds { get; set; } = new();
+
private int DuplicateCredentialsCount { get; set; } = 0;
/// <summary>
@@ -367,7 +387,8 @@
}
catch (Exception ex)
{
- ImportError = $"Error importing credentials: {ex.Message}";
+ ImportError = Localizer["ImportErrorGeneric"];
+ Logger.LogError(ex, "Error during import");
}
finally
{
@@ -396,6 +417,8 @@
{
IsImporting = false;
IsExtractingFavicons = false;
+ IsSavingCredentials = false;
+ IsSyncingVault = false;
StateHasChanged();
}
@@ -418,6 +441,10 @@
TotalFaviconsToExtract = credentialsWithUrls.Count();
+ // Update UI every N items - Task.Delay(1) is required to let browser actually render
+ // Task.Yield() doesn't work because it doesn't give the browser event loop time to paint
+ const int updateEveryNItems = 10;
+
foreach (var credential in credentialsWithUrls)
{
if (FaviconExtractionCancellation.Token.IsCancellationRequested)
@@ -443,12 +470,25 @@
}
catch
{
- // Invalid URL - skip
+ // Invalid URL
}
FaviconExtractionProgress++;
- StateHasChanged();
+
+ // Update UI periodically
+ if (FaviconExtractionProgress % updateEveryNItems == 0)
+ {
+ StateHasChanged();
+ await Task.Delay(1);
+ }
}
+
+ // Final update to show 100% completion before transitioning to next phase
+ StateHasChanged();
+ await Task.Delay(50);
+
+ IsExtractingFavicons = false;
+ StateHasChanged();
}
/// <summary>
@@ -493,21 +533,45 @@
}
var items = BaseImporter.ConvertToItem(ImportedCredentials, folderNameToId);
+
+ // Clear logo tracking for this import session
+ ImportSessionLogoIds.Clear();
+
+ // Show saving credentials progress
+ IsSavingCredentials = true;
+ CredentialSaveProgress = 0;
+ TotalCredentialsToSave = items.Count;
+ StateHasChanged();
+
+ const int updateEveryNItems = 10;
foreach (var item in items)
{
await ProcessSingleItem(item);
- await Task.Delay(2); // Small delay to avoid blocking the UI thread
+ CredentialSaveProgress++;
+
+ if (CredentialSaveProgress % updateEveryNItems == 0)
+ {
+ StateHasChanged();
+ await Task.Delay(1);
+ }
}
+ StateHasChanged();
+ await Task.Delay(50);
+
+ IsSavingCredentials = false;
+ IsSyncingVault = true;
+ StateHasChanged();
+
var success = await DbService.SaveDatabaseAsync();
if (success)
{
- GlobalNotificationService.AddSuccessMessage($"Successfully imported {ImportedCredentials.Count} credentials.");
+ GlobalNotificationService.AddSuccessMessage(string.Format(Localizer["ImportSuccessMessage"], ImportedCredentials.Count));
NavigationManager.NavigateTo("/items");
}
else
{
- ImportError = "Error saving database.";
+ ImportError = Localizer["ImportErrorGeneric"];
}
}
@@ -531,7 +595,7 @@
}
else
{
- // Create new folder - CreateAsync returns the new folder ID directly
+ // Create new folder
var newFolderId = await FolderService.CreateAsync(folderName);
folderNameToId[folderName] = newFolderId;
}
@@ -558,37 +622,49 @@
domain = domain[4..];
}
- var context = await DbService.GetDbContextAsync();
-
- // Check if logo already exists for this source (deduplication)
- var existingLogo = await context.Logos.FirstOrDefaultAsync(l => l.Source == domain);
- if (existingLogo != null)
+ // First check if we already created a logo for this domain in this import session
+ if (ImportSessionLogoIds.TryGetValue(domain, out var sessionLogoId))
{
- // Reuse existing logo
- item.LogoId = existingLogo.Id;
+ item.LogoId = sessionLogoId;
}
- else if (ExtractedFavicons.TryGetValue(domain, out var favicon))
+ else
{
- // Create new logo from extracted favicon
- var logo = new Logo
+ var context = await DbService.GetDbContextAsync();
+
+ var existingLogo = await context.Logos.FirstOrDefaultAsync(l => l.Source == domain);
+ if (existingLogo != null)
+ {
+ // Reuse existing logo
+ item.LogoId = existingLogo.Id;
+ ImportSessionLogoIds[domain] = existingLogo.Id;
+ }
+ else if (ExtractedFavicons.TryGetValue(domain, out var favicon))
{
- Id = Guid.NewGuid(),
- Source = domain,
- FileData = favicon,
- MimeType = "image/png",
- FetchedAt = DateTime.UtcNow,
- CreatedAt = DateTime.UtcNow,
- UpdatedAt = DateTime.UtcNow
- };
- context.Logos.Add(logo);
- item.LogoId = logo.Id;
+ // Create new logo
+ var logo = new Logo
+ {
+ Id = Guid.NewGuid(),
+ Source = domain,
+ FileData = favicon,
+ MimeType = "image/png",
+ FetchedAt = DateTime.UtcNow,
+ CreatedAt = DateTime.UtcNow,
+ UpdatedAt = DateTime.UtcNow
+ };
+ context.Logos.Add(logo);
+ item.LogoId = logo.Id;
+
+ // Track this logo for subsequent items with same domain
+ ImportSessionLogoIds[domain] = logo.Id;
+ }
}
}
catch
{
- // Invalid URL - skip logo assignment
+ // Invalid URL
}
}
+
await ItemService.InsertEntryAsync(item, false, false);
}
@@ -599,13 +675,13 @@
{
if (string.IsNullOrEmpty(e.File.Name))
{
- ImportError = $"Please select a valid {ServiceName} export file to import";
+ ImportError = Localizer["ImportErrorInvalidFile"];
return;
}
if (e.File.Name.EndsWith(".zip"))
{
- ImportError = $"Please unzip the {ServiceName} export file before importing, please read the instructions below for more information.";
+ ImportError = Localizer["ImportErrorZipFile"];
return;
}
@@ -617,7 +693,8 @@
// Limit file size to 10MB
if (e.File.Size > 10 * 1024 * 1024)
{
- throw new ArgumentException("File size exceeds 10MB limit");
+ ImportError = Localizer["ImportErrorFileTooLarge"];
+ return;
}
await using var stream = e.File.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024);
@@ -638,7 +715,7 @@
}
catch (Exception ex)
{
- ImportError = $"Error processing {ServiceName} export file. Please check the file format and try again.";
+ ImportError = Localizer["ImportErrorGeneric"];
Logger.LogError(ex, "Error processing {ServiceName} export file", ServiceName);
}
finally
diff --git a/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServiceCard.en.resx b/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServiceCard.en.resx
index 923f6f6d2..c80fee9ac 100644
--- a/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServiceCard.en.resx
+++ b/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServiceCard.en.resx
@@ -138,4 +138,32 @@
<value>Extracting favicons... {0} / {1}</value>
<comment>Progress text during favicon extraction. {0} is current progress, {1} is total</comment>
</data>
+ <data name="SavingCredentials" xml:space="preserve">
+ <value>Saving credentials to vault... {0} / {1}</value>
+ <comment>Progress text during credential save. {0} is current progress, {1} is total</comment>
+ </data>
+ <data name="SyncingVault" xml:space="preserve">
+ <value>Syncing vault to server...</value>
+ <comment>Progress text when syncing vault to server after import</comment>
+ </data>
+ <data name="ImportSuccessMessage" xml:space="preserve">
+ <value>Successfully imported {0} credentials.</value>
+ <comment>Success message after import completes. {0} is the credential count</comment>
+ </data>
+ <data name="ImportErrorGeneric" xml:space="preserve">
+ <value>An error occurred during import. Please try again.</value>
+ <comment>Generic error message when import fails</comment>
+ </data>
+ <data name="ImportErrorInvalidFile" xml:space="preserve">
+ <value>Please select a valid export file to import.</value>
+ <comment>Error message when invalid file is selected</comment>
+ </data>
+ <data name="ImportErrorZipFile" xml:space="preserve">
+ <value>Please unzip the export file before importing. See the instructions below for more information.</value>
+ <comment>Error message when user tries to import a zip file</comment>
+ </data>
+ <data name="ImportErrorFileTooLarge" xml:space="preserve">
+ <value>File size exceeds 10MB limit.</value>
+ <comment>Error message when file is too large</comment>
+ </data>
</root>
\ No newline at end of file