Skip to content

chore: add sideeffects field to package.json to enable bundler tree-shaking (#886)#923

Merged
NoopDog merged 1 commit into
mainfrom
fran/886-side-effects
May 20, 2026
Merged

chore: add sideeffects field to package.json to enable bundler tree-shaking (#886)#923
NoopDog merged 1 commit into
mainfrom
fran/886-side-effects

Conversation

@frano-m

@frano-m frano-m commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds "sideEffects": false to package.json to enable webpack/Turbopack tree-shaking in consumer applications. The library is genuinely side-effect free at module load — this is correct metadata to publish.

Closes #886.

Audit

Verified there are no module-load side effects in src/:

  • ✅ No .css / .scss imports
  • ✅ No top-level window / global / globalThis mutations
  • ✅ No top-level console.log / addEventListener / IIFEs
  • ✅ Module-scope let singletons (dxConfig in config/config.ts, kyInstance in entity/common/client.ts, hasInstalledInterceptor in services/beforePopState/popStateBus.ts) only declare initial state; mutation happens lazily via exported functions when called by consumers
  • src/common/analytics/analytics.ts is purely function-scoped
  • ✅ Providers use createContext(...) (pure)
  • ✅ Yup schemas (SCHEMA in UseFilterRange, VALIDATION_SCHEMA in SupportRequestForm) are pure construction at module scope — bundler can drop them when unused
  • new Set<BeforePopStateCallback>() at top of popStateBus.ts is pure; interceptor is only installed when registerPopStateHandler() is called

Verdict: Option A ("sideEffects": false) is safe — no allowlist needed.

Bundle-analyzer measurement

Tested against data-biosphere (anvil-cmg production build) using @next/bundle-analyzer:

Total client JS gzipped
Before — 52.2.0 (registry) 846.74 KB
After — local tarball + "sideEffects": false 850.77 KB

Net delta: ~0 (slight fluctuation is from unrelated v53 changes — MarkdownRenderer DOMPurify removal — bleeding into the AFTER baseline).

Why neutral for data-biosphere

grep of consumer imports:

  • 548 deep imports: from "@databiosphere/findable-ui/lib/<path>"
  • 0 barrel imports: from "@databiosphere/findable-ui"

When a consumer always reaches for specific files via deep imports, the bundler is already loading only what's needed; there's nothing for sideEffects to additionally drop. Other findable-ui consumers (anvil-portal, data-browser, etc.) follow the same deep-import convention per CLAUDE.md ("External apps import as @databiosphere/findable-ui/lib/<path>"), so the picture is the same across the fleet.

Why land it anyway

  • Correct metadata for a side-effect-free library — what tree-shaking-aware bundlers expect.
  • Zero cost / zero risk — runtime behavior of the library is unchanged.
  • Latent benefit: protects consumer bundles the moment any consumer adopts barrel imports, or if a findable-ui barrel index ever starts re-exporting from heavy submodules.
  • Defensive future-proofing.

Test plan

  • npm run check-format
  • npm run lint
  • npm run test-compile
  • npm test — 49 suites, 425 tests ✓
  • npm run storybook boots cleanly (HTTP 200, 2.72s preview build, no errors)
  • Production build of data-biosphere succeeds against local tarball

Acceptance criteria

  • Audit completed; no offending modules
  • sideEffects field added to package.json
  • Lint, tests, and tsc --noEmit pass
  • Storybook renders cleanly
  • Before/after bundle-analyzer numbers from one consumer included above (screenshots can be regenerated on request — local artifacts deleted post-measurement)

🤖 Generated with Claude Code

image

Copilot AI review requested due to automatic review settings May 20, 2026 12:01
@frano-m frano-m marked this pull request as ready for review May 20, 2026 12:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds package metadata indicating the library is side-effect free at module evaluation time, enabling bundlers (e.g., webpack/Turbopack) to more aggressively tree-shake unused modules/exports in consuming applications.

Changes:

  • Add "sideEffects": false to package.json to allow consumer bundlers to drop unused @databiosphere/findable-ui modules when appropriate.

…haking (#886)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@NoopDog NoopDog force-pushed the fran/886-side-effects branch from d67784b to d5936b7 Compare May 20, 2026 21:15
@NoopDog NoopDog merged commit 567519a into main May 20, 2026
2 checks passed
@frano-m frano-m deleted the fran/886-side-effects branch June 4, 2026 10:15
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.

Add sideEffects field to package.json to enable bundler tree-shaking

3 participants