Merge claude/consent-banner-first-paint-154f9f: the cookie banner is part of the first render
Conflicts in the docs only, both sides kept: changelog lines, AGENT.md checklist rows 12 (banner) and 13 (wrapper order), the two iapl-upgrade blocks, PROGRAMISTA rows 76 (client hints) and 77 (banner, renumbered from 76). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -228,6 +228,22 @@ once there are more than 20.
|
||||
upgrade. Run `pnpm exec iapl-skills` and commit in the same change as the version bump.
|
||||
|
||||
### Changed
|
||||
- **The cookie banner is part of the first render** ([consent.md → First paint](./consent.md#first-paint-the-banner-is-part-of-the-first-render-1170)).
|
||||
Until now `<CookieBanner>` rendered nothing until the page had hydrated, so on a first visit its text appeared late
|
||||
and on a text page became the LCP element (reference site, mobile profile, 4x CPU, slow 4G: page painted at 1.0 s,
|
||||
banner and LCP at 2.7 s; now banner and LCP at 1.0 s; CLS unchanged). The banner is now in the server HTML with
|
||||
`hidden`, followed by one small inline script that, before the browser paints, shows it (no decision, an older
|
||||
Policy version, an unreadable cookie) or keeps it hidden (current decision). **An existing site gets this by
|
||||
updating, with no edit; public pages stay static / ISR.** Nothing about consent changes: no tag loads earlier, the
|
||||
Consent Mode default is still pushed first, the cookie, the consent log and withdrawal are as before. A click on a
|
||||
banner button before hydration is carried out once the page is live.
|
||||
**What an existing site may notice:** the page's HTML is about 3 kB larger, 1.2 kB gzipped (the banner's markup and the script; the detailed cookie
|
||||
list is not in it); `[data-ipal="banner"]` exists in the DOM (hidden) for a returning visitor until hydration — a
|
||||
project e2e test that counts the element right after load should assert `toBeHidden()`; with a **nonce CSP** the
|
||||
script needs the nonce — `<SiteProviders nonce>` passes it (without it the banner appears after hydration, as
|
||||
before); with **Tailwind 3** and a `classNames.root` that sets `display`, add
|
||||
`[data-ipal="banner"][hidden] { display: none !important }`. Old behaviour: `<CookieBanner firstPaint={false} />`.
|
||||
`CookieButton` and `useConsent` read the decision through a store (`useSyncExternalStore`) instead of an effect.
|
||||
- **New names beside the old ones** (the old ones are deprecated and go in 2.0):
|
||||
`iapl()` for `ipalKit()`, `IaplOptions`, `iaplEnvRules`, `IaplEnvFeatures`, `iaplT`, `iaplVar`, `IAPL_TOKENS`,
|
||||
`IAPL_BREAKPOINTS`, `IaplTokenName`, `IaplGlobalSlug`; commands `iapl`, `iapl-doctor`, `iapl-skills`, `iapl-tokens`,
|
||||
@@ -260,6 +276,10 @@ once there are more than 20.
|
||||
`AdminClientHintsOptions`. Doctor rule `client-hints` (info): the wrapper is inside `withPayload`, or (with
|
||||
`--url`) the home page still sends `Critical-CH`. The starter and the reference site use the new order; an
|
||||
existing site changes one line ("Requires project changes").
|
||||
- Consent, first paint: `CookieBanner` props `firstPaint` (default `true`) and `nonce`; `ConsentProvider` props `nonce`
|
||||
and `cookieValue`, `SiteProviders` prop `consentCookie` (optional server read of the consent cookie: no banner in the
|
||||
HTML of a visitor who decided, at the price of dynamic pages); `consentBannerScript({ version, cookieName })` from the
|
||||
root for a project's own banner; `useConsent` / `useConsentContext` also return `hydrated` and `serverRead`.
|
||||
- **The Intecion Notifications Webservice (IWSN) as the default e-mail transport** ([email.md](./email.md), AGENT.md §7.2).
|
||||
The admin panel calls it **IWSN**; docs, logs and the doctor use the full name.
|
||||
`mailAdapter()` now picks per send: Graph when the panel says so and `GRAPH_*` is set → SMTP when the panel has a
|
||||
|
||||
+2
-1
@@ -246,7 +246,7 @@ site), **P** = a test in the panel. Full code: PROGRAMISTA.md §2.
|
||||
| 9 | **Media / R2 / speed** | `Media` with `focalPoint`, `normalizeFilenameHook`, `buildOptimizeUploadHook`, `buildMediaPlaceholderHook` + field; **always** `buildR2Storage(['media'], { s3Storage })` + `@payloadcms/storage-s3`; `R2_*` in `.env.example`; `<MediaPreconnect/>`; `images: buildImagesConfig()` and `buildUploadSecurityHeaders()` in `next.config.ts`; the project's `<Media>` via `mediaImageProps`/`videoProps` (§6.11b) | `buildR2Storage`, `mediaImageProps`, `videoProps`, `buildImagesConfig` | A, S |
|
||||
| 10 | **Forms** | every form from a **seed** (`scripts/seed-form-*.ts`: fields, confirmation, mail to the company **and** confirmation to the customer, every language); a block with `<RenderForm>` + `formClasses.ts` (look, once); `actions.ts` = `createSubmitAction({ getCachedPayload, headers })`; `forms: {…}` in `iapl`; `email: mailAdapter()` | `RenderForm` (`/rsc`), `createSubmitAction`, `mailAdapter` | A, P |
|
||||
| 11 | **Turnstile** | `<SiteProviders>` in `[locale]/layout.tsx` (wires `TurnstileProvider` with the key from the panel); `RenderForm` renders the widget; keys in Site integrations | `SiteProviders`, `getTurnstileConfig`, `TurnstileProvider` | A, P |
|
||||
| 12 | Consent + analytics | Consent Mode: `'advanced'` (default — the Google tag loads at once with every signal `denied`) or `'basic'` (`<SiteProviders analytics={{ consentMode: 'basic' }}>` — no request to Google before consent; a client who wants zero requests), the choice goes to "Project decisions"; `iapl({ consentLog: true })` (without it the `/api/ipal/consent` endpoint does not exist) + `<SiteProviders logEndpoint="/api/ipal/consent" banner={<CookieBanner equalChoice settings="detailed" />}>` (ConsentProvider, banner, CookieButton, Analytics in the right order); settings window mode (`settings`: `inline` / `modal` / `detailed`) per the design, brief is silent → `detailed`, the decision goes to "Project decisions"; tool IDs in the panel; the cookie list from a scan (`cookieScanner: true` → *Cookie review* → **Scan cookies** → *Approve cookies* → **Approve and add**; or cookie-scan → import) — feeds `<CookieTable>` on the policy page **and** the lists in the `detailed` window; Cookies → Settings window → Cookie list headings in every language | consent.md, analytics.md | A, `iapl-consent-check` |
|
||||
| 12 | Consent + analytics | Consent Mode: `'advanced'` (default — the Google tag loads at once with every signal `denied`) or `'basic'` (`<SiteProviders analytics={{ consentMode: 'basic' }}>` — no request to Google before consent; a client who wants zero requests), the choice goes to "Project decisions"; `iapl({ consentLog: true })` (without it the `/api/ipal/consent` endpoint does not exist) + `<SiteProviders logEndpoint="/api/ipal/consent" banner={<CookieBanner equalChoice settings="detailed" />}>` (ConsentProvider, banner, CookieButton, Analytics in the right order; the banner is in the server HTML and painted with the page — pages stay static, an inline script decides before the first paint; with a nonce CSP pass `nonce` to `SiteProviders`; never wrap the banner in a "mounted" guard or `dynamic(…, { ssr: false })`, never read the consent cookie in the layout unless the site is dynamic anyway: `consentCookie`, consent.md → "First paint"); settings window mode (`settings`: `inline` / `modal` / `detailed`) per the design, brief is silent → `detailed`, the decision goes to "Project decisions"; tool IDs in the panel; the cookie list from a scan (`cookieScanner: true` → *Cookie review* → **Scan cookies** → *Approve cookies* → **Approve and add**; or cookie-scan → import) — feeds `<CookieTable>` on the policy page **and** the lists in the `detailed` window; Cookies → Settings window → Cookie list headings in every language | consent.md, analytics.md | A, `iapl-consent-check` |
|
||||
| 13 | Security | `buildSecurityHeaders` in `next.config.ts`; `withSecurityConfig(withPayload(nextConfig))` — this order (no `X-Powered-By`; Payload's colour-scheme client hints for `/admin` only, check: `curl -sI localhost:3000/pl \| grep -i critical-ch` → nothing); CSP: `buildSecurityHeaders({ csp: { mode: 'report-only', reportUri: '/api/csp-report', … } })` + `buildAdminCspHeaders` on `/admin/:path*` + `src/app/api/csp-report/route.ts` (`createCspReportRoute`) → read the reports → `mode: 'enforce'`; `twoFactor: { issuer, plugin: payloadTotp }` + `generate:importmap` (`TotpRedirectProvider`, `SafeTotpView`; check: a new admin lands on `/admin/setup-totp?back=%2Fadmin` with the QR, no reloading; a login with the password only gets `403` from `/api/globals/site-integrations` and `/api/form-submissions` — security.md "What the second factor covers"); own endpoints: `secondFactorPassed(req)` / `userMeetsRole(req, role)`; **an account without 2FA can only set it up** (`twoFactor.requireSetup`, default: nothing else answers, 72 h from creation or an admin's reset, then blocked until an admin chooses "Reopen setup" on the account) — so set 2FA up right after creating an account; `iapl-doctor --url` must report 0 accounts without 2FA; Postgres/SQLite: migration for `totpSetupFrom`; `IAPL_IP_HEADER` in production | security.md, forms.md | A |
|
||||
| 14 | Operations | `src/app/api/health/route.ts` (`healthRoute`); `src/instrumentation.ts` with `assertEnv(iaplEnvRules({ storage: true, ipHeader: true }))`; staging with `IAPL_NOINDEX=1`; smoke tests (§8a) | `healthRoute`, `assertEnv`, `iaplEnvRules` | A |
|
||||
| 15 | System pages | Site settings → System pages: homepage, 404, privacy policy, cookies; legal links in the footer by role (`getSystemLinks(locale)`) | `getSystemLinks`, `getSystemPagePath`, `getNotFoundPage` | P |
|
||||
@@ -1160,6 +1160,7 @@ project → **plugin gap**, not a copy.
|
||||
| Need | Use | Doc |
|
||||
|---|---|---|
|
||||
| Banner, settings, cookie button | `<SiteProviders banner={<CookieBanner …/>}>`, `CookieButton`, `useConsent` | consent.md |
|
||||
| Banner at first paint (not after hydration; LCP) | built in: `CookieBanner firstPaint` (default on), `SiteProviders nonce` under a nonce CSP; off: `firstPaint={false}`; server-exact HTML on a dynamic site: `SiteProviders consentCookie` / `ConsentProvider cookieValue`; your own banner: `consentBannerScript`. Check: `curl -s <page> \| grep -c 'data-ipal="banner-script"'` → 1 and the response still has `s-maxage` | consent.md → "First paint" |
|
||||
| Settings window: in the bar / small / large with cookie details | `<CookieBanner settings="inline" \| "modal" \| "detailed">` — do not build your own window or cookie list | consent.md → "Large window with details" |
|
||||
| A consent-dependent script | `ConsentScript` | consent.md |
|
||||
| Cookie table on the policy page | `<CookieTable>` (`/rsc`), `getCookieTable` | consent.md |
|
||||
|
||||
@@ -38,6 +38,18 @@ before analytics or marketing consent — check the project's choice in "Project
|
||||
5. Banner not found (`data-ipal="banner"`) → `<CookieBanner/>` is not
|
||||
rendered, or an older IAPL version without `data-ipal` attributes on the buttons → **iapl-upgrade**.
|
||||
|
||||
6. Banner at first paint (1.17.0, consent.md → "First paint"): the banner is in the server HTML and an inline
|
||||
script shows or hides it before the browser paints; pages stay static.
|
||||
```bash
|
||||
curl -s http://localhost:3000/pl | grep -c 'data-ipal="banner-script"' # 1
|
||||
curl -sI http://localhost:3000/pl | grep -i cache-control # still s-maxage=… (static / ISR)
|
||||
```
|
||||
`0` → `firstPaint={false}`, a custom banner, or a wrapper that renders the banner only after mount
|
||||
(remove it). Under a nonce CSP the browser console must not report the inline script as refused: pass
|
||||
`nonce` to `<SiteProviders>`. A visitor who decided must never see the banner on reload; one whose
|
||||
decision is from an older Policy version must see it at once. A click on a button before hydration
|
||||
counts (the checks above click as soon as the button is visible).
|
||||
|
||||
The script needs buttons with `data-ipal="accept"` / `"reject"` — the plugin's
|
||||
`CookieBanner` has them in every `settings` mode (`inline`, `modal`, `detailed`). A custom banner in the project violates AGENT.md §7.
|
||||
|
||||
|
||||
@@ -89,6 +89,8 @@ through this procedure. Ask only when you are missing something you cannot get y
|
||||
| canonical / sitemap with localhost | `NEXT_PUBLIC_SERVER_URL` not set in the build | set it in the build env (not only at runtime) |
|
||||
| `/admin`, `/_next` → 500 or a loop | the proxy matcher is not a literal | inline matcher in `proxy.ts` |
|
||||
| hydration mismatch on the banner | reading cookie/`window` during render | consent only through `CookieBanner`/`useConsentContext`; `Date`, `Math.random` outside render |
|
||||
| banner appears late (after hydration), is the LCP element | `firstPaint={false}`; IAPL older than 1.17.0; a nonce CSP without `<SiteProviders nonce>` (console: the inline script was refused); a custom `classNames.root` is fine | consent.md → "First paint"; check: `curl -s <page> \| grep -c 'data-ipal="banner-script"'` → 1 |
|
||||
| banner flashes for a visitor who already decided | the first-paint script was refused (nonce) and `classNames.root` sets `display` over `[hidden]` (Tailwind 3) | pass the nonce; add `[data-ipal="banner"][hidden] { display: none !important }` |
|
||||
| images do not load (R2) | media domain missing in `images.remotePatterns` / wrong `R2_PUBLIC_URL`; without `R2_PUBLIC_URL`: Media has no `access.read: () => true` → 403 on `/api/media/file/…` | `next.config.ts` + env, or Media access (storage.md) |
|
||||
| 404 page without styles/nav | `not-found.tsx` outside `[locale]` without a layout | pages.md — `not-found` example |
|
||||
|
||||
|
||||
@@ -161,14 +161,15 @@ Fifteen ready blocks and ten page templates. **Use a library block (or a variant
|
||||
|
||||
| Export | Import from | What it does / when |
|
||||
|---|---|---|
|
||||
| `ConsentProvider` | `@intecion/ipal-kit/client` | Consent provider: `{ texts, cookieMap?, logEndpoint? }` — consent state, cookie, Consent Mode, deleting cookies after consent is withdrawn, optional POST of the decision to the log (`'/api/ipal/consent'`). Wrap the layout once; required by the banner, `Analytics`, `ConsentScript`. |
|
||||
| `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. |
|
||||
| `ConsentProvider` | `@intecion/ipal-kit/client` | Consent provider: `{ texts, cookieMap?, logEndpoint?, nonce?, cookieValue? }` (`nonce`: CSP nonce for the banner's first-paint script; `cookieValue`: optional server-read consent cookie → exact HTML, dynamic pages) — consent state, cookie, Consent Mode, deleting cookies after consent is withdrawn, optional POST of the decision to the log (`'/api/ipal/consent'`). Wrap the layout once; required by the banner, `Analytics`, `ConsentScript`. |
|
||||
| `CookieBanner` | `@intecion/ipal-kit/client` | Consent banner + category settings: `settings: 'inline' \| 'modal' \| 'detailed'`, `controls`, `equalChoice` (recommended `true`), `order`, `settingsActions`, `icon`, `classNames`, `firstPaint` (default `true`: in the server HTML, decided before the first paint by an inline script; pages stay static), `nonce`; 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. Props `className`, `side` (`'left' \| 'right'`), `avoid` (selector it lifts above, default `COOKIE_BUTTON_AVOID` = footer; `false`). Tokens `--ipal-cookie-button-offset`, `--ipal-cookie-button-inset`. Type `CookieButtonProps`. |
|
||||
| `COOKIE_BUTTON_AVOID`, `bottomOverlap(tops, viewportHeight)` | `@intecion/ipal-kit/client` | Default footer selector; pixels the footer covers at the bottom of the screen (how far the button moves up) |
|
||||
| `TOTP_TEXTS`, `TOTP_VIEW_TITLE` | `@intecion/ipal-kit` | en/pl texts of the 2FA screens (`totpPlugin:*`, merged by `twoFactor`) and their tab title |
|
||||
| `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?, 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). |
|
||||
| `useConsent(options?)` | `@intecion/ipal-kit/client` | Low-level consent state hook → `{ state, decided, consentId, hydrated, serverRead, acceptAll, rejectAll, savePreferences, reopen }` (options: `cookieMap`, `version`, `onDecision`, `cookieValue`). Usually use `ConsentProvider` + `useConsentContext` (the provider calls it itself). |
|
||||
| `consentBannerScript({ version?, cookieName? })` | `@intecion/ipal-kit` | The inline script `CookieBanner` puts after its markup: before the first paint it removes `hidden` from the banner (no current decision) or sets `display: none` (current decision), and keeps a click made before hydration. For a project's own banner; reads only the consent cookie. Options type: `ConsentBannerScriptOptions`. consent.md → "First paint". |
|
||||
| `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`. |
|
||||
| `getCookieTable({ payload, locale? })` | `@intecion/ipal-kit` | Server: Cookies → Cookie list rows in one language → `Promise<CookieTableRow[]>` (does not throw) — for `CookieTable`. |
|
||||
|
||||
@@ -452,6 +452,7 @@ and `rel="alternate" type="text/markdown"`; `/pl/nie-ma-takiej` → 404 with con
|
||||
- `createPageRoute`: `render` (your own view, e.g. an archive), `onMissing: 'redirectHome'`, `jsonLd: false`,
|
||||
`homeAlias: false`, `layoutField`; a fully custom page on `resolveRoute` (pages.md).
|
||||
`generateStaticParams` covers **only the pages collection, up to 1000 per language** — the scope is currently fixed (entries → ISR).
|
||||
- The cookie banner is in the server HTML and painted with the page; pages stay static (consent.md → "First paint"). Do not wrap it in a "mounted" guard. Off: `banner={<CookieBanner firstPaint={false} />}`; nonce CSP: `nonce` on `SiteProviders`; a dynamic site may pass `consentCookie` for server-exact HTML.
|
||||
- `SiteProviders`: `banner={false}` / your own, `cookieButton={false}`, `analytics={false}` / `{{ defer: true }}`,
|
||||
`preconnect={false}`, `jsonLd={[…]}` (adds), `cookieMap`, `theme`, `stats`; `JsonLdGraph` and
|
||||
`TurnstileProvider` currently always (Turnstile turns itself off without keys). A fully custom layout: providers from `/client`
|
||||
|
||||
@@ -566,6 +566,20 @@ PROGRAMISTA §6, item 76; security.md "Client hints") — one line, recommended
|
||||
**Check** (a production build, `pnpm build && pnpm start`): `curl -sI localhost:3000/pl | grep -iE 'accept-ch|critical-ch'` →
|
||||
nothing; `curl -sI localhost:3000/admin/login | grep -iE 'accept-ch|critical-ch'` → both; the panel opens in the browser's
|
||||
light / dark scheme with no flash; `pnpm exec iapl-doctor` has no `client-hints` finding.
|
||||
**→ 1.17.0, cookie banner at first paint (CHANGELOG 1.17.0 "Changed"; PROGRAMISTA §6, item 77; consent.md → "First paint") — nothing is required:**
|
||||
The banner is now in the server HTML and painted with the page (it appeared after hydration and could be the LCP
|
||||
element). Pages stay static; consent, tags, the cookie and the consent log are unchanged.
|
||||
1. Remove a project wrapper that delays the banner (`ConsentWrapper`, a "mounted" guard, `dynamic(…, { ssr: false })`)
|
||||
— it undoes the improvement.
|
||||
2. Nonce CSP (`createProxy({ csp })`): `<SiteProviders nonce={nonce}>` must be set (it already is where the theme
|
||||
script works); by hand: `<ConsentProvider nonce>`. Without it the banner appears after hydration, as before.
|
||||
3. Tailwind 3, or CSS of your own, with `classNames.root` that sets `display`: add
|
||||
`[data-ipal="banner"][hidden] { display: none !important }`.
|
||||
4. E2E tests of the project that expect **no** `[data-ipal="banner"]` element before a decision is read (e.g.
|
||||
`toHaveCount(0)` right after `goto` for a returning visitor) must wait for hydration or assert `toBeHidden()`.
|
||||
5. Keep the old behaviour: `<CookieBanner firstPaint={false} />`.
|
||||
**Check:** `curl -s <page> | grep -c 'data-ipal="banner-script"'` → 1; the response still carries `s-maxage`; first
|
||||
visit: the banner is there before the page's scripts have loaded; after a decision and a reload: never shown.
|
||||
|
||||
**→ 1.17.0, e-mail (the Intecion mail service (IWSN in the panel) is the default transport; Microsoft Graph deprecated; CHANGELOG 1.17.0;
|
||||
PROGRAMISTA §6, items 73–75; email.md; AGENT.md §7.2) — nothing to run; read which case the site is:**
|
||||
|
||||
+81
-4
@@ -82,9 +82,11 @@ export default async function Layout({ children, params }) {
|
||||
|
||||
`ConsentProvider` — props: `texts` (required, `ConsentTexts` from `getConsentTexts`),
|
||||
`cookieMap` (extra cookies to delete on withdrawal), `logEndpoint`
|
||||
(consent log). `CookieBanner` does not render after a decision, `CookieButton` —
|
||||
the opposite (it shows only after a decision and reopens the banner); both
|
||||
render only after mounting on the client.
|
||||
(consent log), `nonce` (CSP nonce for the banner's first-paint script), `cookieValue` (optional
|
||||
server-read cookie — [First paint](#first-paint-the-banner-is-part-of-the-first-render-1170)).
|
||||
`CookieBanner` does not render after a decision, `CookieButton` —
|
||||
the opposite (it shows only after a decision and reopens the banner). Since 1.17.0 the banner is in
|
||||
the server HTML and painted with the page, not after hydration (next section).
|
||||
|
||||
Built-in banner texts follow the page language: `consentFallback(locale)` → `CONSENT_FALLBACK_PL` on `pl`,
|
||||
`CONSENT_FALLBACK` (English) otherwise; panel values always win. Category names for your own selects:
|
||||
@@ -99,6 +101,8 @@ takes `locale` and optional `labels`; defaults: `COOKIE_TABLE_LABELS` (`@intecio
|
||||
|---|---|---|
|
||||
| `classNames` | — | slots (table below) — a given one replaces the default |
|
||||
| `equalChoice` | `false` | "Reject" styled as the primary button |
|
||||
| `firstPaint` | `true` | banner in the server HTML, decided before the first paint; `false` = nothing until the page has hydrated (as before 1.17.0) |
|
||||
| `nonce` | provider's | CSP nonce for the first-paint script; default: the one given to `ConsentProvider` / `SiteProviders` |
|
||||
| `icon` | `true` | cookie icon |
|
||||
| `order` | `['settings', 'reject', 'accept']` | banner buttons |
|
||||
| `settings` | `'inline'` | `'inline' \| 'modal' \| 'detailed'` |
|
||||
@@ -112,6 +116,78 @@ moves up by its visible part (`bottomOverlap`), so it never covers footer links.
|
||||
`--ipal-cookie-button-offset` (from the bottom, default `1rem`), `--ipal-cookie-button-inset` (from the
|
||||
side, default `1rem`); z-index `--ipal-z-header`. Type `CookieButtonProps`.
|
||||
|
||||
## First paint: the banner is part of the first render (1.17.0)
|
||||
|
||||
Before 1.17.0 the banner rendered nothing until React had hydrated the page and an effect had read the
|
||||
cookie. On a first visit its text appeared seconds after the page (measured on the reference site,
|
||||
mobile profile with 4x CPU and slow 4G: page painted at 1.0 s, banner at 2.7 s) and on a text page it
|
||||
became the **LCP element**. Now it is in the HTML and painted with the page (banner at 1.0 s, LCP 1.0 s).
|
||||
An existing site gets this by updating: no edit, pages stay static.
|
||||
|
||||
**How (default, pages stay static / ISR / CDN-cached).** The HTML is the same for every visitor, so it
|
||||
cannot know the visitor's cookie. The server renders the banner with the `hidden` attribute and, right
|
||||
after it, one small inline script (`consentBannerScript`, about 0.6 kB). The script runs while the HTML is
|
||||
parsed, before the browser paints:
|
||||
|
||||
| Visitor | Before the first paint | After hydration |
|
||||
|---|---|---|
|
||||
| no decision; decision under an older **Policy version**; unreadable or foreign `cookie-consent` | `hidden` removed → banner painted with the page | the same element becomes live (no re-render, no shift: the bar is `position: fixed`) |
|
||||
| current decision | `display: none` on the banner → never painted | React removes it; `CookieButton` appears |
|
||||
| JavaScript off, or a CSP refused the script | banner stays hidden | with JS: appears after hydration, as before 1.17.0; without JS: no banner (and no tag: every tag is loaded by JS) |
|
||||
|
||||
The script decides exactly as `readConsentRecord` does, reads only the consent cookie, stores nothing and
|
||||
loads nothing. A click on a banner button **before** hydration is not lost: the script notes the button
|
||||
(`data-ipal-pending`), and the banner carries the click out when it becomes live (the decision, the cookie
|
||||
and the consent log entry are made then, by the same code as any click). There is no hydration warning:
|
||||
React hydrates with "no decision" (what the server rendered) and switches to the browser's own value
|
||||
before the next paint (`useSyncExternalStore`).
|
||||
|
||||
What does **not** change: what counts as consent, when tags load (nothing earlier), the Consent Mode
|
||||
default (still pushed first), the cookie (`cookie-consent`, `{ id, state, timestamp, version }`), the
|
||||
consent log, withdrawal, `CookieButton`, the settings window in all three modes, texts per language.
|
||||
|
||||
**CSP.** With the header-only policy (`buildSecurityHeaders`, `'unsafe-inline'` for scripts — what
|
||||
static pages need anyway) nothing is to be done. With a nonce policy (`createProxy({ csp })`) the script
|
||||
needs the nonce: `<SiteProviders nonce={nonce}>` passes it on (a site that already passes `nonce` for the
|
||||
theme script is done); by hand: `<ConsentProvider nonce={nonce}>` or `<CookieBanner nonce={nonce}>`.
|
||||
Without the nonce the script is refused and the banner appears after hydration, as before.
|
||||
|
||||
**Your own `classNames.root`.** The banner is hidden with the `hidden` attribute. Tailwind 4 makes
|
||||
`[hidden]` win over every utility; with Tailwind 3 (or other CSS) a root class that sets `display`
|
||||
(`flex`, `grid`) overrides it: add `[data-ipal="banner"][hidden] { display: none !important }` to the
|
||||
site's CSS.
|
||||
|
||||
**Turn it off:** `<CookieBanner firstPaint={false} />` — nothing in the HTML, the banner appears after
|
||||
hydration (before 1.17.0).
|
||||
|
||||
**Option: read the cookie on the server (exact HTML, dynamic pages).** Pass the request's cookie and the
|
||||
server render already knows the decision — no banner in the HTML for a visitor who decided (the
|
||||
`CookieButton` instead), the banner without `hidden` and without a script for one who has not:
|
||||
|
||||
```tsx
|
||||
import { CONSENT_COOKIE } from '@intecion/ipal-kit'
|
||||
import { cookies } from 'next/headers'
|
||||
|
||||
const consentCookie = (await cookies()).get(CONSENT_COOKIE)?.value ?? null // null = read, none sent
|
||||
<SiteProviders shell={shell} consentCookie={consentCookie}>… // by hand: <ConsentProvider cookieValue={consentCookie}>
|
||||
```
|
||||
|
||||
The price: `cookies()` makes every page under that layout **dynamic** — rendered per request, no static
|
||||
or ISR copy, and a CDN must not share one HTML between visitors. Choose it only for a site that is
|
||||
dynamic anyway (a nonce CSP, signed-in pages). `undefined` (the prop left out) = static mode.
|
||||
|
||||
| | Static (default) | Server read (`consentCookie`) |
|
||||
|---|---|---|
|
||||
| Public pages | static / ISR, one HTML for all, CDN-cacheable | dynamic, per request |
|
||||
| Banner in the HTML of a visitor who decided | yes, hidden before paint | no |
|
||||
| Inline script | one (needs the nonce under a nonce CSP) | none |
|
||||
| Banner at first paint for a new visitor | yes | yes |
|
||||
|
||||
**Your own banner** (AGENT.md §7 says: don't; when you must): `consentBannerScript({ version })` from
|
||||
`@intecion/ipal-kit` (options: `ConsentBannerScriptOptions` — `version`, `cookieName`) is the same script — put `hidden` and `suppressHydrationWarning` on your banner's root and
|
||||
the script in a `<script>` as its next sibling; `useConsentContext()` gives `hydrated` (false in the
|
||||
server render and while hydrating) and `serverRead`.
|
||||
|
||||
## Overriding the look (Level 2)
|
||||
|
||||
The default Tailwind classes can be overridden with `classNames`:
|
||||
@@ -292,7 +368,8 @@ Texts from the panel (**Cookies**, per language) — empty field = the element i
|
||||
New fields in the global = a migration in projects on Postgres/SQLite (`payload migrate:create`); MongoDB unchanged.
|
||||
|
||||
The elements also have stable `data-ipal` handles for CSS and e2e tests (used by
|
||||
`iapl-consent-check`): `banner`, `cookie-button` and the buttons `settings`, `reject`,
|
||||
`iapl-consent-check`): `banner` (while it waits for the first-paint script it carries `hidden`; a button clicked before hydration:
|
||||
`data-ipal-pending`; live: `data-ipal-ready`), `banner-script`, `cookie-button` and the buttons `settings`, `reject`,
|
||||
`accept`, `back`, `save`; in modal mode also `consent-overlay`, `consent-dialog`, `close`; in detailed mode
|
||||
additionally `category-<category>` (card) and `cookies` (expandable list).
|
||||
|
||||
|
||||
@@ -684,6 +684,7 @@ Do one item at a time, build, check. Order by importance:
|
||||
| 74 | **1.17.0 — Postgres** — a Postgres site with many form submissions or "forgot password" requests at the same moment stopped answering (every page waited); after the update `transactionWatchState` shows a reserve, form and account mail arrive a moment after the save | Nothing to run. Default: a fifth of the pool (at least 2) kept free of transactions; form, "forgot password" and "verify" mail sent right after the commit; shorter SMTP time-outs. The old way: `connectionReserve: false`, `forms: { emailsInTransaction: true }`, `mail: { accountMailAfterCommit: false }`. An own e-mail adapter calls `sendAccountMailAfterCommit` first. MongoDB / SQLite: no change | CHANGELOG 1.17.0 "Fixed — Postgres", deployment.md §4.3a, forms.md "When e-mails go out" |
|
||||
| 75 | **1.17.0 — e-mail: launch day and copies** — a site moves from `<name>.dev.netscale.pl` to its real domain (the real domain must send with no click); or production's database is copied to a development or staging address (it must not mail real people); or the start stops with "`developmentHosts` must be an array of host patterns" | Nothing to run on launch day. A development address matching `iapl({ developmentHosts })` (built in `*.dev.netscale.pl`) or a site with `IAPL_NOINDEX=1` that holds another host's connection sends nothing until an admin presses "Connect again". Other staging hosts: add their pattern to `developmentHosts` (an array of non-empty patterns; `[]` = none). Production never keeps `IAPL_NOINDEX` | `iapl-upgrade` "→ 1.17.0, e-mail", email.md "Staging, copies and several hosts" |
|
||||
| 76 | **1.17.0 — public pages: Chrome requests the first page of a visit twice** — `curl -sI <site>/pl` shows `Critical-CH: Sec-CH-Prefers-Color-Scheme` (Payload's `withPayload` adds it for every path; only the admin reads the hint); Lighthouse lists the same URL twice under redirects | `next.config.ts`: `withSecurityConfig(withPayload(nextConfig))` — the plugin's wrapper OUTSIDE (was inside). Another panel address: `{ adminClientHints: { route } }`; keep the old behaviour: `{ adminClientHints: false }`. Without the edit nothing changes | `iapl-upgrade` "→ 1.17.0, the public pages' first request", security.md "Client hints" |
|
||||
| 77 | **1.17.0 — cookie banner at first paint** — the banner appeared seconds after the page (after hydration) and was the LCP element on text pages; or after the update an e2e test finds a hidden `[data-ipal="banner"]` for a returning visitor; or with a nonce CSP the console reports a refused inline script | Nothing to run: the banner is now in the server HTML and an inline script shows or hides it before the first paint; pages stay static; consent, tags and the log are unchanged. Remove a project "mounted" wrapper around the banner. Nonce CSP: `<SiteProviders nonce>`. Tailwind 3 with a `classNames.root` that sets `display`: `[data-ipal="banner"][hidden] { display: none !important }`. Old behaviour: `<CookieBanner firstPaint={false} />`; exact HTML on a dynamic site: `consentCookie` | `iapl-upgrade` "→ 1.17.0, cookie banner at first paint", consent.md "First paint" |
|
||||
|
||||
After updating the package: `pnpm exec iapl-skills` (new skill versions), `pnpm payload generate:importmap`, `rm -rf .next`, restart dev, grep for the new symbol in
|
||||
`node_modules/@intecion/ipal-kit/dist`.
|
||||
|
||||
+3
-1
@@ -157,11 +157,12 @@ It does not mount `AlternateLinksProvider` (i18n.md) — add it yourself if you
|
||||
| `logEndpoint` | — | consent log endpoint (`consentLog`) |
|
||||
| `banner` | `<CookieBanner />` | your own banner or `false` |
|
||||
| `cookieButton` | `<CookieButton />` | your own button or `false` |
|
||||
| `consentCookie` | — | optional server read of the consent cookie (`(await cookies()).get(CONSENT_COOKIE)?.value ?? null`): exact HTML, but the pages become dynamic. Left out (default): pages stay static and the banner decides before the first paint with an inline script — consent.md → "First paint" |
|
||||
| `analytics` | on | extra `<Analytics>` props or `false` = no tags |
|
||||
| `cookieMap` | — | extra cookies per category to clean up after consent is withdrawn |
|
||||
| `jsonLd` | `[]` | extra JSON-LD nodes |
|
||||
| `lightbox` | off | `true` / `{ texts, classNames, icons, loop, unstyled }` → one `<LightboxProvider>` for the site; texts from `shell.lightboxTexts` (Form messages → Image viewer) — lightbox.md |
|
||||
| `nonce` | — | CSP nonce (`(await headers()).get('x-nonce')` with `createProxy({ csp })`) for the theme script and the analytics tags — security.md |
|
||||
| `nonce` | — | CSP nonce (`(await headers()).get('x-nonce')` with `createProxy({ csp })`) for the theme script, the cookie banner's first-paint script and the analytics tags — security.md |
|
||||
| `preconnect` | `true` | `<link rel=preconnect>` to the media origin |
|
||||
| `stats` | off | `true`/props → `<PageStats>` (stats.md) |
|
||||
| `theme` | `false` | `<ThemeScript>` before the first paint (theme.md) |
|
||||
@@ -174,6 +175,7 @@ It does not mount `AlternateLinksProvider` (i18n.md) — add it yourself if you
|
||||
of the same name in `src/lib/content.ts` (e.g. your own `generateStaticParams` with entries).
|
||||
- `createPageRoute`: your own view through `render`, your own 404/redirect through `onMissing`, extra block props through `blockProps`, JSON-LD through `jsonLd`.
|
||||
- `SiteProviders`: `lightbox` is off by default; for `renderImage` / `renderDialog` (functions) mount `<LightboxProvider>` yourself in a client component instead (lightbox.md).
|
||||
- The cookie banner is in the server HTML and painted with the page (1.17.0; it used to appear after hydration and could be the LCP element). Off: `banner={<CookieBanner firstPaint={false} />}`; server-exact HTML on a dynamic site: `consentCookie` (consent.md → "First paint").
|
||||
- `SiteProviders`: `banner`, `cookieButton`, `analytics` accept your own element or `false`; `analytics={{ consentMode: 'basic' }}` = no request to Google before consent (default `'advanced'`: the tag loads with every signal `denied`).
|
||||
- Search engines from the panel: `robots` instead of `getRobots` ignores it; your own robots: `buildRobots({ ...robotsOptionsFrom(settings), … })`; drop the verification tags: `const { verification, ...meta } = await generatePageMetadata(…)`.
|
||||
- Construction filter in Markdown / MCP: `markdown: { isPathVisible: () => true }`, `mcp: { isPathVisible: () => true }`; in the sitemap and llms.txt: `underConstructionSeo: false`.
|
||||
|
||||
+2
-1
@@ -224,7 +224,7 @@ export const proxy = createProxy(i18nConfig, {
|
||||
// app/(frontend)/[locale]/layout.tsx
|
||||
import { headers } from 'next/headers'
|
||||
const nonce = (await headers()).get('x-nonce') // CSP_NONCE_HEADER
|
||||
<SiteProviders shell={shell} theme nonce={nonce}>… // ThemeScript + GA4/GTM tag get the nonce
|
||||
<SiteProviders shell={shell} theme nonce={nonce}>… // ThemeScript, the banner's first-paint script + GA4/GTM tag get the nonce
|
||||
```
|
||||
|
||||
Costs and rules:
|
||||
@@ -236,6 +236,7 @@ Costs and rules:
|
||||
- Your own proxy: `createCspNonce()` + `buildCsp({ nonce })`, set the policy on the request headers
|
||||
(`NextResponse.next({ request: { headers } })`) and on the response, like `createProxy` does.
|
||||
- `ConsentScript nonce`, `ThemeScript nonce`, `Analytics nonce` exist for policies without `'strict-dynamic'`.
|
||||
- The cookie banner's first-paint script (consent.md → "First paint") is inline, so under a nonce policy it needs the nonce with or without `'strict-dynamic'`: `SiteProviders nonce` passes it (`ConsentProvider nonce` / `CookieBanner nonce` by hand). Refused, the banner appears after hydration.
|
||||
|
||||
### Payload admin — its own, looser policy
|
||||
|
||||
|
||||
Reference in New Issue
Block a user