Skip to content

fix(core): instantiate nested transient providers in static context#16098

Merged
kamilmysliwiec merged 3 commits into
nestjs:masterfrom
mag123c:fix/static-nested-transient-instantiation
Dec 21, 2025
Merged

fix(core): instantiate nested transient providers in static context#16098
kamilmysliwiec merged 3 commits into
nestjs:masterfrom
mag123c:fix/static-nested-transient-instantiation

Conversation

@mag123c

@mag123c mag123c commented Dec 19, 2025

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

When a DEFAULT-scoped provider depends on a nested TRANSIENT chain (e.g., Controller → TransientA → TransientB), the nested TRANSIENT provider's constructor is not called. The instance exists as a prototype only, causing class fields to be undefined.

Issue Number: #16097

What is the new behavior?

Nested TRANSIENT providers are now properly instantiated in STATIC_CONTEXT. The isStatic() method now returns true when the inquirer is TRANSIENT with a static dependency tree and no rootInquirer set.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Related PRs:

@coveralls

coveralls commented Dec 19, 2025

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build c3b1f3ec-bdab-4a0e-a61d-21b32d8dc74b

Details

  • 10 of 11 (90.91%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 89.685%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/core/injector/instance-wrapper.ts 10 11 90.91%
Totals Coverage Status
Change from base Build 486e7c70-dd96-4131-9d63-6cf55a189b18: 0.001%
Covered Lines: 7425
Relevant Lines: 8279

💛 - Coveralls

@kamilmysliwiec

Copy link
Copy Markdown
Member

We might want to add an integration test, just in case - to ensure this doesn't happen again in the future

Comment on lines +420 to +424
(isStaticTransient && !!rootInquirer && !rootInquirer.isTransient) ||
(isStaticTransient &&
!!inquirer &&
inquirer.isTransient &&
!rootInquirer))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: i wonder if - instead of just adding another newline - it would have been better to break this down into if-else clauses with corresponding comments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, refactored the method with if-else clauses and comments for better readability.

@kamilmysliwiec kamilmysliwiec merged commit 2620db6 into nestjs:master Dec 21, 2025
4 checks passed
@kamilmysliwiec

Copy link
Copy Markdown
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants