mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
In the TanStack build, `next/script` is a compat shim that rendered a
plain React `<script>` element. React never executes scripts it creates
on the client, so `<Script>` silently did nothing. The only consumer is
`TelemetryTagManager` (`packages/common/telemetry.tsx`), so Google Tag
Manager never loaded on the dashboard: the tag was in the DOM, but no
`gtm.js` event and no loader request.
**Changed:**
- `compat/next/script.tsx` is now a client-only port of Next's
`next/script`: it renders nothing and injects the script imperatively in
an effect (`document.createElement`), with Next's attribute handling,
`onLoad`/`onReady`/`onError` semantics and `lazyOnload` strategy
- Scripts are deduped by `id`/`src` at module level, so remounts and
duplicate instances never execute the same script twice (GTM can't
double-initialize)
- `beforeInteractive` and `worker` load after mount like
`afterInteractive`, since there's no Next document or Partytown in the
SPA
**Added:**
- `compat/next/script.test.tsx` covering inline execution, dedupe across
remounts, `src` scripts, load/error callbacks and `lazyOnload`
No CSP change needed: `script-src` already allows `'unsafe-inline'` and
the Stape GTM host, and `connect-src`/`img-src`/`frame-src` cover its
collect hits and service-worker iframe.
## To test
- On the preview, with consent accepted, open devtools on any dashboard
page:
- `window.dataLayer` contains a `gtm.js` event and
`window.google_tag_manager` is defined
- The Network tab shows the GTM loader request (`4icgbaujh.js`) plus
collect hits
- Exactly one `script[src*="4icgbaujh"]` element exists, even after
navigating around
- No CSP violations ("Refused to load…") in the console, including on
sign-in/sign-up
- Opt out of analytics in Account → Preferences, reload, and confirm the
loader isn't requested
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>