elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
9.1k stars 193 forks source link

Plugin registered by async inline function don't work #679

Open kravetsone opened 3 weeks ago

kravetsone commented 3 weeks ago

What version of Elysia.JS is running?

1.0.23

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

It broke my elysia-autoload plugin

Your code for it https://github.com/elysiajs/elysia/blob/8a5871b1a96ebe5c6957310f8e2848064e441f09/src/index.ts#L2697-L2705

function somePlugin() {
    return async () =>
        new Elysia().ws("/ws", {
            message(ws, message) {
                ws.send(message);
            },
        });
}

export const app = new Elysia()
    .use(somePlugin());

app.listen(3002, () => console.log("started"));

When i remove async from function it works fine

function somePlugin() {
    return () =>
        new Elysia().ws("/ws", {
            message(ws, message) {
                ws.send(message);
            },
        });
}

export const app = new Elysia()
    .use(somePlugin());

app.listen(3002, () => console.log("started"));

it works fine too

async function somePlugin() {
    return new Elysia().ws("/ws", {
            message(ws, message) {
                ws.send(message);
            },
        });
}

export const app = new Elysia()
    .use(somePlugin());

app.listen(3002, () => console.log("started"));

it seems to me that this issue is deeper than it seems and may affect https://github.com/kravetsone/elysia-autoload/issues/10 and https://github.com/kravetsone/elysia-autoload/issues/8 and other plugins are connected, but I haven't been able to get to the truth yet.

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response