Skip to content

fix: middleware type #922

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

Merged
merged 2 commits into from
Jul 10, 2025
Merged

fix: middleware type #922

merged 2 commits into from
Jul 10, 2025

Conversation

vicb
Copy link
Contributor

@vicb vicb commented Jul 10, 2025

assetResolver can be used regardless if the middleware is external

Copy link

changeset-bot bot commented Jul 10, 2025

🦋 Changeset detected

Latest commit: c487b2f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@opennextjs/aws Patch
app-pages-router Patch
app-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Jul 10, 2025

Open in StackBlitz

pnpm add https://pkg.pr.new/@opennextjs/aws@922

commit: c487b2f

Copy link
Contributor

github-actions bot commented Jul 10, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 26.93% 2639 / 9798
🔵 Statements 26.93% 2639 / 9798
🔵 Functions 54.26% 140 / 258
🔵 Branches 73.23% 621 / 848
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/open-next/src/adapters/middleware.ts 0% 0% 0% 0% 1-138
packages/open-next/src/build/generateOutput.ts 0% 0% 0% 0% 1-365
packages/open-next/src/build/validateConfig.ts 0% 0% 0% 0% 1-120
packages/open-next/src/core/createGenericHandler.ts 0% 0% 0% 0% 1-54
packages/open-next/src/core/resolve.ts 0% 100% 100% 0% 15-169
packages/open-next/src/types/open-next.ts 0% 0% 0% 0%
Generated in workflow #1353 for commit c487b2f by the Vitest Coverage Report Action

@vicb vicb requested review from conico974 and Copilot July 10, 2025 12:38
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the middleware configuration type so that OpenNextConfig.middleware can be either an external or internal middleware config, and updates all related logic to use the new types.

  • Introduces CommonMiddlewareConfig, ExternalMiddlewareConfig, and InternalMiddlewareConfig and updates OpenNextConfig.middleware.
  • Updates resolver, output generation, and adapter code to cast and use ExternalMiddlewareConfig.
  • Adjusts override extraction in createGenericHandler and adds conditional validation for external middleware.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/open-next/src/types/open-next.ts Refactored middleware types and updated OpenNextConfig to use ExternalMiddlewareConfig or InternalMiddlewareConfig.
packages/open-next/src/core/resolve.ts Changed resolveOriginResolver signature to accept ExternalMiddlewareConfig originResolver.
packages/open-next/src/core/createGenericHandler.ts Guard override extraction to only pull .override when present on handler config.
packages/open-next/src/build/validateConfig.ts Added validateFunctionOptions call for middleware only when external === true.
packages/open-next/src/build/generateOutput.ts Extracted middlewareConfig for external middleware and updated originResolver/override access.
packages/open-next/src/adapters/middleware.ts Cast global config to ExternalMiddlewareConfig and updated all resolver calls to use the cast config.
.changeset/slimy-turkeys-smoke.md Added changeset entry for middleware configuration type fix.
Comments suppressed due to low confidence (3)

packages/open-next/src/types/open-next.ts:424

  • [nitpick] The docblock above middleware only mentions external behavior. Consider expanding it to also describe how external: false (internal middleware) is handled.
  middleware?: ExternalMiddlewareConfig | InternalMiddlewareConfig;

packages/open-next/src/build/validateConfig.ts:112

  • Add unit tests for validateConfig to cover both external: true and external: false middleware cases, ensuring validation logic runs only for external middleware.
  if (config.middleware?.external === true) {

packages/open-next/src/adapters/middleware.ts:38

  • The optional chaining on middlewareConfig?.originResolver causes a type mismatch: resolveOriginResolver expects a non-undefined originResolver. Remove the ? so you pass middlewareConfig.originResolver.
    middlewareConfig?.originResolver,

Copy link
Contributor

@conico974 conico974 left a comment

Choose a reason for hiding this comment

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

LGTM

@vicb
Copy link
Contributor Author

vicb commented Jul 10, 2025

Thanks for the review Nico!

@vicb vicb merged commit d7d3966 into main Jul 10, 2025
3 checks passed
@vicb vicb deleted the vicb/mw-type branch July 10, 2025 13:05
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.

2 participants