Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4004,7 +4004,7 @@ export default class Elysia<
if (plugin instanceof Elysia)
return this._use(plugin).compile()

if (plugin.constructor.name === 'Elysia')
if (plugin.constructor?.name === 'Elysia')
return this._use(
plugin as unknown as Elysia
).compile()
Expand All @@ -4015,10 +4015,10 @@ export default class Elysia<
if (plugin.default instanceof Elysia)
return this._use(plugin.default)

if (plugin.constructor.name === 'Elysia')
if (plugin.constructor?.name === 'Elysia')
return this._use(plugin.default)

Comment on lines +4018 to 4020
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Bug: checking the module namespace object instead of the default export.

When handling an ES module with a default Elysia instance, this should inspect plugin.default.constructor?.name, not plugin.constructor?.name.

Apply:

- if (plugin.constructor?.name === 'Elysia')
+ if (plugin.default?.constructor?.name === 'Elysia')
   return this._use(plugin.default)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (plugin.constructor?.name === 'Elysia')
return this._use(plugin.default)
if (plugin.default?.constructor?.name === 'Elysia')
return this._use(plugin.default)
🤖 Prompt for AI Agents
In src/index.ts around lines 4018 to 4020, the code is checking
plugin.constructor?.name which inspects the module namespace object for ESM
modules instead of the default export; change the conditional to inspect
plugin.default.constructor?.name and call this._use(plugin.default) for ESM
default exports, while preserving the existing path for non-ESM plugins (i.e.,
first check plugin.constructor?.name === 'Elysia' then fall back to
plugin.default?.constructor?.name === 'Elysia'); also guard against
plugin.default being undefined before accessing its constructor.

if (plugin.constructor.name === '_Elysia')
if (plugin.constructor?.name === '_Elysia')
return this._use(plugin.default)

Comment on lines +4021 to 4023
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Same bug for '_Elysia' branch; also targets the wrong object.

This should also read from plugin.default.

Apply:

- if (plugin.constructor?.name === '_Elysia')
+ if (plugin.default?.constructor?.name === '_Elysia')
   return this._use(plugin.default)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (plugin.constructor?.name === '_Elysia')
return this._use(plugin.default)
if (plugin.default?.constructor?.name === '_Elysia')
return this._use(plugin.default)
🤖 Prompt for AI Agents
In src/index.ts around lines 4021 to 4023, the '_Elysia' branch currently checks
plugin.constructor?.name (the wrong object) and must instead inspect the
exported default; change the condition to read plugin.default?.constructor?.name
=== '_Elysia' and have it call this._use(plugin.default) so both the check and
the argument target the actual default export.

try {
Expand Down
Loading