Skip to content

Add sideEffects to package.json in /shared - #605

Open
ajolipa wants to merge 1 commit into
masterfrom
rb/add-sideeffects-field
Open

Add sideEffects to package.json in /shared#605
ajolipa wants to merge 1 commit into
masterfrom
rb/add-sideeffects-field

Conversation

@ajolipa

@ajolipa ajolipa commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

In this PR

Addresses Issue #595 by adding an explicit list of sideEffects to the shared-components package to allow more aggressive tree-shaking by consuming applications. This avoids the issue of bundling a component built on react-ga4 (from the Analytics component of the packagethat includes a gtag injector. Adding thesideEffectsfield inpackage.jsonallows theAnalytics` component to be shaken out of the bundle if unused.

Notes and questions

  • This has been tested locally with npm link; I built the shared-components bundle and then imported it into FDS and ran netlify build, and verified that a) the gtag script is not included in the output and b) the imports from the shared-components module still function in the built site (e.g. the fuzzy date utils, which seems to be the main thing FDS uses from this package).
  • More testing should be done re: the behavior of the CSS, to make sure that it is in fact not getting shaken out of the bundle when it shouldn't be;
  • Obviously this solution introduces a development constraint with this package going forward in terms of making sure that no new side effects are introduced in future updates (or are properly documented and added to the list when they are); this seems worth it to me, since I think especially with shared-components it's not uncommon for it to be imported into the site just to use the date utils or whatever and we don't want to introduce bloat into the built site, but still something to be aware of.
  • Do we think this should also be implemented for other packages? The GA4 stuff seems to be the biggest offender in terms of bundling unnecessary code, but I could imagine we might want to add this to the other packages as well (with the same caveat as above about being very careful about future changes not breaking anything).

@camdendotlol

Copy link
Copy Markdown
Contributor

I can't guarantee that we're not using it in something that lives outside our GitHub org (e.g. EVQ or something at cu-mkp?) but it appears that we're only using this component in FairCopy Activate, which AFAIK is no longer being used (tagging @NickLaiacona to confirm). https://github.com/search?q=org%3Aperformant-software+withGoogleAnalytics&type=code

Archnet rolls its own and it's a lot closer to how GA typically suggests setting it up: https://github.com/performant-software/archnet3/blob/6db713b296081ad89f25d7da119bbe2e8211ddb9/packages/web/components/GoogleAnalyics.js#L8

That is to say, I wonder if we need to keep the GA component here at all.

@ajolipa

ajolipa commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

That is to say, I wonder if we need to keep the GA component here at all.

Yeah, that is a great question. I was going off the framing in Issue #595 but I can definitely imagine that the cleanest solution to this particular issue would be just getting rid of the component. Probably should wait for @jamiefolsom's thoughts on it.

@blms

blms commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

I'd also vote for getting rid of the component if it's easy enough to make that change across any repos using it. Otherwise this also seems fine.

This has been tested locally with npm link; I built the shared-components bundle and then imported it into FDS and ran netlify build, and verified that a) the gtag script is not included in the output and b) the imports from the shared-components module still function in the built site

If we do decide to go this route—can you test with publish-beta on FDS as well as npm link? Just because I know npm link can introduce a bit different behavior

@NickLaiacona

Copy link
Copy Markdown
Member

I can confirm that FairCopy Activate is no longer in production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants