Repository navigation
React 19.3+, server rendering without hydration errors, and ESM + CommonJS builds.
Breaking changes
- Requires React 19.3+.
reactandreact-dom>=19.3are now peer dependencies. - The ad only renders in the browser. The server sends an empty placeholder
<ins>with yourclassNameandstyle, and the browser swaps in the ad after hydration using React'sbrowser(). 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
exportsmap. Import from@ctrl/react-adsense, deep imports like@ctrl/react-adsense/dist/adsenseno longer resolve. The code targets ES2022 (was ES2015). - No empty layout attributes. Without
layoutorlayoutKey, the<ins>no longer getsdata-ad-layout=""ordata-ad-layout-key="".
Fixes
- One
adsbygoogle.push()per ad. StrictMode and<Activity>no longer push twice. styleis merged over the defaultdisplay: blockinstead 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'. AdsensePropsis exported, andref,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