feat(fix): refactor button instantiation into ButtonWrapper class#11940
Open
kochrac wants to merge 2 commits intovercel:mainfrom
Open
feat(fix): refactor button instantiation into ButtonWrapper class#11940kochrac wants to merge 2 commits intovercel:mainfrom
kochrac wants to merge 2 commits intovercel:mainfrom
Conversation
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.
Contributor
|
@ptrgits is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem is that
newis being used on something that is not a constructor (likely a function component). The fix is to stop usingnewand instead useButtonin the manner it is intended to be used. Since the next line callsbutton.render(), it looks like the code expects an instance with arendermethod; to keep behavior similar without changingButton's implementation, we can create a simple wrapper class that internally calls theButtonfunction.The best minimal fix inside
main.tsis: define a smallButtonWrapperclass that has arendermethod invokingButton, then instantiate that wrapper withnew ButtonWrapper()instead ofnew Button(). This avoids changing./button.tsx, aligns with the intended non-constructor nature ofButton, and preserves the existingbutton.render();call site. Concretely, inturborepo-tests/integration/fixtures/turbo_trace/main.ts, we will insert aclass ButtonWrapperdefinition above theconst button = ...line, change that instantiation tonew ButtonWrapper(), and leave therendercall 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 usingneworsuper(...), and attempting to invoke them as a normal function will result in a runtime error.Instead,
newshould be used:References
Mozilla Developer Network: Constructors
Mozilla Developer Network: Arrow functions
Mozilla Developer Network: Method definitions