Skip to content

Comments

feat(fix): refactor button instantiation into ButtonWrapper class#11940

Open
kochrac wants to merge 2 commits intovercel:mainfrom
kochrac:patch-2
Open

feat(fix): refactor button instantiation into ButtonWrapper class#11940
kochrac wants to merge 2 commits intovercel:mainfrom
kochrac:patch-2

Conversation

@kochrac
Copy link

@kochrac kochrac commented Feb 20, 2026

The problem is that new is being used on something that is not a constructor (likely a function component). The fix is to stop using new and instead use Button in the manner it is intended to be used. Since the next line calls button.render(), it looks like the code expects an instance with a render method; to keep behavior similar without changing Button's implementation, we can create a simple wrapper class that internally calls the Button function.

The best minimal fix inside main.ts is: define a small ButtonWrapper class that has a render method invoking Button, then instantiate that wrapper with new ButtonWrapper() instead of new Button(). This avoids changing ./button.tsx, aligns with the intended non-constructor nature of Button, and preserves the existing button.render(); call site. Concretely, in turborepo-tests/integration/fixtures/turbo_trace/main.ts, we will insert a class ButtonWrapper definition above the const button = ... line, change that instantiation to new ButtonWrapper(), and leave the render call as is.

Description

Class methods and arrow functions must not be invoked using new, and attempting to do so will result in a runtime error. conversely, constructors can only be invoked using new or super(...), and attempting to invoke them as a normal function will result in a runtime error.


class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
}

let p = Point(23, 42);

Instead, new should be used:

class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
}

let p = new Point(23, 42);

References

Mozilla Developer Network: Constructors
Mozilla Developer Network: Arrow functions
Mozilla Developer Network: Method definitions

The problem is that `new` is being used on something that is not a constructor (likely a function component). The fix is to stop using `new` and instead use `Button` in the manner it is intended to be used. Since the next line calls `button.render()`, it looks like the code expects an instance with a `render` method; to keep behavior similar without changing `Button`'s implementation, we can create a simple wrapper class that internally calls the `Button` function.

The best minimal fix inside `main.ts` is: define a small `ButtonWrapper` class that has a `render` method invoking `Button`, then instantiate that wrapper with `new ButtonWrapper()` instead of `new Button()`. This avoids changing `./button.tsx`, aligns with the intended non-constructor nature of `Button`, and preserves the existing `button.render();` call site. Concretely, in `turborepo-tests/integration/fixtures/turbo_trace/main.ts`, we will insert a `class ButtonWrapper` definition above the `const button = ...` line, change that instantiation to `new ButtonWrapper()`, and leave the `render` call as is. No new imports are required.
@kochrac kochrac requested a review from a team as a code owner February 20, 2026 20:54
@kochrac kochrac requested review from tknickman and removed request for a team February 20, 2026 20:54
@vercel
Copy link
Contributor

vercel bot commented Feb 20, 2026

@ptrgits is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

Integration test turbo-trace.t contains hardcoded expected AST output for the old main.ts content, which was changed to include a class declaration, causing test failure due to mismatched AST structure and byte spans.

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant