Theme key 'theme', storage keys in the cookie scanner, type in the cookie list

- Theme choice in localStorage under 'theme' (next-themes' key and values)
  instead of 'ipal-theme'. ThemeScript moves an old choice before the first
  paint and removes the old key; useTheme / ThemeSwitcher do the same
  without the script. ipalKit({ theme: { storageKey } }) sets an own key,
  which reaches ThemeScript through getSiteShell().theme and <html
  data-theme-storage>.
- The cookie scanner declares the theme key (Theme choice: local storage,
  necessary, until changed or site data is cleared) when the theme switch
  is on, so Scan cookies finds it without a crawl.
- Cookies -> Cookie list rows get a Type (cookie / local storage / session
  storage, default cookie, shared by every language), filled by scan, review
  and approval. The detailed settings window and <CookieTable> show it with
  English and Polish defaults; the approval page marks storage entries.
- Migration: adds cookie_settings_cookies.storage (DEFAULT 'cookie') and
  cookie_settings_locales.detail_labels_storage, nothing else.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-29 11:29:56 +01:00
co-authored by Claude Opus 5.5
parent 6998b44431
commit b5368cdc61
35 changed files with 522 additions and 78 deletions
+33
View File
@@ -8,6 +8,39 @@ versions at once, go through every "Requires project changes" section in order,
version you have. A new release = a new section at the top; we remove the oldest ones only
once there are more than 20.
## Unreleased
The theme choice moves to the standard `theme` key, the cookie scanner declares the plugin's own browser-storage
key, and the cookie list tells cookies from browser storage.
### Changed
- **Theme key** `ipal-theme` → **`theme`** (`THEME_STORAGE_KEY`), the key and `light` / `dark` values next-themes uses.
Visitors keep their choice: `<ThemeScript>` moves an old `ipal-theme` value to the new key before the first paint
(no flash) and removes the old key; `useTheme` / `<ThemeSwitcher>` do the same on pages without the script
(`migrateThemeStorage`, `LEGACY_THEME_STORAGE_KEY`). A project that also runs next-themes now shares the key —
set `ipalKit({ theme: { storageKey } })` to keep them apart.
### New
- **`theme.storageKey`** option (`ThemeOptions`): `getSiteShell().theme.storageKey` → `<ThemeScript>` →
`<html data-theme-storage>` (`THEME_STORAGE_ATTRIBUTE`) → `useTheme` / `<ThemeSwitcher>`; both also take `storageKey`.
- **Cookie scanner declares browser storage**: the theme choice (*Theme choice*, on when Site settings → Theme →
*Allow theme toggle* is on) as **necessary**, local storage, "until changed or site data is cleared" — so
**Scan cookies** finds it without a crawl.
- **Type in the cookie list**: *Cookies → Cookie list* rows have **Type** (`storage`: cookie · local storage ·
session storage, default cookie, shared by every language), filled by scan, review and approval. The detailed
settings window shows it for storage entries (heading: *Settings window → Cookie list headings → Type*);
`<CookieTable>` adds a **Type** column when the list has a storage entry (`storageColumn`, `storageTypes`,
`COOKIE_STORAGE_LABELS`). `CookieTableRow.storage`, `texts.details.storage` / `.storageTypes`, type `ConsentStorage`.
The approval page marks storage entries.
### What projects must update
1. **Migration (Postgres / SQLite):** `pnpm payload migrate:create cookie-storage-type` — it only adds
`cookie_settings_cookies.storage` (enum, `DEFAULT 'cookie'`) and `cookie_settings_locales.detail_labels_storage`.
Existing rows become *Cookie*: set the type of storage rows by hand. MongoDB: nothing to do.
2. A project that reads `localStorage.getItem('ipal-theme')` itself: use `THEME_STORAGE_KEY` (or `documentThemeStorageKey()`).
3. Cookie list: after the next **Scan cookies**, approve the new *theme* entry; remove an old *ipal-theme* row from
*Cookies → Cookie list* once the site runs this version.
## 1.14.4
Cookie texts in every language without retyping them, and one **Cookies** entry in the admin instead of three.
+2
View File
@@ -983,6 +983,8 @@ add missing hosts with flags / `extra`; (3) change `mode` to `'enforce'` in both
| Staff features without `access` (no roles field): every logged-in account passes (`userMeetsRole`) | add `access` (roles decide) | `globalOverrides`, `forms.formSubmissionOverrides`, `consentLog.collectionOverrides`, `stats.collectionOverrides` |
| Cookie check (`crawl`): start editor+ or the token, results token-only for the running job, latest result only, dashboard warning on, e-mail off until recipients are set | omit `crawl`; `crawl.dashboard: false` | `crawl.serviceUrl` / `token` / `siteUrl` / `maxPages` / `acceptSelector` / `consentMode` / `trackerHosts` / `globalOverride`; *Cookie check → Warning e-mails to*; building blocks `ingestCrawlResult`, `findCrawlViolations`, `parseCrawlResult` |
| Cookie admin: one *Cookies* entry — review list and site check as tabs, their own entries out of the navigation (pages and API kept) | `cookieScanner.adminLayout: 'separate'` | `addCookieScannerTabs`, `CookieReviewTab`, `CookieSiteCheckTab`; `collectionOverrides` / `crawl.globalOverride` win |
| Theme choice in localStorage under `theme` (next-themes' key); old `ipal-theme` moved before paint; declared to the cookie scanner as necessary local storage | — | `ipalKit({ theme: { storageKey } })`; `<ThemeSwitcher storageKey>` / `useTheme({ storageKey })` |
| Cookie list entries have a **Type** (cookie / local / session storage), filled by the scanner; `<CookieTable>` shows it when needed | `<CookieTable storageColumn={false}>` | `storageColumn`, `storageTypes`, Cookies → Settings window → Cookie list headings → Type |
| Text written in one language fills the empty languages (cookie list, cookie review), never over a language's own text | `fillEmptyLocales: false` | `fillEmptyLocales: { 'cookie-settings': [...], 'cookie-review': [...] }`; `buildFillEmptyLocalesGlobalHook` / `…CollectionHook` for your own globals and collections |
| Cookie approval: one summary + **Approve and add** (editor+), unknown cookies approved as `marketing` + "Needs description", dashboard reminder while cookies wait; nothing reaches the cookie banner before approval | `cookieScanner.approval: false` (per-entry review) | `approval.unknownCategory`, `approval.dashboard: false`; building blocks `approveCookies`, `loadCookieApproval`, `countPendingCookies`, `flagGoneEntries`, `sameCookie` |
| Cookie review: scan + review editor+, delete admin; Open Cookie Database "Functional" → `functional` | omit `cookieScanner` | `cookieScanner.access`, `collectionOverrides`, `databaseCategories`, `integrations`, `declarations`, `labels`, `syncAccepted: false`; building blocks `runCookieScan`, `collectCookieFindings`, `applyCookieFindings` |
@@ -130,4 +130,4 @@ unknown names to the panel scan above instead of step 2):
table" block on the policy page is a good place — then the editor decides where it appears.
Lifetime: Chrome caps every cookie at max. 400 days (13 months) — the scan shows what
really stays in the browser. localStorage keys (e.g. `ipal-theme` — the chosen theme) are listed separately.
really stays in the browser. localStorage keys (e.g. `theme` — the chosen theme) are listed separately; in the panel they are entries of type *Local storage* (the scanner declares the theme key itself when the theme switch is on). Check that every storage row in *Cookies → Cookie list* has the right **Type** — rows from before the type existed are *Cookie*.
@@ -76,6 +76,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip
| `cookieScanner.crawl.serviceUrl` / `.token` / `.siteUrl` / `.maxPages` / `.acceptSelector` | env URL / env token / `serverURL` → `NEXT_PUBLIC_SERVER_URL` / `20` / `[data-ipal="accept"]` | where the service is, the shared secret, the public origin crawled and called back, pages from the sitemap (max 100), the banner's accept button | options win over env |
| `cookieScanner.crawl.consentMode` / `.trackerHosts` / `.dashboard` / `.globalOverride` | `'advanced'` / `DEFAULT_TRACKER_HOSTS` / `true` / none | `'basic'` also flags Google tag requests before consent; hosts counted as trackers; dashboard warning; changes the `cookie-crawl` global like `globalOverrides` | `(defaults) => [...defaults, 'chat.example']`; `dashboard: false` |
| `cookieScanner.database` / `.databaseCategories` / `.syncAccepted` | `true` / Functional+Personalization → functional, Security+Necessary → necessary / `true` | Open Cookie Database lookup on or off; category map; accepting writes to Cookie banner | `database: false`; `{ Functional: 'necessary' }`; `syncAccepted: false` |
| `theme.storageKey` | `'theme'` | localStorage key of the visitor's light / dark choice (next-themes uses the same key — set your own to keep them apart); via `config.custom.ipal.themeStorageKey` → `getSiteShell().theme.storageKey` → `ThemeScript` → `<html data-theme-storage>` → `useTheme` / `ThemeSwitcher`. An old `ipal-theme` choice moves before the first paint | `{ storageKey: 'acme-theme' }`; check: DevTools → Application → Local storage shows the key after a switch |
| `stats` | off | `stats-visits` collection, `POST /api/ipal/hit`, `/<admin>/stats` view, nav link, dashboard chart | `true` / object |
| `stats.collectionOverrides` | none | changes `stats-visits` like `consentLog.collectionOverrides`; its `access.read` also decides who sees the stats view and dashboard chart | object or function |
| `stats.retentionDays` / `timeZone` / `dashboard` | 90 / `'Europe/Warsaw'` / `true` | retention, day boundary, `StatsWidget` | `dashboard: false` hides the chart |
@@ -113,7 +113,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT
| `CookieBanner` | `@intecion/ipal-kit/client` | Consent banner + category settings: `settings: 'inline' \| 'modal' \| 'detailed'`, `controls`, `equalChoice` (recommended `true`), `order`, `settingsActions`, `icon`, `classNames`; colours from `--ipal-*` CSS vars. Do not write your own banner. |
| `CookieButton` | `@intecion/ipal-kit/client` | Floating button that reopens the cookie settings (withdrawing consent); hidden while the banner is visible. Prop `className`. |
| `ConsentScript` | `@intecion/ipal-kit/client` | Loads an external script (`src` or `code`) only after consent for `category` — for vendors without Consent Mode (chat, Plausible etc.). Inside `ConsentProvider`. |
| `CookieTable` | `@intecion/ipal-kit/rsc` | Server Component: cookie table for the cookie policy page — `{ rows, labels, categories?, caption?, classNames? }`; `rows` from `getCookieTable()`. |
| `CookieTable` | `@intecion/ipal-kit/rsc` | Server Component: cookie table for the cookie policy page — `{ rows, labels?, locale?, categories?, caption?, classNames?, storageColumn?, storageTypes? }`; `rows` from `getCookieTable()`; a **Type** column when a row is local / session storage (`storageColumn: 'auto' \| boolean`). |
| `useConsent(options?)` | `@intecion/ipal-kit/client` | Low-level consent state hook → `{ state, decided, consentId, acceptAll, rejectAll, savePreferences, reopen }`. Usually use `ConsentProvider` + `useConsentContext` (the provider calls it itself). |
| `useConsentContext()` | `@intecion/ipal-kit/client` | Hook: the `useConsent` value + `texts` from `ConsentProvider` — for your own consent-dependent UI (e.g. `state.marketing`). Throws outside the provider. |
| `getConsentTexts({ payload, config, locale?, privacyPolicy?, settingsSlug? })` | `@intecion/ipal-kit` | Server: banner texts from the CookieSettings global (EN fallback per field) + privacy policy link from the system pages → `Promise<ConsentTexts>`; pass to `ConsentProvider texts`. |
@@ -134,9 +134,9 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT
| `buildConsentLogCollection()` | `@intecion/ipal-kit` | Consent log collection (id, choices, version, time — no IP/personal data; proof of consent under GDPR Art. 7(1)). The plugin wires it itself with `consentLog: true` — do not call. |
| `buildConsentLogEndpoint({ retentionDays? })` | `@intecion/ipal-kit` | `POST /api/ipal/consent` endpoint that saves decisions and deletes records older than `retentionDays` (default 1095). The plugin wires it itself with `consentLog` — do not call. |
**Built-in texts:** `CONSENT_FALLBACK`, `CONSENT_FALLBACK_PL`, `consentFallback(locale)` (banner defaults by page language), `CONSENT_CATEGORY_LABELS` / `consentCategoryOptions()` (category names `{ en, pl }`), `COOKIE_TABLE_LABELS` (`/rsc`, `<CookieTable locale>` defaults).
**Built-in texts:** `CONSENT_FALLBACK`, `CONSENT_FALLBACK_PL`, `consentFallback(locale)` (banner defaults by page language), `CONSENT_CATEGORY_LABELS` / `consentCategoryOptions()` (category names `{ en, pl }`), `COOKIE_TABLE_LABELS` (`/rsc`, `<CookieTable locale>` defaults), `COOKIE_STORAGE_LABELS` (`/rsc`, type names per language).
**Types:** `ConsentCategory`, `ConsentState`, `ConsentTexts`, `CookieTableRow`, `ConsentLogOptions` (root) — categories, consent state, banner texts, cookie table row, log options; `CookieBannerAction`, `CookieSettingsAction`, `CookieBannerClassNames` (`/client`) — `CookieBanner` buttons and classes; `CookieTableLabels` (`/rsc`) — `CookieTable` column headers.
**Types:** `ConsentCategory`, `ConsentState`, `ConsentStorage` (`'cookie' \| 'localStorage' \| 'sessionStorage'`), `ConsentTexts`, `CookieTableRow`, `ConsentLogOptions` (root) — categories, consent state, banner texts, cookie table row, log options; `CookieBannerAction`, `CookieSettingsAction`, `CookieBannerClassNames` (`/client`) — `CookieBanner` buttons and classes; `CookieTableLabels` (`/rsc`) — `CookieTable` column headers.
## Cookie scanner (`consent/scanner`) — details: `node_modules/@intecion/ipal-kit/docs/cookie-scanner.md`
@@ -682,19 +682,23 @@ Most routes and metadata are already ready in `createContentHelpers` (`generateP
| Export | Import from | What it does / when |
|---|---|---|
| `ThemeScript({ allowToggle?, defaultTheme? })` | `@intecion/ipal-kit/rsc` | Inline script that sets `data-theme` on `<html>` before paint (no flash). First in `<body>` or `theme` in `<SiteProviders>`; `<html suppressHydrationWarning>`. |
| `ThemeSwitcher({ label?, classNames?, renderIcon? })` | `@intecion/ipal-kit/client` | Unstyled switcher (`<button role="switch">`, light/dark icons); style the active icon in CSS (`[data-theme=dark]`). |
| `useTheme()` | `@intecion/ipal-kit/client` | Hook `{ theme, setTheme, toggle }`; `theme` = null on the server — do not style from it. |
| `applyTheme(theme, { persist?, transitionMs? })` | `@intecion/ipal-kit/client` | Sets the theme on `<html>` and remembers it in localStorage. |
| `ThemeSwitcher({ label?, classNames?, renderIcon?, storageKey? })` | `@intecion/ipal-kit/client` | Unstyled switcher (`<button role="switch">`, light/dark icons); style the active icon in CSS (`[data-theme=dark]`). |
| `useTheme({ storageKey? })` | `@intecion/ipal-kit/client` | Hook `{ theme, setTheme, toggle }`; `theme` = null on the server — do not style from it. Key: the one on `<html data-theme-storage>`, else `theme`. |
| `applyTheme(theme, { persist?, storageKey?, transitionMs? })` | `@intecion/ipal-kit/client` | Sets the theme on `<html>` and remembers it in localStorage. |
| `documentThemeStorageKey()` | `@intecion/ipal-kit/client` | The key the page uses: `<html data-theme-storage>` (set by `ThemeScript` for a custom key), else `'theme'`. |
| `migrateThemeStorage(key?)` | `@intecion/ipal-kit/client` | Moves an old `ipal-theme` choice to `key` when `key` is empty, removes `ipal-theme`; never throws. `ThemeScript` does it before the first paint. |
| `readDocumentTheme()` | `@intecion/ipal-kit/client` | Current theme from `<html>` or null. |
| `themeConfigFrom(settings)` | `@intecion/ipal-kit` | Theme options from the SiteSettings document (what `getSiteShell(locale).theme` holds). |
| `themeScript({ allowToggle, defaultTheme })` | `@intecion/ipal-kit` | The script content that `ThemeScript` renders — when you insert it yourself. |
| `themeConfigFrom(settings, storageKey?)` | `@intecion/ipal-kit` | Theme options from the SiteSettings document (what `getSiteShell(locale).theme` holds). |
| `themeScript({ allowToggle, defaultTheme, storageKey? })` | `@intecion/ipal-kit` | The script content that `ThemeScript` renders — when you insert it yourself. |
| `isTheme(value)` | `@intecion/ipal-kit`, `@intecion/ipal-kit/client` | Type guard `'light' \| 'dark'`. |
| `isThemeSetting(value)` | `@intecion/ipal-kit` | Type guard `'system' \| 'light' \| 'dark'`. |
| `THEME_ATTRIBUTE` | `@intecion/ipal-kit`, `@intecion/ipal-kit/client` | `'data-theme'` — attribute on `<html>` (Tailwind `dark` variant). |
| `THEME_STORAGE_KEY` | `@intecion/ipal-kit`, `@intecion/ipal-kit/client` | `'ipal-theme'` — localStorage key with the visitor's choice. |
| `THEME_STORAGE_KEY` | `@intecion/ipal-kit`, `@intecion/ipal-kit/client` | `'theme'` — default localStorage key with the visitor's choice (the next-themes key; `ipalKit({ theme: { storageKey } })` changes it). |
| `LEGACY_THEME_STORAGE_KEY` | `@intecion/ipal-kit`, `@intecion/ipal-kit/client` | `'ipal-theme'` — the key before; a choice under it is moved once. |
| `THEME_STORAGE_ATTRIBUTE` | `@intecion/ipal-kit`, `@intecion/ipal-kit/client` | `'data-theme-storage'` — on `<html>` when the key is not the default. |
| `THEME_SWITCHING_ATTRIBUTE` | `@intecion/ipal-kit/client` | `'data-theme-switching'` — briefly on `<html>` while switching (for the colour transition). |
**Types:** `Theme`, `ThemeSetting`, `ThemeConfig` (root, `/client`) — theme, setting from the panel and theme options; `ThemeScriptProps` (`/rsc`), `ThemeSwitcherProps`, `ThemeSwitcherClassNames` (`/client`) — component props.
**Types:** `ThemeOptions` (root, `ipalKit({ theme })`), `Theme`, `ThemeSetting`, `ThemeConfig` (root, `/client`) — theme, setting from the panel and theme options; `ThemeScriptProps` (`/rsc`), `ThemeSwitcherProps`, `ThemeSwitcherClassNames` (`/client`) — component props.
## Turnstile (`turnstile`) — details: `node_modules/@intecion/ipal-kit/docs/turnstile.md`
+17
View File
@@ -332,6 +332,23 @@ independent consent state).
> The consent mechanism for the locale is also described from the i18n side:
> [i18n.md](./i18n.md#locale-cookie-and-consent-gdpr).
## Cookies and browser storage in one list (type)
*Cookies → Cookie list* holds cookies **and** keys the site keeps in the browser's local or session
storage (the theme choice, a chat widget's state). Each row has a **Type** (`storage`: `cookie` ·
`localStorage` · `sessionStorage`, default `cookie`, shared by every language). The cookie scanner fills it.
| Where | What visitors see |
|---|---|
| `<CookieTable>` (`/rsc`) | a **Type** column when the list has an entry that is not a cookie (`storageColumn: 'auto'`, the default; `true` / `false` to force it). Column heading `labels.storage`, type names `storageTypes` — defaults per `locale`: en *Type* · *Cookie* / *Local storage* / *Session storage*, pl `Rodzaj` · `Plik cookie` / `Pamięć lokalna` / `Pamięć sesji` (`COOKIE_STORAGE_LABELS`) |
| Detailed settings window | a **Type** line under entries that are not cookies: label from *Settings window → Cookie list headings → Type* (empty = default per language), type names from `texts.details.storageTypes` |
| `getCookieTable` / `texts.cookies` | every row has `storage` (`ConsentStorage`); `texts.details.storage` / `.storageTypes` |
**Migration (Postgres / SQLite):** two added columns, nothing dropped — `cookie_settings_cookies.storage`
(enum, `DEFAULT 'cookie'`, so existing rows become *Cookie*) and `cookie_settings_locales.detail_labels_storage`.
Run `pnpm payload migrate:create cookie-storage-type` and commit it. Change the type of existing storage rows
by hand (a scan fills it only for new rows).
## Every language filled (`fillEmptyLocales`)
The cookie list's **Purpose** and **Duration** are per language. Text an editor writes in one language
+11 -3
View File
@@ -109,6 +109,7 @@ integrations switched on in this project are part of a scan:
| Integration | On when | Cookies |
|---|---|---|
| Cookie banner | always | `cookie-consent` (necessary, 6 months) |
| Theme choice | Site settings → Theme → *Allow theme toggle* on | `theme` (or `theme.storageKey`) in **local storage** — necessary (a preference the visitor chose), until changed or site data is cleared, may be set before consent |
| Admin panel login | always | `payload-token` (`<cookiePrefix>-token`, necessary, editors only) |
| Language choice | more than one locale in `i18n` | `NEXT_LOCALE` (functional, session) |
| Built-in statistics | `stats` option | `ipal_vid` (analytics, 6 months) |
@@ -120,9 +121,16 @@ integrations switched on in this project are part of a scan:
| TikTok Pixel | Pixel ID | `_ttp`, `_tt_enable_cookie` |
| Cloudflare Turnstile | both Turnstile keys set | `cf_clearance` (necessary; only when pre-clearance is on in Cloudflare) |
An ID that fails its format check counts as off. The theme switcher (`ipal-theme` in localStorage)
and the accessibility widget (`a11y-prefs`) have no plugin option, so they are not declared: add
them with `declarations` when the site uses them.
An ID that fails its format check counts as off. Declarations cover browser storage too
(`storage: 'localStorage' | 'sessionStorage'`): the theme choice is the plugin's only storage key.
The accessibility widget (`a11y-prefs` cookie) has no plugin option the scan could check, so it is not
declared: add it with `declarations` when the site uses the widget.
Every entry keeps its type (cookie, local storage, session storage) from the scan through the review and
approval into *Cookies → Cookie list* (**Type** column; shared by all languages, default *Cookie*). The
banner's detailed window shows the type for entries that are not cookies, and `<CookieTable>` adds a
**Type** column when the list has one ([consent.md](./consent.md)). A row that was already in the list
keeps the type it has; rows from before the type existed are *Cookie* — set storage rows by hand.
## Open Cookie Database
+21 -7
View File
@@ -9,11 +9,23 @@ widget theme that matches the page.
- Pages are ISR/SSG — one HTML for everyone, so the theme does **not** go into the server HTML.
- `<ThemeScript>` (an inline script, the first child of `<body>`) sets `data-theme="light|dark"` and
`color-scheme` on `<html>` before the first paint.
- Order: the visitor's choice from `localStorage` (key `ipal-theme`, only when "Allow theme toggle" is on)
- Order: the visitor's choice from `localStorage` (key `theme`, only when "Allow theme toggle" is on)
→ Site settings → Default theme → with `System`, the device setting (`prefers-color-scheme`).
- `localStorage`, not a cookie: it is an interface preference, it does not track and needs no consent.
- `localStorage`, not a cookie: it is an interface preference the visitor chose themselves, it does not
track and needs no separate consent (CNIL treats such a preference as strictly necessary). The cookie
scanner declares it as **necessary**, local storage — an editor can change that on review.
- A change in one tab carries over to the others (the `storage` event).
## The storage key (`theme`)
| | |
|---|---|
| Default key | `theme`, values `light` / `dark` — the key and values next-themes uses (`THEME_STORAGE_KEY`) |
| Own key | `ipalKit({ theme: { storageKey: 'acme-theme' } })` → `getSiteShell(locale).theme.storageKey` → `<ThemeScript>` uses it and puts it on `<html data-theme-storage>`, so `useTheme` / `<ThemeSwitcher>` use the same key with no extra prop (`<ThemeSwitcher storageKey>` / `useTheme({ storageKey })` to set it by hand) |
| Old key | before this change the key was `ipal-theme` (`LEGACY_THEME_STORAGE_KEY`). When the current key is empty and `ipal-theme` holds `light` / `dark`, `<ThemeScript>` moves it **before the first paint** (no flash) and removes `ipal-theme`; `useTheme` / `<ThemeSwitcher>` do the same on pages without the script (`migrateThemeStorage(key)`). A choice already under the current key wins; the old key is removed anyway |
| next-themes | a project that also runs next-themes shares the key `theme` with it — one choice for both. To keep them apart, give the plugin its own key (`theme.storageKey`) |
| CSP | the inline script runs with the CSP nonce (`<ThemeScript nonce>`, `SiteProviders` passes it); no script hash to update |
## Site settings → Theme
| Field | Meaning |
@@ -22,7 +34,7 @@ widget theme that matches the page.
| `allowThemeToggle` | show the switcher; the visitor's choice is remembered |
| `themeToggleLabel` | the switcher name for screen readers, e.g. "Tryb ciemny" (localized, since 1.11.1) |
`getSiteShell(locale).theme` → `{ defaultTheme, allowToggle, toggleLabel }` (`themeConfigFrom(settings)` from the root entry).
`getSiteShell(locale).theme` → `{ defaultTheme, allowToggle, toggleLabel, storageKey? }` (`themeConfigFrom(settings, storageKey?)` from the root entry; `storageKey` only when it is not the default).
## Wiring
@@ -60,10 +72,12 @@ import { ThemeSwitcher } from '@intecion/ipal-kit/client'
from the attribute on `<html>` (`dark:`), not React state — nothing jumps after hydration.
Hooks for styling: `data-ipal="theme-switch"`, `data-ipal-theme-icon="light|dark"`.
Custom switcher: `useTheme()` → `{ theme, setTheme, toggle }` (`theme` = `null` on the server);
`applyTheme(theme, { persist, transitionMs })`, `readDocumentTheme()`, the constants `THEME_ATTRIBUTE`,
`THEME_STORAGE_KEY`, `THEME_SWITCHING_ATTRIBUTE`, `isTheme` from `/client`. From the root entry also
`isThemeSetting` and `themeScript({ allowToggle, defaultTheme })` (the script text only).
Custom switcher: `useTheme({ storageKey? })` → `{ theme, setTheme, toggle }` (`theme` = `null` on the server);
`applyTheme(theme, { persist, storageKey, transitionMs })`, `readDocumentTheme()`, `documentThemeStorageKey()`,
`migrateThemeStorage(key)`, the constants `THEME_ATTRIBUTE`, `THEME_STORAGE_KEY`, `LEGACY_THEME_STORAGE_KEY`,
`THEME_STORAGE_ATTRIBUTE`, `THEME_SWITCHING_ATTRIBUTE`, `isTheme` from `/client`. From the root entry also
`isThemeSetting` and `themeScript({ allowToggle, defaultTheme, storageKey })` (the script text only), and the
type `ThemeOptions` (`ipalKit({ theme })`).
## CSS (Tailwind 4)