Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin deduplication does not work for decorate #1022

Open
mrcatlait opened this issue Jan 19, 2025 · 1 comment
Open

Plugin deduplication does not work for decorate #1022

mrcatlait opened this issue Jan 19, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@mrcatlait
Copy link

mrcatlait commented Jan 19, 2025

What version of Elysia is running?

1.2.10

What platform is your computer?

Microsoft Windows NT 10.0.26100.0 x64

What steps can reproduce the bug?

import Elysia from 'elysia'

class Plugin {
  constructor() {
    console.log('init Plugin')
  }
}

const plugin = () => new Elysia({ name: 'plugin' }).decorate('plugin', new Plugin())

new Elysia()
  .use(plugin)
  .use(plugin)
  .use(plugin)
  .onStart(({ server }) => {
    console.log(`Server is running at ${server?.url.toString()}`)
  })
  .listen(3000)

What is the expected behavior?

init Plugin
Server is running at http://localhost:3000/

What do you see instead?

init Plugin
init Plugin
init Plugin
Server is running at http://localhost:3000/

Additional information

No response

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

Yes

@mrcatlait mrcatlait added the bug Something isn't working label Jan 19, 2025
@Mudbill
Copy link

Mudbill commented Jan 24, 2025

If you define the plugin instance as const plugin = new Elysia() instead of as a function const plugin = () => new Elysia() then it appears to work as intended.

That said, I would still expect the deduplication to work with a function, unless there's a reason to suggest otherwise. It appears to act as if the deduplication isn't running when the plugin is a function instead of an instance of Elysia.

I recommend not using the function though. Is there a reason why you would want to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants