Skip to content

chore: optimize package imports & remove unused imports#413

Merged
Junman140 merged 2 commits into
Pi-Defi-world:devfrom
hashmart138-creator:fix/optimize-imports-unused-imports
May 29, 2026
Merged

chore: optimize package imports & remove unused imports#413
Junman140 merged 2 commits into
Pi-Defi-world:devfrom
hashmart138-creator:fix/optimize-imports-unused-imports

Conversation

@hashmart138-creator
Copy link
Copy Markdown

@hashmart138-creator hashmart138-creator commented May 27, 2026

chore: optimize imports & remove unused imports

Summary

  • Add Next.js package-import optimization to improve tree-shaking for lucide-react and local UI exports.
  • Remove several unused imports in page components to reduce bundle size and silence ESLint warnings.
  • Add a small detection script scripts/find-unused-imports.cjs to help find remaining unused icons/hooks.

Files changed

  • next.config.mjs — added experimental.optimizePackageImports entries
  • app/auth/wallet-setup/page.tsx — removed unused Dialog* imports
  • app/business/sme/page.tsx — removed unused ArrowRight icon import
  • scripts/find-unused-imports.cjs, scripts/find-unused-imports.js — added detection scripts

Testing & Notes

  • I created branch fix/optimize-imports-unused-imports and pushed the changes.
  • I could not run pnpm lint -- --fix or the test suite in this environment (pnpm not available). Please run the lint and tests locally or in CI and apply/approve any additional fixes.

Recommended local steps

git checkout fix/optimize-imports-unused-imports
pnpm install
pnpm lint -- --fix
pnpm test
git add -A
git commit -m "chore: fix lint issues"
git push

Checklist

  • Add experimental.optimizePackageImports to next.config.mjs
  • Remove obvious unused imports detected
  • Add detection script for unused imports
  • Run pnpm lint -- --fix and apply remaining fixes
  • Confirm tests pass and open PR

close #353 close #349

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

📝 Walkthrough

Walkthrough

This PR consolidates the useApiError() hook usage in FiatSimPage to reduce redundant calls, and adds Next.js experimental configuration for tree-shaking optimizations on lucide-react and local UI component imports.

Changes

Code and build improvements

Layer / File(s) Summary
useApiError hook consolidation
app/fiat/page.tsx
FiatSimPage now uses a single useApiError() destructuring to obtain all error state and handlers (uiError, setApiError, clearError, isSubmitDisabled, handleError), eliminating a duplicate call.
Tree-shaking import optimization
next.config.mjs
Next.js config adds experimental.optimizePackageImports with per-member import transforms for lucide-react and @/components/ui, each with preventFullImport enabled to improve tree-shaking of large packages.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A hook consolidated, clean and neat,
Build optimized with each small beat,
Fewer imports waste the tree,
Lighter bundles, fast and free! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'chore: optimize package imports & remove unused imports' directly relates to the actual changes: consolidating useApiError() calls in app/fiat/page.tsx and adding optimizePackageImports configuration in next.config.mjs to improve tree-shaking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/fiat/page.tsx`:
- Line 20: The destructured variable setApiError from the useApiError hook is
unused (causing an ESLint no-unused-vars error); remove setApiError from the
destructuring expression where useApiError() is called (i.e., update the line
with const { uiError, setApiError, clearError, isSubmitDisabled, handleError } =
useApiError() to omit setApiError) so only used symbols (uiError, clearError,
isSubmitDisabled, handleError) are kept, or alternatively use setApiError if
intended.

In `@next.config.mjs`:
- Around line 8-16: The Next.js config is using
experimental.optimizePackageImports with per-package transform/preventFullImport
objects which is invalid; move the per-package rules into the top-level
modularizeImports key and set experimental.optimizePackageImports to an array of
package names. Specifically, replace the object entries under
experimental.optimizePackageImports with experimental.optimizePackageImports:
['lucide-react'] and add a modularizeImports object containing the
'lucide-react' and '`@/components/ui`' entries (each with transform:
'.../{{member}}' and preventFullImport: true) so modularizeImports handles the
transform/preventFullImport behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 114fe702-15ee-47ed-a9dd-11cf830bc5e9

📥 Commits

Reviewing files that changed from the base of the PR and between 0b65d5e and 83f511f.

📒 Files selected for processing (2)
  • app/fiat/page.tsx
  • next.config.mjs

Comment thread app/fiat/page.tsx
const { userId, stellarAddress } = useAuth();
const kit = useStellarWalletsKit();
const { uiError, setApiError, clearError, isSubmitDisabled } = useApiError();
const { uiError, setApiError, clearError, isSubmitDisabled, handleError } = useApiError();
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Remove unused setApiError from hook destructuring (Line 20).

setApiError is currently unused and is flagged by ESLint (@typescript-eslint/no-unused-vars). Drop it from the destructuring (or use it) to keep CI/lint clean.

Suggested fix
-  const { uiError, setApiError, clearError, isSubmitDisabled, handleError } = useApiError();
+  const { uiError, clearError, isSubmitDisabled, handleError } = useApiError();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const { uiError, setApiError, clearError, isSubmitDisabled, handleError } = useApiError();
const { uiError, clearError, isSubmitDisabled, handleError } = useApiError();
🧰 Tools
🪛 ESLint

[error] 20-20: 'setApiError' is assigned a value but never used.

(@typescript-eslint/no-unused-vars)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/fiat/page.tsx` at line 20, The destructured variable setApiError from the
useApiError hook is unused (causing an ESLint no-unused-vars error); remove
setApiError from the destructuring expression where useApiError() is called
(i.e., update the line with const { uiError, setApiError, clearError,
isSubmitDisabled, handleError } = useApiError() to omit setApiError) so only
used symbols (uiError, clearError, isSubmitDisabled, handleError) are kept, or
alternatively use setApiError if intended.

