Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
echo "tag=$TAG" >> "$GITHUB_OUTPUT"

# Staged, not published: nothing is public until a maintainer approves it
# with 2FA (`npm stage approve`, see CONTRIBUTING.md). Trusted Publishing
# with 2FA (`pnpm stage approve`, see CONTRIBUTING.md). Trusted Publishing
# adds the provenance statement on its own.
- name: Stage via Trusted Publishing (OIDC)
run: npm stage publish *.tgz --access public --tag ${{ steps.disttag.outputs.tag }}
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ at build time too (`website/src/lib/github.ts`). Details: `website/README.md`.

A `v*` tag (pushed by `pnpm release`) runs `.github/workflows/release.yml`: CI → tag/version check →
pack + contents check → `npm stage publish` (Trusted Publishing) → draft GitHub release
(changelogithub) → waits until a maintainer runs `npm stage approve` (2FA) → publishes the release →
(changelogithub) → waits until a maintainer runs `pnpm stage approve` (2FA) → publishes the release →
deploys the website. Steps: `CONTRIBUTING.md` → Releases.

## Public API of the library
Expand Down
9 changes: 5 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ version (`2.0.0-beta.2`…), commits it, tags it and pushes. The tag runs
`feat`, `fix` and `perf` commits, and only marks a change as breaking when its commit has a `!` or
a `BREAKING CHANGE:` footer.

Nothing is public until a maintainer approves the staged version with 2FA (npm 11.15 or later):
Nothing is public until a maintainer approves the staged version with 2FA, with the repo's pnpm
(`pnpm stage`, logged in with `pnpm login`) or npm 11.15 or later (`npm stage`, same subcommands):

```sh
npm stage list qwik-sonner
npm stage approve <stage-id> # asks for the one-time password
pnpm stage list qwik-sonner
pnpm stage approve <stage-id> # asks for the one-time password
```

The workflow waits for that (up to 6 hours), then publishes the GitHub release and deploys the
website, which reads the new version from npm. If the approval takes longer, publish the draft
release by hand and run the Website workflow (Actions → Website → Run workflow). To drop a staged
version, `npm stage reject <stage-id>` and delete the draft release.
version, `pnpm stage reject <stage-id>` and delete the draft release.

Staging needs the npm Trusted Publisher of `qwik-sonner` (GitHub Actions, `release.yml`) to allow
`npm stage publish`. Keep the workflow's file name: the Trusted Publisher is tied to it.
Expand Down
11 changes: 4 additions & 7 deletions website/src/lib/toaster-context.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createContextId, useContext, type Signal } from "@qwik.dev/core";
import type { ToasterProps } from "qwik-sonner";
import type { Position, Theme } from "qwik-sonner";

// qwik-sonner doesn't export these unions yet, so derive them from the props.
export type Position = Extract<NonNullable<ToasterProps["position"]>, string>;
export type Theme = Extract<NonNullable<ToasterProps["theme"]>, string>;
export type { Position, Theme };

