-
Notifications
You must be signed in to change notification settings - Fork 7
fix(middleware): static vs dynamic invoke issue #89
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@cursor review |
There was a problem hiding this 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 fixes a middleware invocation bug where middlewares were not being correctly applied based on the directory hierarchy when both static and dynamic routes coexisted. The fix ensures that only middlewares in the directory path of a matched route are executed, preventing incorrect middleware execution for static routes when dynamic route middlewares were present.
Key Changes:
- Refactored middleware extraction to use directory-based filtering instead of regex-only matching
- Added
directoryPathstracking to routes to map their directory hierarchy - Updated test expectations to reflect correct middleware execution order
- Updated Docusaurus and related dependencies to version 3.9.2
Reviewed changes
Copilot reviewed 17 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/file-router.ts | Refactored middleware extraction to filter by route's directory paths instead of regex matching |
| src/components/route/route.ts | Added directoryPaths property to track route's directory hierarchy |
| src/components/route/middleware.ts | Added path property and improved regex generation using dynamic route parsing |
| src/components/file-route-resolver.ts | Added buildDirectoryPaths() and normalizeMiddlewarePath() methods, extracted route parsing logic |
| src/components/dynamic-routes/parse-dynamic-route.ts | Extracted dynamic route parsing logic into reusable function |
| tests/test-utils.ts | Added optional method parameter to middleware request runner |
| tests/request-handle-middlewares.test.ts | Updated existing test expectations and added comprehensive test suite for static vs dynamic routes |
| tests/api-middlewares/static-vs-dynamic/* | Added test fixtures for static and dynamic route middleware scenarios |
| website/package.json | Updated Docusaurus to 3.9.2 and @mdx-js/react to 3.1.1 |
| website/src/css/custom.css | Updated announcement bar selector for Docusaurus 3.9.2 compatibility |
| website/docusaurus.config.js | Removed backgroundColor (now handled via CSS gradient) |
| examples/web-socket/package.json | Updated ws package to 8.18.1 |
| examples/web-socket/pnpm-lock.yaml | Updated lock file for ws 8.18.1 |
Files not reviewed (1)
- examples/web-socket/pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@cursor review |
|
Skipping Bugbot: Bugbot is disabled for this repository |
|
@cursor review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note
Fixes middleware execution for dynamic routes by scoping middleware matching to the matched route’s directory stack, refactors dynamic route parsing, and adds comprehensive tests; also updates website deps and minor CSS.
parseDynamicRouteutility and use it across dynamic route parsing.FileRouteResolver:parentRouteand builddirectoryPathsforRoute.parseDynamicRoute.matchRoute; changeextractMiddlewaresto select only middlewares alongmatchedRoute.directoryPaths.routeParamsto handlers and middleware executor.Middlewareto build precise regex viaparseDynamicRouteand support nesting-level; storepath.RoutewithdirectoryPaths.[id]/applesand static paths) asserting correct middleware order and route params.Written by Cursor Bugbot for commit 1ef3190. This will update automatically on new commits. Configure here.