Skip to content

fix: auto-generate unique IDs so multiple toasts display simultaneously#25

Open
lubauss wants to merge 1 commit intohiaaryan:mainfrom
lubauss:fix/unique-toast-ids
Open

fix: auto-generate unique IDs so multiple toasts display simultaneously#25
lubauss wants to merge 1 commit intohiaaryan:mainfrom
lubauss:fix/unique-toast-ids

Conversation

@lubauss
Copy link
Copy Markdown
Contributor

@lubauss lubauss commented Feb 21, 2026

Summary

Change the default toast ID from the hardcoded "sileo-default" to an auto-generated unique ID, so multiple toasts can display simultaneously.

Problem

In createToast(), when no id is provided, it defaults to "sileo-default":

const id = merged.id ?? "sileo-default";

This means every toast without an explicit id shares the same identifier. Calling sileo.success(...) twice in quick succession replaces the first toast instead of showing two separate notifications.

// Only shows ONE toast — the second replaces the first
sileo.success({ title: "Toast 1" });
sileo.success({ title: "Toast 2" });

This is unexpected — most toast libraries (Sonner, react-hot-toast, etc.) show each call as a separate notification.

Solution

Use the existing generateId() helper (already defined in the file) as the default:

// Before
const id = merged.id ?? "sileo-default";

// After
const id = merged.id ?? generateId();

generateId() produces IDs like "3-m1abc2d-x7k9f2" (counter + timestamp + random), ensuring uniqueness.

Files Changed

File Changes
src/toast.tsx (line 134) Replace "sileo-default" with generateId()

Backward Compatibility

  • Explicit id usage still works exactly as before (deduplicated)
  • Only affects the default case where no id is provided
  • Users who want the old "replace" behavior can pass a fixed id:
// Still deduplicates when you pass an explicit id
sileo.success({ title: "Toast 1", id: "my-toast" });
sileo.success({ title: "Toast 2", id: "my-toast" }); // Replaces first

Testing

// After fix: shows TWO separate toasts
sileo.success({ title: "Toast 1" });
sileo.success({ title: "Toast 2" });

The default toast ID was hardcoded to "sileo-default", meaning every
toast without an explicit id shared the same identifier. Calling
sileo.success() twice would replace the first toast instead of showing
two separate notifications.

Changed the fallback to use the existing generateId() helper, which
produces unique IDs (counter + timestamp + random). Users who want the
old "replace" behavior can still pass an explicit id.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant