Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

shared-components ships react-ga4 (a live GA4 loader) into every consumer bundle, used or not #595

Copy link
Copy link

Description

@jamiefolsom
Issue body actions

@performant-software/shared-components exports an Analytics component built on react-ga4, and the package.json declares no sideEffects field. Without that flag, bundlers can't tree-shake the barrel (dist/index.es.js), so importing anything from the package pulls in the bundled react-ga4 module — including its runtime gtag injector:

n.src = `https://www.googletagmanager.com/gtag/js?id=${e}`

Observed in FairData Sites (core-data-places 3.1.25): the site has no analytics code at all, but a 1.7 MB public _astro chunk contains the GA4 loader on every deployed site. Clients do inspect our shipped bundles (a university infosec team recently reviewed one), and an analytics loader that's never used is exactly the kind of thing that raises questions.

Suggested fix, either or both:

  • Add "sideEffects": false to shared-components' package.json (assuming the modules are side-effect-free — the dist is already built with preserved module structure, so tree-shaking should then drop it).
  • Make react-ga4 a lazy import() inside the Analytics component so only consumers that render it pay for it.

Found by the new dhtools fds inventory bloat census (dhtools#15).

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.