Skip to content

Troubleshooting for Svelte

Markdown
Loading…

Common CookieYes setup problems, like a banner that never shows or scripts loading before consent, and the one line to check for each.

Most problems here are a setup detail, and several show no error at all. Find what you see in the table; each row is one line to check.

Find your symptom

What you seeCauseFix
The banner never appearsYou already chose in this browser, or closed it in this page viewDelete the cookieyes-consent cookie and reload, see Reset and re-test
The banner never appears, no error anywhereNo page renders the component that holds <CookieBanner />See Installation → Common mistakes
A component or hook throws could not find CookieYesIt is not inside <CookieYesProvider>, or a hook was called outside a component's initialisation, such as in an event handlerRender it inside the provider, and call hooks at the top of a component's <script>, see Console messages
The banner is unstyled textThe stylesheet import is missingKeep import "@cookieyes/svelte/styles.css" in src/main.ts
The preferences dialog is unstyled, the banner is fineOnly critical.css is loadedLoad styles.css too, see Critical CSS
Do Not Sell does nothing<CookieOptOut /> is not renderedRender it next to the banner
Customise or your own "Cookie settings" link does nothing<CookiePreferences /> is not renderedRender it next to the banner
A tracker loads when a switch is flipped, before SaveYou read the live valuesUse useConsentCategory() or committedCategories, see useConsent
A value from a hook never updatesYou destructured the object a hook returned, which reads each field onceRead the fields in the template or a $derived, see useConsent
A custom category is missingYour categories list was rejected; the console says whySee Configuration → Consent categories
The banner is in English although you set a languageThe language is not in i18n.messagesImport the catalogue, see Translations
The recall button is an unstyled circleclass replaced its default classAdd cy-widget to your class
The banner flashes and vanishes for returning visitorsThe server did not know their choicePass initialConsent to CookieYesProvider, see Runtime and server helpers
Svelte warns about a hydration mismatch in the bannerThe server and the browser gave CookieYesProvider different region, regulation or initialConsentPass the same values on the server and in the browser
Your CSS rule does nothingYour stylesheet loads before the SDK's, or a theme value sets the same property inlineImport yours after styles.css; see Custom CSS
A rule in a component's <style> block never reaches the bannerSvelte scopes that block to the component's own elementsUse a global stylesheet with data-cy-part selectors, or :global(...)
Tracking continues after the visitor withdraws consentA script that already ran cannot be unloadedRender ReloadNotice
Every returning visitor is asked againYou changed a category id, or which one is requiredExpected. See CookiePreferences
A checkbox in your own dialog turns on but never offonchange={toggle} passes the eventUse onchange={(e) => toggle(e.currentTarget.checked)}
Focus jumps to the top of the page when a dialog closesThe dialog was opened through the runtime directlyOpen it with useConsentActions().showPreferences()
The banner is not where you put it in your codeIt moves to the top of <body> so keyboard users reach it firstExpected. See Accessibility

Console messages

[cookieyes] useConsent() could not find CookieYes. Wrap the app in <CookieYesProvider config={...}> and call hooks while a component initialises. Thrown by every hook and component when no <CookieYesProvider> is above it; the name at the start is the one that threw, such as useConsent() or <CookieBanner>. It is also thrown when a hook runs after the component initialised, for example inside an event handler. Render the component inside the provider, and call hooks at the top of its <script>.

[cookieyes] getCookieYes() found no runtime. Mount <CookieYesProvider config={...}> first. Thrown by getCookieYes() when it runs before the provider. Every hook throws the message above instead. See Runtime and server helpers.

[cookieyes] <CookieYesProvider> ran again with a different config. Replacing the previous runtime. The provider rendered a second time in the browser with another config object. Import one module-level config, as in src/lib/cookieyes.ts, instead of writing it inline.

[cookieyes] OptOut.* sub-components must be rendered inside <OptOut.Root>. An OptOut.* piece sits outside OptOut.Root. Move it inside. Preferences.* pieces give the same message about <Preferences.Root>.

[cookieyes] Invalid categories config (...). Falling back to the default five Your categories list broke a rule; the reason is in the brackets. The built-in five are shown until you fix it.

[cookieyes] `regulation` is set manually, so region detection is ignored. You set both regulation and region. Keep one.

[cookieyes] no translations for language "..."; staying on "..." You switched to a language that is not in i18n.messages and has no loadLanguage. Add the catalogue.

[cookieyes] blocked POST https://... (rule "...", category: ...) Not an error: network blocking stopped a request, as configured. Set logBlockedRequests: false to silence it.

Reset and re-test

Make the banner come back. Delete the cookieyes-consent cookie in DevTools → Application → Cookies, or run this in the console and reload:

Console
document.cookie = "cookieyes-consent=; max-age=0; path=/";

Or call useConsentActions().reset() from a button you show only in development.

See the banner from any location. Set regulation: "GDPR" while developing instead of relying on region detection.

Check which version a page runs. In the console:

Console
window.CookieYesSDK; // { version: "x.y.z" }

The SDK sets this in the browser on every page where it starts, whether or not the banner shows, so public technology scanners can recognise the SDK. It holds the @cookieyes/core version and nothing else.

Trigger the reload notice. Accept the category, reload so the tool starts, then withdraw it. Rejecting on a first visit never shows it, because nothing was running.

Next steps

  • Installation: the three-step setup, with its own common mistakes
  • Configuration: every option of the config you pass to <CookieYesProvider>

On this page