fix(build): lazy-init mainnet provider; drop global sideEffects:false#236
Merged
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two interacting bugs caused
next build --webpackto crash on routes that importedresolve-adahandle(notably/wallets/[wallet]/transactions/new):Top-level provider construction.
resolve-adahandle.tsx:5calledgetProvider(1)at module load. Duringnext buildpage-data collection every SSR'd page imports that module, which constructsBlockfrostProvider(undefined)whenNEXT_PUBLIC_BLOCKFROST_API_KEY_MAINNETisn't readable at build time (SKIP_ENV_VALIDATION=true). The constructor throws; webpack reports it as a generic "factory error".Global
sideEffects: false.next.config.jshadoptimization.sideEffects: falseset 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 whenresolveAdaHandle()is actually called (client-side).next.config.js— remove the globalsideEffects: falseoverride. Per-packagesideEffectsflags in eachpackage.jsonare the correct surface._app.tsx/api-docs.tsx— moveswagger-ui-react/swagger-ui.cssimport into the custom App, since Pages Router only allows global CSS imports from_app.tsx.Test plan
next build --webpackcompletes without errors/wallets/[wallet]/transactions/newrenders (was failing before)/api-docsrenders Swagger UI with styles intactVerified locally: production build completes (exit 0), all routes generate.
🤖 Generated with Claude Code