You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After upgrading from 2.2.0 to 4.1.0, we noticed that some of our components would crash at runtime. This seems to be due to vitejs/vite@f677b62 that changed the way to compile JSX. The new compiled version includes this as the last argument of the JSX function, which was not the case previously.
This is problematic if you have some JSX defined inside a class constructor before calling super because you cannot access this before that point.
// Compiled code from the reproduction linksuper(/* @__PURE__ */jsxDEV("div",{children: "Content"},void0,false,{fileName: "/home/projects/vitejs-vite-t1y2x7/src/App.jsx",lineNumber: 19,columnNumber: 11},this));
Create a class component that uses JSX before calling super
Render the component
See the error in the console: ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
I investigated a bit and found that a edge case that Babel support but not esbuild and SWC.
if you want this edge case to be supported you need to ask it to the lib that do the transformation.
My opinion is that this edge case is quite an anti-pattern of React (FB never needed this) and I think this fine for Vite to continue to default to esbuild for this transformation, given that it allows a nice build time boost when not using custom babel plugins.
Note that I created an issue for esbuild to consider fixing this – failing only during development seems like a bug to me (anti-pattern or not): evanw/esbuild#3454
Describe the bug
After upgrading from 2.2.0 to 4.1.0, we noticed that some of our components would crash at runtime. This seems to be due to vitejs/vite@f677b62 that changed the way to compile JSX. The new compiled version includes
this
as the last argument of the JSX function, which was not the case previously.This is problematic if you have some JSX defined inside a class constructor before calling
super
because you cannot accessthis
before that point.Reproduction
https://stackblitz.com/edit/vitejs-vite-t1y2x7?file=src%2FApp.jsx
Steps to reproduce
super
ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: