#2004·elysia

AOT cookie/context injection (isFnUse) silently drops context properties when handler delegates to another function

Author: mohasCreated Sep 21, 2026Updated Sep 21, 2026
Labelsbug

What version of Elysia is running?

1.2.6+

What platform is your computer?

every platform

What environment are you using

bun 1.3.2

Are you using dynamic mode?

no

What steps can reproduce the bug?

had some serious head banging for this

typescript
import { Elysia } from 'elysia'

async function handle({ cookie, request }: { cookie: any }) {
    console.log('cookie:', cookie) // undefined
    console.log('cookie in header:', request.headers) // not undefined
    return cookie
}

new Elysia()
    .get('/repro', async (ctx) => {
        // ctx.cookie is never referenced textually in THIS function's
        // literal source, so Elysia's static analysis (isFnUse) does not
        // detect cookie usage and skips constructing the cookie jar.
        return await handle(ctx)
    })
    .listen(3000)

Compare with:

typescript
new Elysia()
    .get('/works', async (ctx) => {
        void ctx.cookie // <-- merely referencing it here fixes it
        return await handle(ctx)
    })
    .listen(3000)

What is the expected behavior?

Please at least leave this example in your documentation to prevent cotchas

What do you see instead?

No response

Additional information

No response

Have you try removing the node_modules and bun.lock and try again yet?

No response