-
-
Notifications
You must be signed in to change notification settings - Fork 22.4k
Closed
vercel/next.js
#81573Description
When using Express as a custom server in front of Next.js, accessing req.query directly no longer returns a mutable plain object. Instead, it is now a getter, and attempts to modify it or use it as a plain object lead to unexpected behavior or errors.
This change affects routes where the server modifies or depends on the mutability of req.query before passing it to Next.js, breaking compatibility with existing implementations.
Next.js Issue:
vercel/next.js#79158
Context
We applied the following patch, but we do not believe it is the best solution:
// Express 5 makes the 'query' property read-only, but Next.js needs to write to it
try {
Object.defineProperty(req, 'query', descriptor);
} catch (error) {
// If property already exists and is configurable, delete and recreate it
try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (req as any).query;
Object.defineProperty(req, 'query', descriptor);
logger.logInfo(`query property fixed ${error}`, requestID);
} catch (error) {
logger.logWarn(
`Could not fix query property for Next.js compatibility: ${error}`,
requestID
);
}
}Is it possible to know why Express decided to change? This would help us understand where we need to make adjustments (on the Next.js side or the Express.js side).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels