Skip to content

[Bug] MessageComponents.prototype.row() creates a circular reference #379

@marcusjang

Description

@marcusjang

What's the bug?
Using MessageComponents.prototype.row() pushes this onto this, thus creating a circular reference, as shown in here on line 29:

export class MessageComponents extends Array<MessageComponentData> {
row(cb: (builder: MessageComponents) => unknown): this {
const components = new MessageComponents()
cb(components)
this.push({
type: MessageComponentType.ACTION_ROW,
components: this as MessageComponentData[]
})
return this
}

How do we reproduce it?
Call row(cb) method on new MessageComponents(), then try to use the component.

What should have happened?
row(cb) should call cb() with a new MessageComponents, then push it to the newly created row.

What is actually happening?
It throws an error such as:

error: Uncaught (in promise) RangeError: Maximum call stack size exceeded
  return d.map((data: unknown) => {

with a console output on MessageComponents:

<ref *1> MessageComponents(1) [
  { type: 1, components: [Circular *1] }
]

What versions you're using?

  • OS: macOS 14.4.1
  • Deno: Deno 1.43.1
  • Harmony: Harmony 2.9.0

Do you have anything to tell us more about the bug?
Undoes change done in #287, probably a simple slip.

Previous commit on the file:

export class MessageComponents extends Array<MessageComponentData> {
row(cb: (builder: MessageComponents) => unknown): this {
const components = new MessageComponents()
cb(components)
this.push({
type: MessageComponentType.ActionRow,
components
})
return this

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions