Repository navigation
fix(core): inherit optional ctor params when the ctor is not redeclared - #17838
Merged
Merged
Conversation
Since 011bff6 the injector reads OPTIONAL_DEPS_METADATA with getOwnMetadata so that a subclass that redeclares its constructor no longer inherits the parent's @optional() flags (#2581). Parameter types, however, are still inherited through the prototype chain, so a subclass without its own constructor (e.g. `class LocalAuthGuard extends AuthGuard('local') {}`) got the parent's parameter types but none of its optional flags, and failed to bootstrap when the optional provider was not registered. Read the optional flags from the class that declares the constructor, i.e. the nearest class in the prototype chain with own constructor metadata.
4 of 12 tasks
Msoenn
added a commit
to semaphore-chat/semaphore-chat
that referenced
this pull request
Sep 25, 2026
…ts on Nest 12.0.x Nest 12 reads @optional() constructor markers with getOwnMetadata, so a subclass without its own constructor no longer inherits them (v12 migration guide, "@optional() is no longer inherited"). LocalAuthGuard and OptionalJwtAuthGuard extend AuthGuard(...) without a constructor, so AuthModuleOptions became required. FileModule provides OptionalJwtAuthGuard without importing PassportModule, and on @nestjs/core 12.0.4 the app fails to start with UnknownDependenciesException (generate:openapi and main both exit). 12.1.0 (nestjs/nest#17838) restores inheritance when the constructor isn't redeclared, but it is younger than pnpm's 3-day minimumReleaseAge. Both guards now declare `constructor(@optional() options?: AuthModuleOptions)` as the migration guide recommends, which keeps the v11 behavior on every 12.x release. New specs resolve each guard through DI in a module without PassportModule (they fail without the constructors). Also tidy RedisIoAdapter.createIOServer (drop the stale "types are incomplete" comment) and make its spec stub the parent IoAdapter instead of the method under test, with a case for the not-yet-connected path. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A5SQwjCR8fAYegPRWMCRKu
Msoenn
added a commit
to semaphore-chat/semaphore-chat
that referenced
this pull request
Sep 25, 2026
* chore(deps): upgrade NestJS to 12 (replaces #471) Dependabot's #471 bumps @nestjs/platform-express alone to 12, which peers @nestjs/core and @nestjs/common ^12, so it can't land against core 11. This moves every @nestjs package to its Nest 12 major together: common, core, platform-express, platform-socket.io, websockets, testing, config, swagger, terminus, jwt, passport, schedule, event-emitter, bullmq, mapped-types, cli and schematics. It also bumps @willsoto/nestjs-prometheus to 6.1.1, the first release whose peer range includes Nest 12. The range floors are the newest releases that pass pnpm's 3-day minimumReleaseAge today (common/core/platform-*/websockets/testing 12.0.4, config 12.0.0, swagger 12.0.1, cli 12.0.3, schematics 12.0.4), not 12.1.0 etc., so no minimumReleaseAgeExclude entries are needed. The v12 packages are ESM-only. Our backend stays CommonJS: node 24 loads them through require(esm). Jest 30 (already on main) does too on node >= 24.9, but only with --experimental-vm-modules; without it every suite fails with "Must use import to load ES Module". So: - The test scripts set NODE_OPTIONS=--experimental-vm-modules, and the docs say `pnpm run test <pattern>` instead of `pnpm exec jest <pattern>`. - transformIgnorePatterns goes: uuid now loads natively as well, so there is one ESM mechanism, not two. Code changes: - @nestjs/terminus 12 removes HealthCheckError, and a thrown error now means 500 instead of 503. The database and redis indicators now return HealthIndicatorService up()/down() results, keeping the same 3s timeout and the same response body. - IoAdapter now has a protected `logger`, so RedisIoAdapter's own logger is renamed. server.adapter() is now typed and rejects undefined, so it is only called once connectToRedis() has built the adapter. Passing undefined was a no-op getter call anyway. - backend/openapi.json is regenerated. @nestjs/swagger 12: - marks optional query params as required: false; - writes regex patterns without the /.../ delimiters; - adds enum/responseTime details to the terminus health schema. The frontend client regenerated from it type-checks unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A5SQwjCR8fAYegPRWMCRKu * fix(auth): re-declare AuthGuard's optional constructor so the app boots on Nest 12.0.x Nest 12 reads @optional() constructor markers with getOwnMetadata, so a subclass without its own constructor no longer inherits them (v12 migration guide, "@optional() is no longer inherited"). LocalAuthGuard and OptionalJwtAuthGuard extend AuthGuard(...) without a constructor, so AuthModuleOptions became required. FileModule provides OptionalJwtAuthGuard without importing PassportModule, and on @nestjs/core 12.0.4 the app fails to start with UnknownDependenciesException (generate:openapi and main both exit). 12.1.0 (nestjs/nest#17838) restores inheritance when the constructor isn't redeclared, but it is younger than pnpm's 3-day minimumReleaseAge. Both guards now declare `constructor(@optional() options?: AuthModuleOptions)` as the migration guide recommends, which keeps the v11 behavior on every 12.x release. New specs resolve each guard through DI in a module without PassportModule (they fail without the constructors). Also tidy RedisIoAdapter.createIOServer (drop the stale "types are incomplete" comment) and make its spec stub the parent IoAdapter instead of the method under test, with a case for the not-yet-connected path. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A5SQwjCR8fAYegPRWMCRKu * fix(ws): keep the global HTTP guards and ValidationPipe off WebSocket handlers Nest 12 passes the ApplicationConfig to the WebSocket guard, pipe and interceptor context creators (nestjs/nest 5e3dc4d0, "request-scoped gateways"), so global enhancers now run for gateway handlers too. On Nest 11 they never did. It isn't in the migration guide or the release notes, and no unit or e2e test covers a WebSocket message, but booting the app and sending one shows it: - The global JwtAuthGuard runs Passport's JWT strategy on every message. It only reads the Authorization header, while the web client sends its token in the handshake `auth` payload, so every message from a logged-in client got an "Unauthorized" exception instead of its ack (main: `431["ACK"]` for presenceOnline). It now accepts sockets the connection middleware authenticated (handshake.user set), like WsJwtAuthGuard, and still runs Passport for anything else. - The global ThrottlerGuard (non-test only) would key WebSocket messages on the Socket's undefined `ip`, putting every client in one shared bucket of the IP-based HTTP tiers. HttpThrottlerGuard skips non-HTTP contexts; gateways keep their per-user WsThrottleGuard. - The global ValidationPipe would validate every payload before the gateways' wsValidationPipe and turn invalid ones into a BadRequestException, reported to the client as "Internal server error" instead of the WsException details. HttpValidationPipe only validates HTTP param types; the e2e app helper uses it as well. The global interceptors are left on: TimingInterceptor was extended for gateway handlers in 8b07343 and now logs them as intended, and ClassSerializerInterceptor only serializes return values. Verified against the built app (NODE_ENV=development, test-stack services): presenceOnline acks with "ACK" and broadcasts userOnline, the same frames as main; unauthenticated sockets still get AUTH_FAILED; HTTP throttling still gives 20x200 then 429s. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A5SQwjCR8fAYegPRWMCRKu * fix(ws): one global ValidationPipe for HTTP and gateways, WS debug timing HttpValidationPipe never skipped WebSocket payloads: PipesConsumer maps the param type to a string before any pipe runs, and WsParamtype.PAYLOAD (3) == RouteParamtypes.BODY, so @MessageBody() arrived as 'body'. An invalid payload (e.g. typingStart {channelId: 42}) threw a BadRequestException ahead of the gateways' wsValidationPipe and the client got "Internal server error". A pipe gets no ExecutionContext and Nest 12 has no way to keep global pipes off gateways, so: - AppValidationPipe (transform, whitelist; replaces HttpValidationPipe in main.ts and the e2e helper) validates HTTP bodies and gateway payloads alike, once. Its ValidationFailedException is the stock 400 over HTTP (same response body) and carries the class-validator errors. - WsLoggingExceptionFilter turns it into WsException(errors), so WS clients get the same `exception` payload as the gateways' own pipe sent before Nest 12 (ValidationError[] without target/value). - The per-gateway @UsePipes(wsValidationPipe) goes away (it would only validate a second time). - The pipe spec goes through PipesConsumer and a running app (gateway via socket.io-client plus a controller via supertest); new test/websocket.e2e-spec.ts asserts the real typingStart case against the booted AppModule. socket.io-client (already in the lockfile for the frontend) becomes a backend devDependency. TimingInterceptor logs gateway handler timing at debug level now that Nest 12 runs it on every WebSocket message; HTTP stays at info. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A5SQwjCR8fAYegPRWMCRKu --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 task
CatsMiaow
added a commit
to CatsMiaow/nestjs-project-structure
that referenced
this pull request
Sep 30, 2026
Nest 12.0 dropped the @optional() of AuthGuard() in subclasses without a constructor, so AuthModuleOptions had to be registered. @nestjs/core 12.1.0 fixed it (nestjs/nest#17838), and the project requires ^12.1.1.
Merged
3 of 10 tasks
4 of 12 tasks
4 of 12 tasks
ttt43ttt
pushed a commit
to NoDevelopers/ts-monorepo
that referenced
this pull request
Nov 22, 2026
| datasource | package | from | to | | ---------- | ------------------------ | ------ | ------ | | npm | @nestjs/common | 12.0.1 | 12.1.0 | | npm | @nestjs/core | 12.0.1 | 12.1.0 | | npm | @nestjs/platform-express | 12.0.1 | 12.1.0 | ## [v12.1.0](https://github.com/nestjs/nest/releases/tag/v12.1.0) ##### v12.1.0 (2026-09-23) ##### Bug fixes - `core` - [#17838](nestjs/nest#17838) fix(core): inherit optional ctor params when the ctor is not redeclared ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - [#17819](nestjs/nest#17819) fix(core): name the module when metadata entries are invalid ([@thekhegay](https://github.com/thekhegay)) - `microservices` - [#17828](nestjs/nest#17828) fix(microservices): let the redis client retry after a failed connect ([@hktitof](https://github.com/hktitof)) - [#17810](nestjs/nest#17810) fix(microservices): fail every pending request when a callback throws ([@hktitof](https://github.com/hktitof)) ##### Enhancements - `core` - [#17846](nestjs/nest#17846) fix(core): do not skip subsequent middleware after a transient one ([@lehafari](https://github.com/lehafari)) - [#17840](nestjs/nest#17840) fix(core): preserve route handler names ([@Grmiade](https://github.com/Grmiade)) - `common`, `core` - [#17713](nestjs/nest#17713) feat(core): add support for array of global prefixes ([@micalevisk](https://github.com/micalevisk)) - [#17834](nestjs/nest#17834) feat(common,core): add built-in, adapter-agnostic cookies ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - `platform-fastify` - [#17824](nestjs/nest#17824) fix(fastify): honor Nest forceCloseConnections in initHttpServer ([@xia-chao](https://github.com/xia-chao)) - `common` - [#17827](nestjs/nest#17827) fix(common): apply the ParseDatePipe default to every missing value ([@xia-chao](https://github.com/xia-chao)) - `platform-fastify`, `testing` - [#17835](nestjs/nest#17835) feat(fastify): add file upload interceptors backed by [@fastify/multipart](https://github.com/fastify/multipart) ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - `common`, `core`, `platform-fastify` - [#17836](nestjs/nest#17836) feat(common,core,fastify): built-in CSRF protection and security headers ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) ##### Committers: 9 - Abdellatif Anaflous ([@hktitof](https://github.com/hktitof)) - Alejandro ([@lehafari](https://github.com/lehafari)) - Chris Z ([@haimingZZ](https://github.com/haimingZZ)) - Johnny J. Huirilef Millán ([@johnnyhuirilef](https://github.com/johnnyhuirilef)) - Jérémy Fauvel ([@Grmiade](https://github.com/Grmiade)) - Kamil Mysliwiec ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - Micael Levi L. Cavalcante ([@micalevisk](https://github.com/micalevisk)) - Roman Khegay ([@thekhegay](https://github.com/thekhegay)) - Xia Chao ([@xia-chao](https://github.com/xia-chao)) ## [v12.0.4](https://github.com/nestjs/nest/releases/tag/v12.0.4) ##### v12.0.4 (2026-09-21) ##### Bug fixes - `microservices` - [#17816](nestjs/nest#17816) fix(microservices): let the kafka client retry after a failed connect ([@Xch4rt](https://github.com/Xch4rt)) - [#17786](nestjs/nest#17786) fix(microservices): fail pending rmq requests on client close ([@johnnyhuirilef](https://github.com/johnnyhuirilef)) - [#17802](nestjs/nest#17802) fix(microservices): fail pending nats requests on client close ([@hktitof](https://github.com/hktitof)) - [#17803](nestjs/nest#17803) fix(microservices): handle missing grpc package namespace gracefully ([@Se3do](https://github.com/Se3do)) - [#17799](nestjs/nest#17799) fix(microservices): share the processing hook envelope across transports ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - [#17797](nestjs/nest#17797) fix(microservices): close the kafka request-response span exactly once ([@MingLin1995](https://github.com/MingLin1995)) - [#17794](nestjs/nest#17794) fix(microservices): close the request-response span exactly once ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - [#17785](nestjs/nest#17785) fix(microservices): route message handler rejections to handleError ([@hktitof](https://github.com/hktitof)) - `core` - [#17821](nestjs/nest#17821) fix(core): hang on sparse factory inject array ([@xia-chao](https://github.com/xia-chao)) ##### Enhancements - `platform-express` - [#17818](nestjs/nest#17818) Fix: merge multer `limits` key-by-key instead of overriding it wholesale ([@mdrezuanislamridoy](https://github.com/mdrezuanislamridoy)) - `common` - [#17780](nestjs/nest#17780) fix(common): mark parse date pipe options as optional ([@Chy-Zaber-Bin-Zahid](https://github.com/Chy-Zaber-Bin-Zahid)) ##### Dependencies - `common` - [#17793](nestjs/nest#17793) fix(deps): update dependency file-type to v22.1.1 ([@renovate\[bot\]](https://github.com/apps/renovate)) - `platform-fastify` - [#17791](nestjs/nest#17791) fix(deps): update dependency fastify to v5.12.5 ([@renovate\[bot\]](https://github.com/apps/renovate)) ##### Committers: 10 - Abdellatif Anaflous ([@hktitof](https://github.com/hktitof)) - Chowdhury Zaber Bin Zahid ([@Chy-Zaber-Bin-Zahid](https://github.com/Chy-Zaber-Bin-Zahid)) - Imad - Prakticode ([@prakticode](https://github.com/prakticode)) - Johnny J. Huirilef Millán ([@johnnyhuirilef](https://github.com/johnnyhuirilef)) - Kamil Mysliwiec ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - MD. Ridoy Babu ([@mdrezuanislamridoy](https://github.com/mdrezuanislamridoy)) - Ming ([@MingLin1995](https://github.com/MingLin1995)) - Mohammed Said ([@Se3do](https://github.com/Se3do)) - Pablo Gutiérrez ([@Xch4rt](https://github.com/Xch4rt)) - Xia Chao ([@xia-chao](https://github.com/xia-chao)) ## [v12.0.3](https://github.com/nestjs/nest/releases/tag/v12.0.3) ##### v12.0.3 (2026-09-15) ##### Bug fixes - `microservices` - [#17766](nestjs/nest#17766) fix(microservices): always run the kafka processing end hook ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - [#17757](nestjs/nest#17757) fix(microservices): fail pending requests on client close ([@hktitof](https://github.com/hktitof)) - [#17746](nestjs/nest#17746) fix(microservices): bound memory held for a TCP peer ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - [#17745](nestjs/nest#17745) fix(microservices): destroy open TCP sockets on shutdown ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - `common` - [#17738](nestjs/nest#17738) fix(common): validate uuid version and variant when no version is set ([@otnc](https://github.com/otnc)) - [#17761](nestjs/nest#17761) fix(common): invoke proto-key stripping hook via this in transform ([@koreahghg](https://github.com/koreahghg)) ##### Dependencies - `platform-express` - [#17762](nestjs/nest#17762) fix(deps): update dependency multer to v2.4.0 ([@renovate\[bot\]](https://github.com/apps/renovate)) - `common` - [#17753](nestjs/nest#17753) fix(deps): update dependency file-type to v22.1.0 ([@renovate\[bot\]](https://github.com/apps/renovate)) ##### Committers: 4 - Abdellatif Anaflous ([@hktitof](https://github.com/hktitof)) - Kamil Mysliwiec ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - otoneko. ([@otnc](https://github.com/otnc)) - 한국 ([@koreahghg](https://github.com/koreahghg)) ## [v12.0.2](https://github.com/nestjs/nest/releases/tag/v12.0.2) ##### v12.0.2 (2026-09-14) ##### Bug fixes - `platform-socket.io`, `platform-ws` - [#17666](nestjs/nest#17666) fix(socket.io): keep the message stream alive when a handler throws ([@hktitof](https://github.com/hktitof)) - `microservices` - [#17728](nestjs/nest#17728) fix(microservices): detach signal listeners of connected microservices ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - [#17671](nestjs/nest#17671) fix(microservices): fail requests whose reply subscription is rejected ([@samuelmbabhazi](https://github.com/samuelmbabhazi)) - [#17670](nestjs/nest#17670) fix(microservices): do not treat foreign JSON as an RPC envelope ([@xia-chao](https://github.com/xia-chao)) - [#17644](nestjs/nest#17644) fix(microservices): don't flatten plain handler results with pre-request hooks ([@iamolegga](https://github.com/iamolegga)) - [#17641](nestjs/nest#17641) fix(microservices): run the mqtt listen callback once ([@johnnyhuirilef](https://github.com/johnnyhuirilef)) - `common` - [#17710](nestjs/nest#17710) fix(common): collapse duplicate internal slashes in `normalizePath` ([@Asadshah7950](https://github.com/Asadshah7950)) - [#17655](nestjs/nest#17655) fix(common): validate UUID v3 variant ([@gwagjiug](https://github.com/gwagjiug)) - [#17702](nestjs/nest#17702) fix(common): treat empty string as array input in ParseArrayPipe ([@xia-chao](https://github.com/xia-chao)) - `core` - [#17667](nestjs/nest#17667) fix(core): discover factory providers with discovery decorators ([@hktitof](https://github.com/hktitof)) - [#17709](nestjs/nest#17709) fix(core): avoid treating error instances with `statusCode` as http errors ([@Asadshah7950](https://github.com/Asadshah7950)) - [#17625](nestjs/nest#17625) fix(core): clean up repeated shutdown signal listeners ([@Raj4478](https://github.com/Raj4478)) - `platform-fastify` - [#17705](nestjs/nest#17705) fix(fastify): derive neutral version when accept header is absent ([@Gaurav1112](https://github.com/Gaurav1112)) - [#17699](nestjs/nest#17699) fix(fastify): send responses for exceptions thrown from middleware ([@micalevisk](https://github.com/micalevisk)) ##### Enhancements - `microservices` - [#17734](nestjs/nest#17734) feat(microservices): add maxConnectionAttempts to ServerMqtt ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) ##### Dependencies - `platform-fastify` - [#17729](nestjs/nest#17729) fix(deps): update dependency fastify to v5.12.4 ([@renovate\[bot\]](https://github.com/apps/renovate)) ##### Committers: 16 - Abdellatif Anaflous ([@hktitof](https://github.com/hktitof)) - Alexey Solovyov ([@lyohaplotinka](https://github.com/lyohaplotinka)) - Asad Ali Shah ([@Asadshah7950](https://github.com/Asadshah7950)) - Gyeonghun Park ([@Gyeonghun-Park](https://github.com/Gyeonghun-Park)) - Johnny J. Huirilef Millán ([@johnnyhuirilef](https://github.com/johnnyhuirilef)) - Kamil Mysliwiec ([@kamilmysliwiec](https://github.com/kamilmysliwiec)) - Kumar Gaurav ([@Gaurav1112](https://github.com/Gaurav1112)) - Micael Levi L. Cavalcante ([@micalevisk](https://github.com/micalevisk)) - Ming ([@MingLin1995](https://github.com/MingLin1995)) - Mohammed Said ([@Se3do](https://github.com/Se3do)) - Rajeshwar Singh ([@Raj4478](https://github.com/Raj4478)) - Xia Chao ([@xia-chao](https://github.com/xia-chao)) - [@iamolegga](https://github.com/iamolegga) - cui fliter ([@cuishuang](https://github.com/cuishuang)) - samuel mbabhazi ([@samuelmbabhazi](https://github.com/samuelmbabhazi)) - 곽지욱 ([@gwagjiug](https://github.com/gwagjiug))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Regression in 12.0.0–12.0.4, introduced by 011bff6 (the fix for #2581). The injector reads constructor parameter types with
Reflect.getMetadata, which walks the prototype chain, but since that commit it reads@Optional()flags withReflect.getOwnMetadata. A subclass that doesn't declare its own constructor therefore inherits the parent's parameter types but none of its optional flags.This breaks the pattern from the Passport recipe:
Issue Number: N/A
What is the new behavior?
The optional flags are read from the class that declares the constructor: the nearest class in the prototype chain that has its own constructor metadata (
design:paramtypes,@Optional()or@Inject()).@Optional()flags again, along with the parameter types it already inherited.Both tsc and SWC omit
design:paramtypeson a subclass without its own constructor, so this check works with either compiler.Tests: unit tests for
getClassDependencies(child and grandchild without a constructor, children with a redeclared constructor), and new cases inintegration/injector/e2e/inherited-optional.spec.tsfor the mixin pattern, alongside the existing #2581 case. I also checked the fix against a real@nestjs/passport12.0.0 app: it fails to boot on 12.0.4 and boots with the patched injector.Does this PR introduce a breaking change?
Other information
@Inject()tokens on constructor parameters are still copied from parent to child when the child redeclares its constructor (Inject()itself merges withgetMetadata). That's the same kind of leak as #2581, but it predates 011bff6, so it's left for a separate change.