Skip to content

fix(build): lazy-init mainnet provider; drop global sideEffects:false#236

Merged
jinglescode merged 1 commit into
mainfrom
fix/build-ssr-provider
May 10, 2026
Merged

fix(build): lazy-init mainnet provider; drop global sideEffects:false#236
jinglescode merged 1 commit into
mainfrom
fix/build-ssr-provider

Conversation

@jinglescode
Copy link
Copy Markdown
Member

Summary

Two interacting bugs caused next build --webpack to crash on routes that imported resolve-adahandle (notably /wallets/[wallet]/transactions/new):

  1. Top-level provider construction. resolve-adahandle.tsx:5 called getProvider(1) at module load. During next build page-data collection every SSR'd page imports that module, which constructs BlockfrostProvider(undefined) when NEXT_PUBLIC_BLOCKFROST_API_KEY_MAINNET isn't readable at build time (SKIP_ENV_VALIDATION=true). The constructor throws; webpack reports it as a generic "factory error".

  2. Global sideEffects: false. next.config.js had optimization.sideEffects: false set on the global webpack config. That tells webpack every file is side-effect-free, silently stripping global CSS imports and module-level init — and masking the real crash from (1) until a caller exercised the code path.

Fix

  • resolve-adahandle.tsx — lazy-init singleton: getProvider(1) runs only when resolveAdaHandle() is actually called (client-side).
  • next.config.js — remove the global sideEffects: false override. Per-package sideEffects flags in each package.json are the correct surface.
  • _app.tsx / api-docs.tsx — move swagger-ui-react/swagger-ui.css import into the custom App, since Pages Router only allows global CSS imports from _app.tsx.

Test plan

  • next build --webpack completes without errors
  • /wallets/[wallet]/transactions/new renders (was failing before)
  • /api-docs renders Swagger UI with styles intact
  • No regressions on other routes

Verified locally: production build completes (exit 0), all routes generate.

🤖 Generated with Claude Code

Two interacting issues caused the production build to crash on routes
that imported resolve-adahandle (notably /wallets/[wallet]/transactions/new):

1. resolve-adahandle.tsx called getProvider(1) at module top level. Under
   `next build` page-data collection, every server-rendered page imports
   that module, which constructs BlockfrostProvider(undefined) when
   NEXT_PUBLIC_BLOCKFROST_API_KEY_MAINNET isn't readable at build time
   (e.g. SKIP_ENV_VALIDATION=true). The constructor throws and the
   webpack runtime reports it as a generic "factory error".

2. next.config.js had `optimization.sideEffects: false` set globally,
   which tells webpack that *every* file is side-effect-free. That
   silently strips global CSS imports and any module-level initialization,
   masking issues like (1) until you hit a route that exercises them.

Fix:
- Lazy-init the mainnet provider with a cached singleton, so import is
  free and instantiation only happens when a caller actually resolves a
  handle (always client-side).
- Remove the global sideEffects:false override. Per-package sideEffects
  declarations in package.json are the correct mechanism; the global
  override was masking real bugs.
- Move swagger-ui-react CSS import from api-docs.tsx into _app.tsx so
  Next.js Pages Router's "global CSS only from _app" rule is satisfied.

Verified locally: `next build --webpack` completes; both
/wallets/[wallet]/transactions/new and /api-docs render.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
multisig Ready Ready Preview, Comment May 10, 2026 8:26am

Request Review

@jinglescode jinglescode merged commit 9e4eed1 into main May 10, 2026
6 checks passed
@jinglescode jinglescode deleted the fix/build-ssr-provider branch May 10, 2026 08:56
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.

1 participant