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

The plugin with scoped settings is not functioning correctly. #559

Closed
hagishi opened this issue Mar 19, 2024 · 2 comments
Closed

The plugin with scoped settings is not functioning correctly. #559

hagishi opened this issue Mar 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@hagishi
Copy link

hagishi commented Mar 19, 2024

What version of Elysia.JS is running?

1.0.5

What platform is your computer?

Darwin 23.1.0 arm64 arm

What steps can reproduce the bug?

When a plugin with "scoped" setting is referenced in multiple routers,
the type can be referenced in the latter router, but becomes undefined at runtime when executed.

it("scoped run", async () => {
  const plugin = new Elysia({ name: "plugin" }).derive({ as: "scoped" }, () => {
    return { id: 1 };
  });

  const a = new Elysia().use(plugin).get("/foo", (c) => {
     return { id: c.id, name: "foo" };
  });

  const b = new Elysia().use(plugin).get("/bar", (c) => {
     return { id: c.id, name: "bar" };
  });

  console.log((await treaty(a).foo.get()).data);
  // show:  { id: 1, name: 'foo' }
  console.log((await treaty(b).bar.get()).data);
  // show: { name: 'bar' }
});

What is the expected behavior?

A plugin with the "scoped" setting is expected to be referenced at runtime within the scope it's defined.

What do you see instead?

The type can be referenced but becomes undefined at runtime.

Additional information

No response

@hagishi hagishi added the bug Something isn't working label Mar 19, 2024
@hagishi hagishi changed the title scoped doesn't work in handler The plugin with scoped settings is not functioning correctly. Mar 19, 2024
@CodyTseng
Copy link

I executed your test cases and obtained the expected results.

{
  id: 1,
  name: "foo",
}
{
  id: 1,
  name: "bar",
}

@SaltyAom
Copy link
Member

Closing as unable to reproduce. Thanks.

@SaltyAom SaltyAom closed this as not planned Won't fix, can't repro, duplicate, stale Aug 30, 2024
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

3 participants