Skip to content
ComponentsReloadNotice

ReloadNotice for SvelteKit

Markdown
Loading…

Ask the visitor to reload when a withdrawn tool cannot be stopped otherwise.

What it does

Some third-party tools cannot be switched off once they are running. When a visitor withdraws consent for such a tool, this notice appears with a Reload and a Dismiss button. It never reloads on its own; the visitor decides.

You need it only if you register a tool as "needs a reload" (below). The ready-made integrations stop their tools themselves. Hotjar is the exception; its page shows how to register it.

Add it

<CookieYesRoot> does not render it. Give <CookieYesRoot> a ui snippet and add it there; the snippet replaces the stock banner, dialogs and recall button, so keep the others:

src/routes/+layout.svelte
<script lang="ts">
  import {
    CookieBanner,
    CookiePreferences,
    CookieYesRoot,
    RecallButton,
    ReloadNotice,
  } from "@cookieyes/sveltekit";
  import { config } from "../lib/cookieyes";

  let { data, children } = $props();
</script>

<CookieYesRoot {config} state={data.consent}>
  {#snippet ui()}
    <CookieBanner />
    <CookiePreferences />
    <RecallButton />
    <ReloadNotice />
  {/snippet}
  {@render children()}
</CookieYesRoot>

Then mark the tool that cannot be stopped, once, before <CookieYesRoot> starts the runtime. The SDK reads this list once, when it starts, so a line placed after it misses returning visitors. Module scope in src/lib/cookieyes.ts is early enough, since the root layout imports it:

src/lib/cookieyes.ts
import { type CookieYesConfig, registerStopHandler } from "@cookieyes/sveltekit";

registerStopHandler({ id: "legacy-pixel", category: "advertisement", needsReload: true });

export const config: CookieYesConfig = { mode: "cookie-only", regulation: "GDPR" };

It appears only when a reload is genuinely needed

The notice shows only when a category that was granted is turned off and a tool marked needsReload was running under it. A first-time rejection shows nothing: nothing was running. Once dismissed, it stays away until a new withdrawal needs a reload.

Change what it shows

It has no props. The text comes from the reloadNotice.message, reloadNotice.reloadButton and reloadNotice.dismissButton keys in i18n; see Translations. For your own markup, read the same state with useReloadNotice(), which returns required and dismiss.

Restyle it

Target [data-cy-part="reload-notice"], [data-cy-part="reload-message"], [data-cy-part="reload"] and [data-cy-part="reload-dismiss"] in your CSS.

Common mistakes

I rejected a category and the notice did not appear. Expected, unless that category was granted before and a needsReload tool was running. Accept first, then reject.

The notice appears for a tool I did not mark. That tool's own stop function threw an error, so CookieYes fell back to asking for a reload.

Next steps

On this page