Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): keep analytics consent banner floating above page

Gusb938ed550a6e
diff --git a/src/web/src/components/analytics-consent.dom.test.tsx b/src/web/src/components/analytics-consent.dom.test.tsx
index c006f9858..c4b64d155 100644
--- a/src/web/src/components/analytics-consent.dom.test.tsx
+++ b/src/web/src/components/analytics-consent.dom.test.tsx
@@ -49,6 +49,41 @@ afterEach(() => {
})
describe("AnalyticsConsent", () => {
+ it("preserves page layout while the floating banner is open and dismissed", async () => {
+ vi.stubGlobal("fetch", successfulFetch("denied"))
+ const layoutStyle = document.createElement("style")
+ layoutStyle.textContent = `
+ body { padding-bottom: 0px; }
+ .hero-section, .workspace-shell { height: 100dvh; }
+ `
+ document.head.appendChild(layoutStyle)
+ try {
+ render(
+ <>
+ <main className="hero-section" data-testid="consent-hero" />
+ <main className="workspace-shell" data-testid="consent-workspace" />
+ <AnalyticsConsent />
+ </>,
+ )
+ const banner = await screen.findByTestId(tid.analyticsConsentBanner)
+ const expectPageLayout = () => {
+ expect(getComputedStyle(document.body).paddingBottom).toBe("0px")
+ expect(getComputedStyle(screen.getByTestId("consent-hero")).height).toBe("100dvh")
+ expect(getComputedStyle(screen.getByTestId("consent-workspace")).height).toBe("100dvh")
+ }
+ expectPageLayout()
+ fireEvent(window, new Event("resize"))
+ expectPageLayout()
+ fireEvent.click(within(banner).getByRole("button", { name: "Only necessary" }))
+ await waitFor(() => {
+ expect(screen.queryByTestId(tid.analyticsConsentBanner)).not.toBeInTheDocument()
+ })
+ expectPageLayout()
+ } finally {
+ layoutStyle.remove()
+ }
+ })
+
it("shows a first-visit banner without loading GTM", async () => {
render(<AnalyticsConsent />)
const banner = await screen.findByTestId(tid.analyticsConsentBanner)
diff --git a/src/web/src/components/analytics-consent.tsx b/src/web/src/components/analytics-consent.tsx
index 766732ce7..193fabb85 100644
--- a/src/web/src/components/analytics-consent.tsx
+++ b/src/web/src/components/analytics-consent.tsx
@@ -126,46 +126,12 @@ function ConsentButtons({
export function AnalyticsConsent() {
const { ready, decision, nativeMobile } = useStoredAnalyticsConsent(true)
const { choose, saving, error } = useAnalyticsConsentChoice()
- const bannerRef = useRef<HTMLElement>(null)
-
- useEffect(() => {
- if (!ready || decision !== null || !bannerRef.current) return
- const root = document.documentElement
- const banner = bannerRef.current
- const updateInset = () => {
- root.style.setProperty(
- "--analytics-consent-inset",
- `${Math.ceil(banner.getBoundingClientRect().height) + 32}px`,
- )
- }
- root.dataset.analyticsConsentPending = "true"
- updateInset()
- const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(updateInset)
- observer?.observe(banner)
- window.addEventListener("resize", updateInset)
- return () => {
- observer?.disconnect()
- window.removeEventListener("resize", updateInset)
- delete root.dataset.analyticsConsentPending
- root.style.removeProperty("--analytics-consent-inset")
- }
- }, [decision, ready])
return (
<>
- <style>{`
- html[data-analytics-consent-pending="true"] body {
- padding-bottom: var(--analytics-consent-inset);
- }
- html[data-analytics-consent-pending="true"] .hero-section,
- html[data-analytics-consent-pending="true"] .workspace-shell {
- height: calc(100dvh - var(--analytics-consent-inset));
- }
- `}</style>
{ready && decision === "granted" ? <GoogleTagManager gtmId={GTM_ID} /> : null}
{ready && !nativeMobile && decision === null ? (
<section
- ref={bannerRef}
aria-label="Analytics choices"
className={styles.banner}
data-testid={tid.analyticsConsentBanner}