mzohaibqc / svelte-toasts

A highly configurable notification/toast component with individual toast state management capabilities.
https://mzohaibqc.github.io/svelte-toasts/
MIT License
42 stars 6 forks source link

Duplicate Keys #6

Open jamesatjaminit opened 2 years ago

jamesatjaminit commented 2 years ago

Since the UID of a toast is generated via Date.now() generating two toasts quickly after one another causes svelte to throw: Error: Cannot have duplicate keys in a keyed each. I fixed it in my fork by generating the UID using Math.random() which should reduce the collision rate, although I'm not sure if that's how you'd like to fix it.

image

tv42 commented 2 years ago

Math.random isn't guaranteed unique either. It seems like a simple counter would be plenty for this.

AlexRMU commented 2 years ago
    let last_toast = 0;
    function add_toast(...) {
        while (last_toast == Date.now()) {}
        last_toast = Date.now();
        toasts.add({...});
    }
unlocomqx commented 2 years ago

I think it should check if a uid is passed before overwriting it I tried passing a uid but it's not taken into account

pyoner commented 1 year ago

I think we should use a global counter

shyunku commented 4 months ago

I create PR for this, using key instead of uid, auto-generated uuid.v4() or given input