Skip to content
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

First alert.toast() produces error #2336

Open
lbird-mma opened this issue Jan 8, 2025 · 4 comments
Open

First alert.toast() produces error #2336

lbird-mma opened this issue Jan 8, 2025 · 4 comments
Labels
bug Things that aren't working right in the library.

Comments

@lbird-mma
Copy link

lbird-mma commented Jan 8, 2025

Describe the bug

The Alert component has a built-in .toast() method. I'm using the demo code from the shoelace website.
When called for the first time, it either

  1. produces no toast. A quick flash of the text is shown below the button (or end of document)
  2. runs into an error. Uncaught TypeError: alert.toast is not a function

On the Shoelace site it all works fine, however isolating it doesn't.

To Reproduce

Steps to reproduce the behavior:

See demo

Demo

Codepen

Browser / OS

  • OS: Windows 11
  • Browser: [Brave/Chrome/Firefox]
  • Browser version: latest

Additional information

@lbird-mma lbird-mma added the bug Things that aren't working right in the library. label Jan 8, 2025
@CetinSert
Copy link

https://xcodepen.io/lbird-mma/pen/WbeMeZO
This is the error and DOM state after several .toast()s:
image

@vonpawn
Copy link

vonpawn commented Jan 12, 2025

In case this helps you, I was running into the same issue due to using the autoloading version of shoelace. The solution in #1324 worked for me.

@lbird-mma
Copy link
Author

@vonpawn Thanks so much, yes this helps. I was using autoloader and didn't think of that. Just to prevent this issue and some FOUC related problems, I decided to go back to the traditional loader. Also because I use a lot SL components it's worth the initial performance penalty.

@lbird-mma
Copy link
Author

lbird-mma commented Jan 13, 2025

@claviska : won't close this just yet, as it might be good to mention this in the documentation example.
Either use traditional loader or use
customElements.whenDefined('sl-alert').then(() => alert.toast());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Things that aren't working right in the library.
Projects
None yet
Development

No branches or pull requests

3 participants