I discovered a bug when using disableMiddleware: true.
When relying on I18nLanguageInterceptor to initialize the I18nContext, it's not possible to use another interceptor on the same endpoint.
When doing so, the AsyncLocalStorage containing the i18n context is broken: I18nContext.current() always returns undefined.
How to reproduce
Set disableMiddleware: true in I18nModule options.
coverage: 90.869% (+0.1%) from 90.764%
when pulling 45d148d584357591d3103b867e501f82d05b378c on lucas-gregoire:fix/undefined-current-context
into 0774e23b6e64fbfa7b5044e87c86e2b0f55fe7b7 on toonvanstrijp:main.
Description
I discovered a bug when using
disableMiddleware: true
. When relying onI18nLanguageInterceptor
to initialize theI18nContext
, it's not possible to use another interceptor on the same endpoint. When doing so, theAsyncLocalStorage
containing the i18n context is broken:I18nContext.current()
always returnsundefined
.How to reproduce
Set
disableMiddleware: true
inI18nModule
options.Define a simple interceptor such as:
Add it on your endpoint:
This endpoint will always return
undefined
instead of the resolved lang. When removing the interceptor it works.Additional context
I did something similar to the
nestjs-cls
's interceptor implementation: https://github.com/Papooch/nestjs-cls/blob/main/packages/core/src/lib/cls-initializers/cls.interceptor.ts I just simplified it by passing the observer directly to thesubscribe
method. I added a test ini18n-disable-middleware.e2e.spec.ts
to avoid regressions.See also: