Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unique imports in #nitro-internal-virtual/server-handlers-meta #2945

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from

Conversation

ZerxZ
Copy link

@ZerxZ ZerxZ commented Dec 17, 2024

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR fixes an issue with duplicate handler imports in the virtual server handlers meta file, as discussed in nuxt/nuxt#29804.

Current Behavior

Currently, when multiple routes point to the same handler, the handler is imported multiple times in the #nitro-internal-virtual/server-handlers-meta virtual module, causing unnecessary code duplication and potential naming conflicts.

Changes Made

  • Modified the handler meta generation logic to use unique imports
  • Refactored the code to first collect all unique handlers
  • Ensured each handler is imported only once with a consistent import identifier
  • Maintained the correct mapping between routes and their corresponding handler metadata

Impact

This change:

  • Reduces bundle size by eliminating duplicate imports
  • Prevents potential naming conflicts in generated code
  • Improves code maintainability
  • Has no breaking changes to the public API

Example

Before:

import handler1Meta from "handler1?meta";
import handler1Meta from "handler1?meta"; // Duplicate import

After:

import handler1Meta from "handler1?meta"; // Single import

This fix ensures better code generation while maintaining all existing functionality

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@ZerxZ ZerxZ requested a review from pi0 as a code owner December 17, 2024 15:36
@ZerxZ ZerxZ force-pushed the fix/nitro-internal-virtual-server-handlers-meta branch from f707298 to 24b7d17 Compare December 17, 2024 15:59
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