export const POSITIONS: Position[] = [
"top-left",
Expand All @@ -16,9 +14,8 @@ export const POSITIONS: Position[] = [

/**
* Live settings of the site-wide `<Toaster>` rendered in the root layout. Demos
* on any page write to these signals instead of rendering their own Toaster:
* a Toaster that is first rendered on the client (e.g. after a `<Link>`
* navigation) never subscribes in qwik-sonner 2.0.0-beta.1.
* on any page write to these signals instead of rendering their own Toaster,
* so every toast on the site comes from the same one.
*/
export interface ToasterControls {
position: Signal<Position>;
Expand Down
75 changes: 30 additions & 45 deletions website/src/routes/docs/v2/advanced/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ const typesCode = `import type {
ToastClassnames,
ToastToDismiss,
Action,
} from "qwik-sonner";

// Not exported yet — derive them from ToasterProps:
type Position = Extract<ToasterProps["position"], string>;
type Theme = Extract<ToasterProps["theme"], string>;
type Direction = Extract<ToasterProps["dir"], string>;`;
Position, // "top-left" | "top-center" | … | "bottom-right"
Theme, // "light" | "dark" | "system"
Direction, // "rtl" | "ltr" | "auto"
SwipeDirection, // "top" | "right" | "bottom" | "left"
ToastTypes,
ToastIcons,
Offset,
PromiseData,
} from "qwik-sonner"; // the same from "qwik-sonner/headless"`;

export default component$(() => {
return (
Expand All @@ -65,7 +68,10 @@ export default component$(() => {
<code>toast()</code> writes to a small module-level store, the same design as sonner. Each{" "}
<code>{"<Toaster />"}</code> subscribes to it in the browser once Qwik starts (on the{" "}
<code>qinit</code> event), so the Toaster's code only loads when the page boots — not when
it scrolls into view — and toasts work even if it sits below the fold.
it scrolls into view — and toasts work even if it sits below the fold. A Toaster first
rendered in the browser (behind a condition, or after a <code>{"<Link>"}</code> navigation)
subscribes as soon as it renders, picks up the toasts already showing, and unsubscribes when
it unmounts.
</p>
<p>
Toasts only exist in the browser. Server-side rendering always outputs an empty toaster.
Expand All @@ -89,6 +95,14 @@ export default component$(() => {
<ul>
<li>Off by default, for parity with sonner.</li>
<li>No-op in browsers without the Popover API — it falls back to normal stacking.</li>
<li>
Each Toaster opens only while it has toasts of its own, so several can use{" "}
<code>topLayer</code>.
</li>
<li>
The browser stacks the top layer in opening order: if a modal opens while toasts are
showing, the Toaster's next toast brings it back above the modal.
</li>
<li>
With the headless entry, add the{" "}
<Link href="/docs/v2/styling/#headless-top-layer">popover reset</Link> yourself.
Expand All @@ -100,8 +114,9 @@ export default component$(() => {

<H2 id="use-sonner">useSonner()</H2>
<p>
A reactive list of the active toasts, for building your own renderer, a badge, or a log. It
subscribes when the component becomes visible.
A reactive list of the active toasts, for building your own renderer, a badge, or a log.
Like the Toaster, it subscribes once the page boots (or as soon as it renders in the
browser) and unsubscribes when the component unmounts.
</p>
<CodeBlock code={useSonnerCode} />
<p>
Expand Down Expand Up @@ -153,44 +168,14 @@ export default component$(() => {

<H2 id="known-issues">Known issues</H2>
<p>
Found in 2.0.0-beta.1. Each has a workaround; follow the{" "}
<Link href="/docs/changelog/">changelog</Link> for fixes.
The issues found in 2.0.0-beta.1 are fixed in 2.0.0-beta.2 — see the{" "}
<Link href="/docs/changelog/">changelog</Link>. One remains, in development only:
</p>
<Callout type="warning" title="A Toaster first rendered on the client shows no toasts">
<p>
The subscription relies on <code>qinit</code>, which fires once when the page boots. A
Toaster that mounts later — behind a condition, or on a page reached through{" "}
<code>{"<Link>"}</code> — misses it. Render the Toaster in the root layout.
</p>
</Callout>
<Callout type="warning" title="useSonner() in a component first rendered on the client">
<p>
Same cause: <code>useSonner()</code> subscribes on <code>qvisible</code>, which a
component mounted after boot (e.g. on a page reached through <code>{"<Link>"}</code>)
doesn't receive, so its list stays empty until a full page load.
</p>
</Callout>
<Callout type="warning" title="topLayer and modals opened while toasts are showing">
<p>
The browser stacks top-layer elements in the order they open, so a Toaster whose popover
is already open when a <code>{"<dialog>"}</code> opens stays beneath it and toasts fired
from the dialog are hidden. In 2.0.0-beta.1 a <code>topLayer</code> Toaster also opens its
popover for toasts meant for other Toasters and, since it never renders them, never closes
it again. Use <code>topLayer</code> only with a single Toaster, and open modals while no
toasts are showing.
</p>
</Callout>
<Callout type="note" title={'Switching away from theme="system"'}>
<p>
A Toaster that started with <code>theme="system"</code> keeps listening to OS changes
after its theme signal moves to <code>light</code>/<code>dark</code> (inherited from
sonner). If you switch themes at runtime, start from an explicit theme.
</p>
</Callout>
<Callout type="note" title="Some type unions aren't exported">
<Callout type="note" title="Two toasts back to back on the dev server">
<p>
<code>Position</code>, <code>Theme</code> and <code>Direction</code> must be derived from{" "}
<code>ToasterProps</code> for now — see <a href="#types">TypeScript</a>.
With Qwik 2.0.0-beta.37's dev server, a plain <code>toast()</code> followed right away by
a typed one (<code>toast.success()</code>…), before the first has rendered, can stall the
Toaster until the page reloads. Production builds aren't affected.
</p>
</Callout>
</>
Expand Down
18 changes: 3 additions & 15 deletions website/src/routes/docs/v2/examples/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,7 @@ const DialogDemo = component$(() => {

return (
<>
<button
class="button"
onClick$={() => {
// Workaround for 2.0.0-beta.1 (see Advanced → Known issues): a
// topLayer Toaster also opens its popover for other Toasters' toasts
// and never closes it, which would leave it beneath the modal.
// Closing it lets the next toast re-open it above the dialog.
document
.querySelectorAll<HTMLElement>("[data-sonner-toaster-popover]:popover-open")
.forEach((el) => el.hidePopover());
dialog.value?.showModal();
}}
>
<button class="button" onClick$={() => dialog.value?.showModal()}>
Open dialog
</button>
<dialog ref={dialog} class={styles.dialog}>
Expand Down Expand Up @@ -331,7 +319,7 @@ export default component$(() => {
<code>{"<dialog>.showModal()"}</code> lives in the browser's top layer, above any z-index. A
Toaster with <code>topLayer</code> joins it there.
</p>
<Demo hint="The demo closes the top-layer container before opening the dialog — a workaround for a known issue in 2.0.0-beta.1.">
<Demo>
<DialogDemo />
</Demo>
<CodeBlock code={dialogCode} />
Expand Down Expand Up @@ -362,7 +350,7 @@ toast.info("Maintenance tonight", { toasterId: "announcements" });`}
/>

<H2 id="counter">Live toast counter</H2>
<Demo hint="In 2.0.0-beta.1 the counter only subscribes after a full page load — reload if you navigated here (see known issues).">
<Demo>
<ToastCounter />
<button class="button" onClick$={() => toast("Another one")}>
Add a toast
Expand Down
8 changes: 0 additions & 8 deletions website/src/routes/docs/v2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ export default component$(() => {
</p>
<CodeBlock title="src/routes/layout.tsx" code={layoutCode} />
<CodeBlock title="src/routes/index.tsx" code={pageCode} />
<Callout type="warning" title="Keep the Toaster in a server-rendered layout">
<p>
In 2.0.0-beta.1 a <code>Toaster</code> that is first rendered on the client — behind a
condition, or inside a page reached through <code>{"<Link>"}</code> navigation — never
subscribes to the toast store, so its toasts don't show. Rendering it in the root layout
avoids this: it's server-rendered on first load and survives navigation.
</p>
</Callout>

<H2 id="entry-points">Styled or headless</H2>
<p>
Expand Down
2 changes: 1 addition & 1 deletion website/src/routes/docs/v2/migration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default component$(() => {
<code>1 dependency (DOMPurify)</code>
<code>0 dependencies</code>
<code>sonner 1.x behaviour</code>
<code>sonner 2.0.7 behaviour</code>
<code>sonner 2.0.8 behaviour</code>
</div>

<H2 id="steps">Steps</H2>
Expand Down
7 changes: 5 additions & 2 deletions website/src/routes/docs/v2/options/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ const OPTION_ROWS: PropRow[] = [
{
name: "important",
type: "boolean",
deprecated: true,
description:
"Accepted for parity with sonner's types; it currently has no effect (sonner 2 announces every toast through the region's polite live region).",
'No effect. In qwik-sonner 1.x it announced the toast with `aria-live="assertive"`; sonner 2 dropped it, and every toast is announced through the Toaster\'s polite live region.',
},
];

Expand All @@ -108,7 +109,9 @@ const ACTION_ROWS: PropRow[] = [
{
name: "actionButtonStyle",
type: "CSSProperties",
description: "Typed for parity; style buttons through the toast's `actionButtonStyle`.",
deprecated: true,
description:
"No effect, as in sonner. Style the buttons with the toast's `actionButtonStyle` / `cancelButtonStyle` or the Toaster's `toastOptions`.",
},
];

Expand Down
3 changes: 2 additions & 1 deletion website/src/routes/docs/v2/styling/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const CLASS_ROWS: PropRow[] = [
{
name: "default",
type: "ClassList",
description: "Added to every toast `<li>`, whatever its type (same as sonner).",
description:
"Added to the toast `<li>` when it has no type: `toast()`, `toast.message()` and `toast.custom()` (same as sonner).",
},
];

Expand Down
4 changes: 2 additions & 2 deletions website/src/routes/docs/v2/toast/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ toast.promise(promise, data) // loading → success / error
toast.custom((id) => jsx, options?)
toast.dismiss(id?) // one toast, or all of them
toast.getToasts() // active toasts
toast.getHistory() // everything created so far`;
toast.getHistory() // created so far (up to 100)`;

const typesCode = `toast("Event has been created");

Expand Down Expand Up @@ -97,7 +97,7 @@ toast.dismiss(id); // remove one toast
toast.dismiss(); // remove every toast`;

const stateCode = `toast.getToasts(); // toasts currently on screen (not dismissed)
toast.getHistory(); // every toast created so far, including dismissed ones`;
toast.getHistory(); // toasts created so far, dismissed ones included (up to 100)`;

const PROMISE_ROWS: PropRow[] = [
{
Expand Down
Loading