-
Notifications
You must be signed in to change notification settings - Fork 78
fix: trigger warning toast when localstorage is full #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: trigger warning toast when localstorage is full #329
Conversation
There was a problem hiding this 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.
tests/session-interaction.test.ts
Outdated
// 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; | ||
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this 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:
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: EDIT 2: |
- Added !outline-none to remove blue border - Added !bg-yellow-700 to ensure yellow background
There was a problem hiding this 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!
src/routes/+layout.svelte
Outdated
'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', |
There was a problem hiding this comment.
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 👍
src/lib/localStorage.ts
Outdated
} catch (error) { | ||
// Handle localStorage quota exceeded error | ||
if (error instanceof DOMException && error.name === 'QuotaExceededError') { | ||
toast.warning('Localstorage is full', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toast.warning('Localstorage is full', { | |
toast.warning('Local storage is full', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tests/session-interaction.test.ts
Outdated
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await expect(toastLocator).toContainText('Localstorage is full'); | |
await expect(toastLocator).toContainText('Local storage is full'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Perfect Fernando, typo resolved and styling hack was reverted! Great, we are ready to go! |
Thanks for the contribution @mcendon! |
🎉 This PR is included in version 0.35.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
You're welcome, Fernando. Count on me for other contributions—I'm short on time, but I'll help however I can! Cheers. |
Closes #318