Skip to content

v3.0.0

Latest

Choose a tag to compare

@github-actions github-actions released this 27 Oct 02:39
eb810c6

React 19.3+, server rendering without hydration errors, and ESM + CommonJS builds.

Breaking changes

  • Requires React 19.3+. react and react-dom >=19.3 are now peer dependencies.
  • The ad only renders in the browser. The server sends an empty placeholder <ins> with your className and style, and the browser swaps in the ad after hydration using React's browser(). This fixes hydration errors from AdSense filling a server rendered slot before React hydrated it (#35). Give the slot a size so the page doesn't jump when the ad loads:
    <Adsense client="ca-pub-…" slot="…" style={{ minHeight: 280 }} />
  • New package entry points. ESM and CommonJS builds behind an exports map. Import from @ctrl/react-adsense, deep imports like @ctrl/react-adsense/dist/adsense no longer resolve. The code targets ES2022 (was ES2015).
  • No empty layout attributes. Without layout or layoutKey, the <ins> no longer gets data-ad-layout="" or data-ad-layout-key="".

Fixes

  • One adsbygoogle.push() per ad. StrictMode and <Activity> no longer push twice.
  • style is merged over the default display: block instead of replacing it. style={{ width: 300, height: 250 }} used to render an inline <ins> that ignored the size (#37).

New

  • Server Components (like the Next.js App Router) can render <Adsense> directly, the package is marked 'use client'.
  • AdsenseProps is exported, and ref, id, aria-*, data-* and the other <ins> props are typed and passed through.
    import { Adsense, type AdsenseProps } from '@ctrl/react-adsense';
    
    <Adsense ref={adRef} id="sidebar-ad" client="ca-pub-…" slot="…" />

Published from GitHub Actions with npm trusted publishing and provenance.

Full changelog: v2.1.0...v3.0.0