Comment thread next.config.mjs
Comment on lines +8 to +16
optimizePackageImports: {
'lucide-react': {
transform: 'lucide-react/dist/esm/icons/{{member}}',
preventFullImport: true,
},
'@/components/ui': {
transform: '@/components/ui/{{member}}',
preventFullImport: true,
},
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

`For Next.js 16.0.10, what is the exact expected schema for:

  1. experimental.optimizePackageImports
  2. modularizeImports
    Please include official docs/examples showing whether transform/preventFullImport are valid under optimizePackageImports.`

💡 Result:

  1. experimental.optimizePackageImports (Next.js 16.0.10) Exact expected schema (from the official docs): module.exports = { experimental: { optimizePackageImports: ['package-name'], }, } So, experimental.optimizePackageImports is an array of package specifiers (strings). [1] Official notes/examples about transform/preventFullImport validity under optimizePackageImports: - The optimizePackageImports docs describe only the allow-list array of package names and do not mention any per-package options such as transform or preventFullImport. [1] - In contrast, preventFullImport is explicitly documented as an option for modularizeImports (not optimizePackageImports). [2] Conclusion: transform and preventFullImport are not valid keys under experimental.optimizePackageImports based on the official optimizePackageImports documentation (which specifies only the array of package names). [1] 2) modularizeImports (Next.js 16.0.10) Exact expected schema: module.exports = { modularizeImports: { 'package-name': { transform: 'package-name/{{member}}', preventFullImport: true, }, }, } This comes directly from the official docs that show: - modularizeImports is an object keyed by package name - each key maps to an object containing at least transform - and includes an example configuration for preventFullImport: true [3] Official docs/examples showing whether transform/preventFullImport are valid under optimizePackageImports: - For modularizeImports: yes, both transform and preventFullImport are documented and used in the example config. [3] - For optimizePackageImports: only optimizePackageImports: ['package-name'] is documented; there is no documented structure supporting transform or preventFullImport under experimental.optimizePackageImports. [1] Therefore, transform and preventFullImport are valid under modularizeImports, but not under experimental.optimizePackageImports (as documented for Next.js 16). [1][3]

Citations:


Fix Next.js config schema: use modularizeImports for transform/preventFullImport

experimental.optimizePackageImports only supports an array of package specifiers (e.g., ['lucide-react']). The current per-package object entries with transform and preventFullImport won’t be applied there; move those rules under modularizeImports:

export default {
  experimental: {
    optimizePackageImports: ['lucide-react'],
  },
  modularizeImports: {
    'lucide-react': {
      transform: 'lucide-react/dist/esm/icons/{{member}}',
      preventFullImport: true,
    },
    '`@/components/ui`': {
      transform: '`@/components/ui/`{{member}}',
      preventFullImport: true,
    },
  },
};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@next.config.mjs` around lines 8 - 16, The Next.js config is using
experimental.optimizePackageImports with per-package transform/preventFullImport
objects which is invalid; move the per-package rules into the top-level
modularizeImports key and set experimental.optimizePackageImports to an array of
package names. Specifically, replace the object entries under
experimental.optimizePackageImports with experimental.optimizePackageImports:
['lucide-react'] and add a modularizeImports object containing the
'lucide-react' and '`@/components/ui`' entries (each with transform:
'.../{{member}}' and preventFullImport: true) so modularizeImports handles the
transform/preventFullImport behavior.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 27, 2026

@hashmart138-creator Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Junman140 Junman140 merged commit b882f26 into Pi-Defi-world:dev May 29, 2026
1 check passed
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.

next.config.mjs missing experimental.optimizePackageImports – T Unused import statements in page components – T

3 participants