Skip to content

Conversation

mcendon
Copy link
Contributor

@mcendon mcendon commented Jul 15, 2025

Closes #318

  • Added the warning toast with "Failed to save to localStorage" and error message when localStorage quota is full
  • Playwright test added

Copy link
Owner

@fmaclen fmaclen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting the PR, left you some minor notes.

Comment on lines 731 to 735
// Remove the filler key to clean up localStorage
await page.waitForFunction(() => {
localStorage.removeItem('hollama-localStorage-full-test');
return localStorage.getItem('hollama-localStorage-full-test') === null;
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to do the cleanup, Playwright will reset the session at the end of the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed that cleanup and improved the test (locator is warning toast specific, only 1 toast and containing user-friendly message)

@fmaclen fmaclen changed the title Fix/trigger warning toast when localstorage is full #318 fix: trigger warning toast when localstorage is full Jul 17, 2025
@mcendon mcendon requested a review from fmaclen July 17, 2025 18:01
Copy link
Owner

@fmaclen fmaclen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are more or less there. Found a styling bug with the toast, it's rendered in a semi-transparent blue color:

Image

Probably because we are triggering it from a non-svelte file but I don't have time to really investigate.

So for now let's rely on a hack by adding !important to CSS classes to override inline styles:

// src/routes/+layout.svelte
<Toaster
	toastOptions={{
		unstyled: true,
		classes: {
			toast:
-				'shadow-xl px-4 py-3 flex items-center gap-x-3 max-w-full w-full rounded mx-auto text-xs mx-0',
+				'shadow-xl px-4 py-3 flex items-center gap-x-3 max-w-full w-full rounded mx-auto text-xs mx-0 !outline-none',
			loading: 'bg-shade-0',
			error: 'text-red-50 bg-red-700',
			success: 'text-emerald-50 bg-emerald-700',
-			warning: 'text-yellow-50 bg-yellow-700',
+			warning: 'text-yellow-50 !bg-yellow-700',
			info: 'bg-shade-1 text-neutral-500'
		}
	}}
	position="top-center"
/>
  • Added !outline-none to remove blue border
  • Added !bg-yellow-700 to ensure yellow background

@mcendon
Copy link
Contributor Author

mcendon commented Jul 19, 2025

I think we are more or less there. Found a styling bug with the toast, it's rendered in a semi-transparent blue color:

Image Probably because we are triggering it from a non-svelte file but I don't have time to really investigate.

So for now let's rely on a hack by adding !important to CSS classes to override inline styles:

// src/routes/+layout.svelte
<Toaster
	toastOptions={{
		unstyled: true,
		classes: {
			toast:
-				'shadow-xl px-4 py-3 flex items-center gap-x-3 max-w-full w-full rounded mx-auto text-xs mx-0',
+				'shadow-xl px-4 py-3 flex items-center gap-x-3 max-w-full w-full rounded mx-auto text-xs mx-0 !outline-none',
			loading: 'bg-shade-0',
			error: 'text-red-50 bg-red-700',
			success: 'text-emerald-50 bg-emerald-700',
-			warning: 'text-yellow-50 bg-yellow-700',
+			warning: 'text-yellow-50 !bg-yellow-700',
			info: 'bg-shade-1 text-neutral-500'
		}
	}}
	position="top-center"
/>
  • Added !outline-none to remove blue border
  • Added !bg-yellow-700 to ensure yellow background

Mmm it's pretty weird... I haven't checked with --ui parameter the last time, but before my last commit changes ( b2e3286#diff-2ee3676f914b574f502300b378adbd28b876202fd3769466dda03777209deb70) I executed it with --ui and the toast was OK (yellow color / no transparency)

I guess the problem is with the playwright test itself, because when running a local server and manually executes the test in the browser (I am using Chrome 138.0.7204.157 (Official Build) (64-bit) under Pop OS!) the toast styles are fine.

Anyway, I'll check the test code again because i think is related with the test code and not with the actual toast...

EDIT:
I just did a quick test by dispatching an event from localStorage.ts, then listening for the event and creating the toast on layout.svelte onMount() hook and the style problem persists when running the test. So, i don't think that the problem is related with creating the toast from a non-svelte file... i notice that playwright is executing the test using chromium-1169 binary that is a version from 2021, it could maybe related with that (i dont have enough time now to investigate it also :D)

EDIT 2:
Workaround for toast styles added

- Added !outline-none to remove blue border
- Added !bg-yellow-700 to ensure yellow background
@mcendon mcendon requested a review from fmaclen July 19, 2025 21:56
Copy link
Owner

@fmaclen fmaclen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into the Playwright issue. Your earlier implementation appears to be working fine without the hacks.

Also left you 2 minor typo changes.

Other than that, we are good to go!

Comment on lines 131 to 135
'shadow-xl px-4 py-3 flex items-center gap-x-3 max-w-full w-full rounded mx-auto text-xs mx-0 !outline-none',
loading: 'bg-shade-0',
error: 'text-red-50 bg-red-700',
success: 'text-emerald-50 bg-emerald-700',
warning: 'text-yellow-50 bg-yellow-700',
warning: 'text-yellow-50 bg-yellow-700 !bg-yellow-700',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the problem is with the playwright test itself, because when running a local server and manually executes the test in the browser (I am using Chrome 138.0.7204.157 (Official Build) (64-bit) under Pop OS!) the toast styles are fine.

Oh, great catch! I think you are right, I just re-ran the test but took a screenshot instead of using the Trace Viewer and the colors are correct!

We can undo the hacks 👍

} catch (error) {
// Handle localStorage quota exceeded error
if (error instanceof DOMException && error.name === 'QuotaExceededError') {
toast.warning('Localstorage is full', {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
toast.warning('Localstorage is full', {
toast.warning('Local storage is full', {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const toastLocator = page.locator('ol[data-sonner-toaster] li[data-type="warning"]');
await expect(toastLocator).toBeVisible();
await expect(toastLocator).toHaveCount(1);
await expect(toastLocator).toContainText('Localstorage is full');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await expect(toastLocator).toContainText('Localstorage is full');
await expect(toastLocator).toContainText('Local storage is full');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@mcendon
Copy link
Contributor Author

mcendon commented Jul 20, 2025

Perfect Fernando, typo resolved and styling hack was reverted! Great, we are ready to go!

@mcendon mcendon requested a review from fmaclen July 20, 2025 15:44
@fmaclen fmaclen merged commit 15cc272 into fmaclen:main Jul 20, 2025
2 checks passed
@fmaclen
Copy link
Owner

fmaclen commented Jul 20, 2025

Thanks for the contribution @mcendon!

github-actions bot pushed a commit that referenced this pull request Jul 20, 2025
## [0.35.1](0.35.0...0.35.1) (2025-07-20)

### Bug Fixes

* trigger warning toast when localstorage is full ([#329](#329)) ([15cc272](15cc272)), closes [#318](#318)
Copy link
Contributor

🎉 This PR is included in version 0.35.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@mcendon
Copy link
Contributor Author

mcendon commented Jul 20, 2025

Thanks for the contribution @mcendon!

You're welcome, Fernando. Count on me for other contributions—I'm short on time, but I'll help however I can! Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trigger warning toast when the localStorage is full
2 participants