svelte-toasts icon indicating copy to clipboard operation
svelte-toasts copied to clipboard

Duplicate Keys

Open jamesatjaminit opened this issue 3 years ago • 5 comments
trafficstars

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

jamesatjaminit avatar Jan 15 '22 15:01 jamesatjaminit

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

tv42 avatar Feb 09 '22 01:02 tv42

    let last_toast = 0;
    function add_toast(...) {
        while (last_toast == Date.now()) {}
        last_toast = Date.now();
        toasts.add({...});
    }

AlexRMU avatar Jul 07 '22 11:07 AlexRMU

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

unlocomqx avatar Jul 08 '22 17:07 unlocomqx

I think we should use a global counter

pyoner avatar Jan 08 '23 19:01 pyoner

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

shyunku avatar Mar 14 '24 13:03 shyunku