Skip to content

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

Description

@mohas

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

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:

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions