Cookie button never moves; the footer gets room under its last row while the button is shown

Owner, 2026-12-01, after the review of fb92b35: option 3, "miejsce pod stopką" — the button stays in its corner at
all times and covers nothing; the page gets room under its last row.

- Removed: the step up at the end of the page (`clear`, COOKIE_BUTTON_CLEAR, stepAbove; never released).
- New: while the button is shown, the last footer (`reserve`, COOKIE_BUTTON_RESERVE; no footer: <body>) gets bottom
  padding, measured: button height + offset + safe area + 8 px, minus what is already free under the lowest text or
  control in the button's column. The footer's own padding counts (no double space); an empty corner gets nothing.
  Not before a decision, not while the banner is open, gone with the button; `reserve={false}` turns it off,
  `--ipal-cookie-button-space` on the footer sets the amount (0 = none, per breakpoint).
- No layout shift: on a static page <CookieButton> renders an inline script that makes the room before the first
  paint for a visitor who already decided — in a constructed style sheet, so the server's markup is untouched and
  React hydrates without a mismatch; after hydration the same function moves it onto the element.
- consentDecidedScript: the shared start of the banner's and the button's pre-paint scripts.
- avoid={COOKIE_BUTTON_AVOID} is still the placement before 1.17.2 (no room then).

Tests: test/cookieButtonPlacement.test.ts rewritten (24); reference e2e on desktop, 390 px and 360 px phones, light
and dark, five pages: the corner at every scroll position, nothing under the button at the very end, every footer
link clickable, layout shift < 0.001, the room before hydration.
Docs: consent.md, AGENT.md, skills, PROGRAMISTA item 83, changelog draft 1.17.2.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 12:08:00 +01:00
co-authored by Claude Fable 5.2
parent fb92b357e8
commit 3821174be4
20 changed files with 763 additions and 321 deletions
+118 -54
View File
@@ -493,70 +493,134 @@ test('consent: withdrawal — reopen, reject: analytics cookies and listed stora
expect((await consentRecord(context))!.state).toMatchObject({ analytics: false, functional: false, marketing: false })
})
// The "cookie settings" button stays in the bottom corner of the window (1.17.2): it does not climb above the footer.
// At the very end of the page it steps above a link it would keep covered.
// The "cookie settings" button stays in the bottom corner of the window (1.17.2) and never moves: not above the
// footer, not at the end of the page. The footer gets room under its last row while the button is shown, so the
// button covers nothing there (consent.md → "Where the cookie button sits").
const BUTTON_PAGES = ['/pl', '/pl/kontakt', '/en', '/pl/blog', '/pl/regulamin']
const buttonState = () => {
const b = document.querySelector<HTMLElement>('[data-ipal="cookie-button"]')
const footer = [...document.querySelectorAll<HTMLElement>('footer, [role="contentinfo"]')].at(-1)!
if (!b) {return { button: false, room: footer.hasAttribute('data-ipal-cookie-space') }}
const r = b.getBoundingClientRect()
const hits = (q: DOMRect) => q.width > 0 && q.height > 0 && q.right > r.left && q.left < r.right && q.bottom > r.top && q.top < r.bottom
// every piece of footer text and every control of the page that lies under the button
const under: string[] = []
const walker = document.createTreeWalker(footer, NodeFilter.SHOW_TEXT)
const range = document.createRange()
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
if (!/\S/.test(node.nodeValue ?? '')) {continue}
range.selectNodeContents(node)
if ([...range.getClientRects()].some(hits)) {under.push(`text: ${node.nodeValue!.trim().slice(0, 24)}`)}
}
for (const el of document.querySelectorAll('a[href], button, input, select, textarea, summary')) {
if (el !== b && hits(el.getBoundingClientRect())) {under.push(`control: ${(el.textContent ?? '').trim().slice(0, 24)}`)}
}
return {
button: true,
gap: Math.round(window.innerHeight - r.bottom),
inFooter: !!b.closest('footer'),
left: Math.round(r.left),
position: getComputedStyle(b).position,
room: footer.hasAttribute('data-ipal-cookie-space'),
transform: getComputedStyle(b).transform,
under,
}
}
const CORNER = { button: true, gap: 16, inFooter: false, left: 16, position: 'fixed', transform: 'none' }
for (const device of [
{ name: 'desktop', viewport: { height: 800, width: 1280 } },
{ name: 'phone', viewport: { height: 844, width: 390 } },
{ name: 'small phone', viewport: { height: 640, width: 360 } },
]) {
test(`cookie button, ${device.name}: bottom corner on long and short pages, never on a link at the page end, no layout shift`, async ({ browser }) => {
const context = await browser.newContext({ viewport: device.viewport })
const page = await context.newPage()
await page.addInitScript(() => {
const w = window as unknown as { __cls: number }
w.__cls = 0
new PerformanceObserver((list) => {
for (const entry of list.getEntries() as unknown as { hadRecentInput: boolean; value: number }[]) {
if (!entry.hadRecentInput) {w.__cls += entry.value}
}
}).observe({ buffered: true, type: 'layout-shift' })
})
await page.goto('/pl')
await page.locator('[data-ipal="reject"]').click()
const button = page.locator('[data-ipal="cookie-button"]')
const probe = () =>
button.evaluate((b: HTMLElement) => {
const r = b.getBoundingClientRect()
b.style.pointerEvents = 'none'
const covered = [[r.left + 4, r.top + 4], [r.right - 4, r.top + 4], [r.left + 4, r.bottom - 4], [r.right - 4, r.bottom - 4], [r.left + r.width / 2, r.top + r.height / 2]]
.map(([x, y]) => document.elementFromPoint(x, y)?.closest('a, button, input, select, textarea, summary'))
.filter(Boolean)
.map((el) => (el!.textContent ?? '').trim().slice(0, 30))
b.style.pointerEvents = ''
return { covered, gap: Math.round(window.innerHeight - r.bottom), inFooter: !!b.closest('footer'), left: Math.round(r.left), position: getComputedStyle(b).position }
for (const colorScheme of ['light', 'dark'] as const) {
test(`cookie button, ${device.name}, ${colorScheme}: the corner at every scroll position, nothing under it at the end, no layout shift`, async ({ browser }) => {
const context = await browser.newContext({ colorScheme, hasTouch: device.name !== 'desktop', viewport: device.viewport })
const page = await context.newPage()
await page.addInitScript(() => {
const w = window as unknown as { __cls: number }
w.__cls = 0
new PerformanceObserver((list) => {
for (const entry of list.getEntries() as unknown as { hadRecentInput: boolean; value: number }[]) {
if (!entry.hadRecentInput) {w.__cls += entry.value}
}
}).observe({ buffered: true, type: 'layout-shift' })
})
for (const path of ['/pl', '/pl/regulamin', '/pl/kontakt']) {
await page.goto(path)
await expect(button).toBeVisible()
const shifts = () => page.evaluate(() => (window as unknown as { __cls: number }).__cls)
await page.waitForTimeout(300)
const before = await shifts()
const height = await page.evaluate(() => document.documentElement.scrollHeight)
for (const y of [0, Math.max(0, (height - device.viewport.height) / 2)]) {
await page.evaluate((to) => window.scrollTo(0, to), y)
await page.waitForTimeout(350)
if (y + device.viewport.height < height - 2) {
// anywhere above the end of the page: exactly in the corner, the footer in view or not
expect(await probe(), `${path} at ${Math.round(y)}`).toMatchObject({ gap: 16, inFooter: false, left: 16, position: 'fixed' })
const footerPadding = () => page.evaluate(() => getComputedStyle([...document.querySelectorAll('footer')].at(-1)!).paddingBottom)
// before a decision: no button, the footer as the project made it
await page.goto('/pl')
await expect(page.locator('[data-ipal="banner"]')).toBeVisible()
expect(await page.evaluate(buttonState)).toEqual({ button: false, room: false })
const ownPadding = await footerPadding()
await page.locator('[data-ipal="reject"]').click()
const button = page.locator('[data-ipal="cookie-button"]')
for (const path of BUTTON_PAGES) {
// a returning visitor's page load: the room is there from the first paint, so nothing shifts when the button appears
await page.goto(path)
await expect(button).toBeVisible()
await page.waitForTimeout(400)
const height = await page.evaluate(() => document.documentElement.scrollHeight)
const end = Math.max(0, height - device.viewport.height)
for (const y of [0, end / 2, end - 40, end]) {
await page.evaluate((to) => window.scrollTo(0, to), y)
await page.waitForTimeout(250)
expect(await page.evaluate(buttonState), `${path} at ${Math.round(y)} of ${end}`).toMatchObject(CORNER)
}
// the very end of the page (measured now: a form or its Turnstile widget may have grown the page since)
await page.evaluate(() => window.scrollTo(0, document.documentElement.scrollHeight))
await page.waitForTimeout(250)
expect(await page.evaluate(() => Math.round(window.innerHeight + window.scrollY - document.documentElement.scrollHeight)), `${path}: at the end`).toBe(0)
expect(await page.evaluate(buttonState), `${path} at the very end`).toMatchObject(CORNER)
// no footer text and no control under the button
expect((await page.evaluate(buttonState)).under, `${path}: under the button at the end`).toEqual([])
// and every footer link can be clicked (Playwright refuses a click another element would receive)
const links = page.locator('footer a[href]')
const count = await links.count()
expect(count).toBeGreaterThan(3)
for (let i = 0; i < count; i++) {await links.nth(i).click({ timeout: 3000, trial: true })}
expect(await shifts(), `${path}: layout shift from load to the end of the page`).toBeLessThan(0.001)
}
await page.evaluate(() => window.scrollTo(0, document.documentElement.scrollHeight))
await page.waitForTimeout(450)
const end = await probe()
expect(end, `${path} at the end`).toMatchObject({ covered: [], inFooter: false, left: 16, position: 'fixed' })
expect(end.gap, `${path}: still at the bottom, not above the footer`).toBeLessThan(120)
expect((await shifts()) - before, `${path}: layout shift while scrolling`).toBeLessThan(0.001)
}
// keyboard: reachable and it reopens the banner
await button.focus()
await expect(button).toBeFocused()
await page.keyboard.press('Enter')
await expect(page.locator('[data-ipal="banner"]')).toBeVisible()
await expect(button).toHaveCount(0)
await context.close()
})
// keyboard: reachable and it reopens the banner; the room goes with the button
await button.focus()
await expect(button).toBeFocused()
await page.keyboard.press('Enter')
await expect(page.locator('[data-ipal="banner"]')).toBeVisible()
expect(await page.evaluate(buttonState)).toEqual({ button: false, room: false })
await page.goto('/pl') // decided again? no: reopening does not undo the stored decision, the button is back
await expect(button).toBeVisible()
await page.locator('[data-ipal="cookie-button"]').click()
expect(await footerPadding(), 'banner open: the footer as before a decision').toBe(ownPadding)
await context.close()
})
}
}
test('cookie button: for a returning visitor the room is there before the page hydrates (no application script)', async ({ browser }) => {
const context = await browser.newContext({ hasTouch: true, viewport: { height: 844, width: 390 } })
const page = await context.newPage()
const padding = () => page.evaluate(() => parseFloat(getComputedStyle([...document.querySelectorAll('footer')].at(-1)!).paddingBottom))
await page.goto('/pl')
const own = await padding()
await page.locator('[data-ipal="reject"]').click()
await expect(page.locator('[data-ipal="cookie-button"]')).toBeVisible()
const live = await padding()
expect(live).toBeGreaterThan(own)
// the same page with every application script refused: only the inline script can have made the room
await page.route(isAppScript, (route) => route.abort())
await page.goto('/pl')
await expect(page.locator('[data-ipal="cookie-button"]')).toHaveCount(0)
// the same room, to the pixel or one off: here the web font may not have arrived yet, and the row's text box follows the font
expect(Math.abs((await padding()) - live)).toBeLessThanOrEqual(2)
expect(await padding()).toBeGreaterThan(own + 30)
// the server's markup is untouched (React hydrates it without a mismatch): the room is in a style sheet
expect(await page.evaluate(() => [...document.querySelectorAll('footer')].at(-1)!.getAttribute('style'))).toBeNull()
await context.close()
})
test('admin: sign in through 2FA, agency credit, panel link preview', async ({ page, request }) => {
const head = await (await request.get('/admin/login')).text()
expect(head).toMatch(/noindex/)